Help storing and accessing tokens #1068
Replies: 4 comments 14 replies
-
The intended place to modify the jwt token is the export default function (req: NextApiRequest, res: NextApiResponse) {
NextAuth(req, res, {
providers: [
{
id: '[redacted]',
name: '[redacted]',
type: 'oauth',
version: '2.0',
state: false,
accessTokenUrl: '[redacted]',
authorizationUrl: `[redacted]`,
clientId: process.env.CONSUMER_KEY,
params: {
grant_type: 'authorization_code',
},
profileUrl: '[redacted]',
profile: (p) => {
return {
id: p.userId,
accounts: p.accounts,
}
},
},
],
pages: {
signIn: '/login',
},
callbacks: {
async jwt(token, user, account, profile) {
if(account) { // First time jwt callback is called, we have the extra user info
return {
...user,
// name: account.userId,
// accessToken: account.accessToken,
...account,
...profile
})
}
return token // Every subsequent request should just return the previous token
},
async session(_, token) {
return token // Pass the jwt to the session
},
},
jwt: {
secret: process.env.JWT_SIGNING_PRIVATE_KEY,
},
})
} Please read the jwt and session callback documentation: |
Beta Was this translation helpful? Give feedback.
-
A custom provider as seen above
--
Best
Jack
|
Beta Was this translation helpful? Give feedback.
-
Sounds good, thanks again for all your help
…--
Best
Jack
|
Beta Was this translation helpful? Give feedback.
-
@jackHedaya have you tried to add I've tested it using "next-auth": "^3.1.0". |
Beta Was this translation helpful? Give feedback.
-
Hi
I'm having serious difficulty storing and accessing tokens using a custom provider.
Here is my custom provider:
The API returns the following format and I'm not sure Next Auth is picking it up:
Calling
getSession
gives me{ email: null, sub: 'jackehedaya', iat: 1610257797, exp: 1612849797 }
.Printing the
signIn
callback, gives me this value foraccount
without expiration orrefresh_token
stored. However, I'm unable to get the accessToken signed.Really struggling here, please let me know what I might be doing wrong.
Beta Was this translation helpful? Give feedback.
All reactions