You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I confirm that upgrading next (from 12.2.2, not working) to 12.2.5 fixes this issue.
I was using Twitter provider.
Here's my code if anyone's interested or struggling 馃:
./src/middleware.js :
import{withAuth}from'next-auth/middleware';exportdefaultwithAuth(// `withAuth` augments your `Request` with the user's token.functionmiddleware(req){console.log(req.nextauth.token);// This was null in 12.2.2, and working in 12.2.5},{callbacks: {authorized: ({ token })=>{// This is to only allow access to these Twitter user ids.return['44196397','15540222'].includes(token?.sub);// Elon Musk & Guillermo Rauch (NextJS creator), welcome :)},},});exportconstconfig={matcher: ['/movies/:path*']};
./src/pages/api/[...nextauth].ts
/* eslint-disable no-param-reassign */importtype{NextAuthOptions}from'next-auth';importNextAuthfrom'next-auth';importTwitterProviderfrom'next-auth/providers/twitter';exportconstauthOptions: NextAuthOptions={providers: [TwitterProvider({clientId: process.env.TWITTER_CONSUMER_KEY!,clientSecret: process.env.TWITTER_CONSUMER_SECRET!,}),],pages: {signIn: '/auth/signin',},session: {strategy: 'jwt',maxAge: 90*24*60*60,// 90 days, change it as you like},callbacks: {asyncjwt({ token, user }){if(user){token.sub=user.id;}returntoken;},asyncsession({ session, token }){if(token){session.user=token;}returnsession;},},};exportdefaultNextAuth(authOptions);
I was using Twitter provider.
Here's my code if anyone's interested or struggling 馃:
./src/middleware.js
:./src/pages/api/[...nextauth].ts
Originally posted by @kodsu in nextauthjs/next-auth#5008 (comment)
The text was updated successfully, but these errors were encountered: