Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update NextAuth JWT docs #1510

Closed
ruymon opened this issue Jul 12, 2023 · 0 comments · Fixed by #1511 or #1582
Closed

docs: Update NextAuth JWT docs #1510

ruymon opened this issue Jul 12, 2023 · 0 comments · Fixed by #1511 or #1582

Comments

@ruymon
Copy link
Contributor

ruymon commented Jul 12, 2023

Provide environment information

N/A

Describe the bug

The current code snippet for migrating nextauth to JWT strategy is outdated to what is scaffolded.

Current snippet:

  export const authOptions: NextAuthOptions = {
+   session: {
+     strategy: "jwt",
+   },
    callbacks: {
-     session({ session, user }) {
+     session({ session, token }) {
-       if (session.user) {
+       if (session.user && token.sub) {
-         session.user.id = user.id;
+         session.user.id = token.sub;
        }
        return session;
      }
    },
  };

However, currently T3 uses a destructuring approach for the Callback object, like so:

    session: ({ session, token }) => ({
     ...session,
     user: {
       ...session.user,
       id: token.sub,
     },
   }),

Reproduction repo

https://create.t3.gg/en/usage/next-auth#usage-with-nextjs-middleware

To reproduce

N/A

Additional information

No response

@ruymon ruymon changed the title bug: Update NextAuth JWT docs docs: Update NextAuth JWT docs Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant