Replies: 1 comment
-
Just came across this issue while integrating nextjs v14 with express backend For my solution I added the async jwt({ token, trigger, user, session }) {
if (user) {
const customUser = user as unknown as {
token: string
refreshToken: string
email: string
firstName: string
lastName: string
}
token.accessToken = customUser.token
token.refreshToken = customUser.refreshToken
token.email = customUser.email
token.firstName = customUser.firstName
token.lastName = customUser.lastName
}
return token
}, This will be the contents of the and in your backend you can use a function like this as suggested in the comment response of here is mine: const decodeJWE = async (token: string) => {
try {
const { decode } = await import('next-auth/jwt')
const decodedJWE= await decode({
token: token,
secret: process.env.NEXTAUTH_SECRET,
})
return decodedJWE.accessToken as string
} catch (error) {
throw error
}
} This worked for me! it might not be the best, but it gets the job done! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello Next-Auth,
I am attempting to implement Next-Auth w/ the Auth0Provider but there is no clear explanation on how to pass the DECODED access_token to the backend for validation. I am seeing some posts referencing the getToken helper function & others referencing overriding the encode & decode methods but both of these are used on the frontend.
I know this has to do with next-auth encoding JWTs as JWEs but what am i missing in terms of a pretty standard flow of decoding & passing an access_token to an API service? What is the recommended way to let next-auth integrate with a backend API?
I have a full SO Post outlining my issue.
Below is my current authOptions for next-auth (I do NOT currently have the encode & decode overwritten)
I have also copied the middleware validator that I am using in my Express Server directly from the Auth0 quick start into my Express Backend Server
The Server Error
Thank you for any help on this!
Beta Was this translation helpful? Give feedback.
All reactions