session.accessToken is undefined #913
-
Your question What are you trying to do // api/auth/[...nextauth].ts import NextAuth from 'next-auth';
import Providers from 'next-auth/providers';
const options = {
providers: [
Providers.Auth0({
clientId: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET,
domain: process.env.AUTH0_DOMAIN,
}),
],
secret: process.env.NEXTAUTH_SECRET,
jwt: {
encryption: true,
secret: process.env.NEXTAUTH_JWT_SECRET,
},
pages: {
signIn: '/auth',
},
};
export default (req, res) => NextAuth(req, res, options);
Feedback
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 25 replies
-
Could you please provide a bit more information about how you set up Auth0 with |
Beta Was this translation helpful? Give feedback.
-
@balazsorban44 Updated the question. |
Beta Was this translation helpful? Give feedback.
-
What do you mean by:
Right now, You can use the Please refer to the documentation:
To access it from client and server-side: |
Beta Was this translation helpful? Give feedback.
-
I tried to use I tried to access accessToken as in const IndexPage: NextPage = () => {
const classes = useStyles();
const [session, loading] = useSession();
const login = () => signIn('auth0');
return (
<>
{!session && (
<b>
Sign in
</b>
<Button onClick={login} color="primary" variant="contained">
Sign In
</Button>
</AuthLayout>
)}
{session && (
<div>
<p>Session : {session.expires}</p>
<p>Token : {session.accessToken}</p>
</div>
)}
</>
);
};
export default IndexPage; but session.accessToken is |
Beta Was this translation helpful? Give feedback.
-
You have to forward it in the |
Beta Was this translation helpful? Give feedback.
-
https://codesandbox.io/s/quizzical-wave-phrfj?file=/pages/api/auth/%5B...nextauth%5D.ts Here is a working CodeSandbox for you. :) The problem was that you did not check if I also added the I created an Auth0 client and tested it, so I am sure it should work! |
Beta Was this translation helpful? Give feedback.
@iamchathu
https://codesandbox.io/s/quizzical-wave-phrfj?file=/pages/api/auth/%5B...nextauth%5D.ts
Here is a working CodeSandbox for you. :)
The problem was that you did not check if
account
existed injwt
. I understood your intention with using optional chaining, but remember, it will just return undefined foraccount
wheneverjwt
re-runs, resetting youraccessToken
you set in the first run.I also added the
accessToken
to the session with the help of thesession
callback.I created an Auth0 client and tested it, so I am sure it should work!