How to consume an provider API after user logged in #563
-
Your question What are you trying to do Documentation feedback
|
Beta Was this translation helpful? Give feedback.
Replies: 11 comments
-
I've never done it myself, but I believe you're going to want to use a custom callback on signin. After sign-in you can access the info in the JWT callback. See: https://next-auth.js.org/configuration/callbacks#jwt-callback
|
Beta Was this translation helpful? Give feedback.
-
Related to #447. |
Beta Was this translation helpful? Give feedback.
-
I see there is a session cookie named (This is the encoded jwt. Is there a better way to get this than reading the cookie directly? In the Edit (after response already given): That cookie is |
Beta Was this translation helpful? Give feedback.
-
@glawler If you pass the option |
Beta Was this translation helpful? Give feedback.
-
I'm sorry for being dense here, but I'm looking to get the token to add to a request. Specifically like
(If there's a better forum for this, slack, IRC, etc, please let me know.) |
Beta Was this translation helpful? Give feedback.
-
Oh, this looks to be fixed/amended in #513. Sorry for the noise. |
Beta Was this translation helpful? Give feedback.
-
Hi there! It looks like this issue hasn't had any activity for a while. It will be closed if no further activity occurs. If you think your issue is still relevant, feel free to comment on it to keep ot open. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Any update about this problem |
Beta Was this translation helpful? Give feedback.
-
Hi @MatteoGauthier. Could you please provide a bit more information about your usecase? What kind of provider are you using? Where do you need the access token? Do you maybe have a reproduction repository you can link to? |
Beta Was this translation helpful? Give feedback.
-
You can also add it to the session in callback. Session already have a property for accessToken. Then it is available client side if you need to send to some apis callbacks: {
session: async (session, user: any) => {
session.accessToken = user.accessToken;
return Promise.resolve(session)
},
jwt: async (token, user, account, profile, isNewUser) => {
const isSignIn = (user) ? true : false
if (isSignIn) {
token.accessToken = account.accessToken;
}
return Promise.resolve(token)
}
} |
Beta Was this translation helpful? Give feedback.
-
Example of consuming accessToken in a signIn callback to grab an email address from Linkedin in this discussion: #976 |
Beta Was this translation helpful? Give feedback.
You can also add it to the session in callback. Session already have a property for accessToken. Then it is available client side if you need to send to some apis