'Sveltekit newly created cookie is not showing in the hook's getSession() function
Summary
Hello everyone, as in this topic, I'm experimenting issues with my newly created cookie. I'm implementing Oauth2 to authenticate with Discord account in my SvelteKit project. The flow is as follows:
- User clicks on
index.sveltehyperlink which redirect to/api/authendpoint in my app. - The
/api/authendpoint is managed byauth.tswhich makes a request to Discord Authentification Endpoint using my ClientID, RedirectURI (/api/callback) and Scope identify - Discord redirects to my callback endpoint
/api/callbackwith a code set in the url, that a retrive usingurl.searchParams.get('code') - Then my callback function redirect the user to my main
index.sveltefile by setting a cookie containing the code sent by discord, I coded it to create the cookie no matter if the code is correctly retrived or no so I would know if the problem was here - In my
index.sveltefile, I call the getSession inhooks.tsto retrieve the cookie value and console log it.
The attended behavior is that after my callback redirection, the cookie should appear on the main page and it's value printed to my console. Which is not the case.
Instead I have to refresh my index.svelte page to get the cookie.
The link code to access /api/auth endpoint from index.svelte:
<a rel="external" href="/api/auth">
Connexion
</a>
All my redirections are set with a status code of 302.
Reproduction
You can find all my files at pastebin.com by following this link.
Anyone got an idea ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
