Replies: 8 comments 9 replies
-
It happens with me all time. |
Beta Was this translation helpful? Give feedback.
-
I don't think it is, the first request is made through server side rendering. I await the refresh token call to return the newly received token and then the component call should be called retrieving the updated token since I'm waiting for the response to finish. I don't how else you are supposed to implement a refresh token flow. One thing to point out is that I need to make a server side call in order for Apollojs to send the access token with the headers. I tried doing that client side only but for some reason it wont' retrieve the session when using the useSession hook. |
Beta Was this translation helpful? Give feedback.
-
@remcotak Do you use Provider? https://next-auth.js.org/getting-started/client#provider |
Beta Was this translation helpful? Give feedback.
-
I have a similar issue, but not quite the same, and it only happens at build time. Note that this only happens in dev mode, and may not be an issue in production. Let me try to describe what happens in my case:
I didn't want to open a separate Issue for this because I'm not sure is this a bug or just a side-effect of fast refresh or something else that just occurs during build in dev mode. |
Beta Was this translation helpful? Give feedback.
-
I think point 5 of what @vstrider mentioned could probably be cause of this going wrong. In order to avoid this problem I only used client side authentication and not while ssr. |
Beta Was this translation helpful? Give feedback.
-
Sharing my solution with you, im Brazilian so my English Isn't that much, but here we go, I've got a Semaphore and a timeout(please, don't judge me), timeout stores a "session" for 3000ms(can be less, but in my case is enough), then while I have a "session" stored I only return it, then semaphore execute only first and stores it, is working on section and in refresh, just one execution and every sub call return the stored(3000ms)
then on start of session
after first semaphore release, all others take 1ms and it working for 1 call, 2 calls at same time, 1 call then 2 calls, and this make refresh token from |
Beta Was this translation helpful? Give feedback.
-
It may be caused by |
Beta Was this translation helpful? Give feedback.
-
That was happening for me because I had both useSession and getSession being used in the same component, like so: export default function Auth() {
const { data: session } = useSession({
required: true
})
// rest of the code...
}
export const getServerSideProps = async (context) => {
const session = await getSession(context);
if (session) {
return {
redirect: {
destination: "/dashboard",
permanent: false,
},
};
}
return {
props: {},
};
} And since useSession (line 3) and getSession (line ) both trigger the JWT callback, I beleive the second time it was being called was wrong because it was not yet updated, or something like that. I was able to fix it by using only one of them, it didn't matter which one |
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.
-
Describe the bug
When using the getSession function inside getInitialProps/getServerSideProps AND using the useSession hook in a component on the same page, the JWT callback gets called twice, even when using the provider in _app.js. When using Refresh Token Rotation flow this is a big problem since the first time the JWT callback gets called it might go into the refresh token flow and return the updated access token, but in the 2nd JWT callback the access token isn't updated with the newly received access token.
Steps to reproduce
Expand the next-auth tutorial code with the Refresh Token Rotation code provided here https://next-auth.js.org/tutorials/refresh-token-rotation. Use the getSession inside getServerSideProps and on the same page let a component use the useSession hook.
Expected behavior
I expect the useSession hook to use the data from the getSession call
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
Beta Was this translation helpful? Give feedback.
All reactions