Your question
According to this documentation, when I use this configuration I should expect to see an accessToken property in session. I see every property in the example but the accessToken. What am I missing?
const options = {
pages: {
signIn: '/login'
},
session: {
jwt: true
},
callbacks: {
session: async (session: any, jwt: any) => {
console.log(session)
console.log(jwt)
return Promise.resolve(session)
}
},
providers: [
Providers.Auth0({
domain: publicRuntimeConfig.AUTH0_DOMAIN,
clientId: publicRuntimeConfig.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_APPLICATIONS_NEXTJS_CLIENTSECRET ?? ""
})
],
debug: true
}
What are you trying to do
I want to use getSession() in my client to retrieve the access token so I can include it in the Bearer header of a request to another API in my application.
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
@jonathaneckman You can add it back in using callbacks for the session (you can also do that for the refresh token too).
This worked for me:
callbacks: {
jwt: async (token, user, account) => {
if (account) {
token.accessToken = account.accessToken;
token.refreshToken = account.refreshToken;
}
return Promise.resolve(token);
},
session: async (session, token) => {
session.accessToken = token.accessToken;
session.refreshToken = token.refreshToken;
return Promise.resolve(session);
},
},
That was it. Thank you!
I have a similar case with a custom Oauth, but my account is null... Any idea why?
hmm, odd. I added the user param (on JWT callback) to avoid the null problem on my side when I first commented but there may be a better solution