Replies: 1 comment 4 replies
-
Hi @m4tt133 ! Thanks for providing all the info on how to reproduce this issue. I was able to set this up and I ended up having the same problem. Apparently Then the code would look something like this: // Ref to check against if we're currently fetching so we don't override current fetch
const fetching = useRef(false);
async function fetcher() {
if (fetching.current) return;
fetching.current = true;
// Get the most up to date session
const currentSession = await getSession();
if (!currentSession) {
fetching.current = false;
return null;
}
const user = await swell.account.login(currentSession?.user?.email, {
password_token: currentSession?.user?.token,
});
fetching.current = false;
return user;
}
const { data: session } = useSession();
const { data, error } = useSWR(session, fetcher);
It's a bit odd that useSession would not return the most up to date session when passed to useSWR. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
I am currently using next-auth for session management, and I am having issues with the custom Google sign-in flow.
The problem happens when the user tries to log in to an account for a second or more time after the initial account has been created.
Sometimes the front end doesn't seem to log in to swell, I assume that it is a matter of different tokens that are sent from Google and the existing ones for an account that is already in Swell's database, and was created using only Google's token on initial account creation.
Assuming that we implement the code mentioned on your community hub:
When I do change the tab the code refreshes and sometimes the authentication process passes.
Here's my request to a backend - next-auth:
Here's token generation:
Here's the code that I am using to check if the session is present (when Google authenticated properly):
I am aware that useSWR will try to revalidate the query and begin a new Swell session, but the session token stored in the next-auth session object stays the same, that's why I am having a hard time understanding the problem.
And here's a screenshot of what's happening:
1 - Next-auth session (No problems at all)
0 - Swell Session (Sometimes it drops)
I would be really grateful for some help in resolving the issue / providing some guidance on how to approach this.
I think that it would also be really helpful for those that are building using Next.js and Swell.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions