Next.js Discord

Discord Forum

Saving the current user session to the Zustand (client side)

Unanswered
Cape horse mackerel posted this in #help-forum
Open in Discord
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
// 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;
    },
Cape horse mackerelOP
ok, but where do I have to call a method to set user in the state?