Saving the current user session to the Zustand (client side)
Unanswered
Cape horse mackerel posted this in #help-forum
Cape horse mackerelOP
Hi, what's the best way to store user session in Zustand?
I'm using next-auth with one provider.
Can I do smth like
I'm using next-auth with one provider.
Can I do smth like
// RootLayout
<AuthProvider>
<Layout>{children}</Layout>
</AuthProvider>
// Layout.tsx
const session = useSession();
const _useAuthStore = useAuthStore();
// use method from useAuthStore to save user in the state
<>
<ReactQueryProvider>
<Header />
<main>
{children}
</main>
<Footer />
</ReactQueryProvider>
</>4 Replies
Cape horse mackerelOP
and also I have this in
authOptions async session({session, token}) {
session.user.appJwtToken = token.appJwtToken;
session.user.permissions = token.permissions;
return session;
},You can use something like persisting.
https://docs.pmnd.rs/zustand/integrations/persisting-store-data
https://docs.pmnd.rs/zustand/integrations/persisting-store-data
Cape horse mackerelOP
ok, but where do I have to call a method to set user in the state?
@Cape horse mackerel ok, but where do I have to call a method to set user in the state?
Read the docs there are code samples