token
value is null
when using getToken
#2964
-
I'm still following https://spacejelly.dev/posts/how-to-make-twitter-api-requests-with-nextauth-js-session-tokens/ & I have import { NextApiRequest, NextApiResponse } from 'next'
import { getSession } from 'next-auth/react'
import { getToken } from 'next-auth/jwt'
export default async (req: NextApiRequest, res: NextApiResponse) => {
try {
const session = await getSession({ req })
const token = await getToken({
req,
token: process.env.NEXTAUTH_SECRET,
})
console.log({ session })
console.log({ token })
return res.status(200).json({
status: 'Ok',
data: [],
})
} catch (e: unknown) {
return res.status(400).json({
status: (e as Error).message,
})
}
} I get the Full repro is on branch |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
You have a typo: getToken({
req,
secret: process.env.NEXTAUTH_SECRET
}) tip, you probably don't need both getSession and getToken. session is the subset of token in most cases, depending on what you do in your session callback |
Beta Was this translation helpful? Give feedback.
You have a typo:
tip, you probably don't need both getSession and getToken. session is the subset of token in most cases, depending on what you do in your session callback