You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my NextJS 14 (App Router) application, attempting to sign the user in using the Slack OIDC provider with the recommended PKCE auth flow works after starting the dev server, but NOT after logging out and logging back in to the application. In the first case, signInWithOAuth correctly sets the verifier token in the browser, but in the second case, it does not.
The issue appears to be with this function here: setItemAsync. As described above, it correctly sets the storedCodeVerifier immediately after starting the dev server (or making any change to the code that causes a hot-reload), but it does not do so if the user logs out (via supabase.auth.signOut()).
I was able to fix this behavior by instead using NextJS's cookies() module. I simply set const cookieStore = cookies() then replaced await setItemAsync(storage, ${storageKey}-code-verifier, storedCodeVerifier) with cookieStore.set(${storageKey}-code-verifier, storedCodeVerifier)
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Create a NextJS application that uses signInWithOAuth with Slack (or probably any provider) in a server-side function for login. redirectTo should be set to a route.ts file
In your route.ts file, use supabase.auth.exchangeCodeForSession(code) to handle the second step of the login process.
I also recommend modifying the Helpers.js file to log the stored cookies just after the setItemAsync() function. I used const cookieStore = cookies() and console.log(cookieStore). This helps reveal exactly what cookies the setItemAsync() function is setting.
run rm -rf .next and yarn dev to clear the cached Next files and start the dev server
Log into the application using your chosen provider. -- See that you can successfully log in and that the console log after setItemAsync() shows the expected cookies.
Log out of your application using supabase.auth.signOut()
Immediately try to log in a second time and see that you get an error that reads: "both auth code and code verifier should be non-empty'. You should also see that your console log shows no cookies present.
Steps to temporarily fix:
in Helpers.js, within the getCodeChallengeAndMethod function, add const cookieStore = cookies() then replace await setItemAsync(storage, ${storageKey}-code-verifier, storedCodeVerifier) with cookieStore.set(${storageKey}-code-verifier, storedCodeVerifier)
run rm -rf .next, then run yarn dev. Repeat steps 5-7 above to see that it now works.
Bug report
Describe the bug
In my NextJS 14 (App Router) application, attempting to sign the user in using the Slack OIDC provider with the recommended PKCE auth flow works after starting the dev server, but NOT after logging out and logging back in to the application. In the first case, signInWithOAuth correctly sets the verifier token in the browser, but in the second case, it does not.
The issue appears to be with this function here: setItemAsync. As described above, it correctly sets the
storedCodeVerifier
immediately after starting the dev server (or making any change to the code that causes a hot-reload), but it does not do so if the user logs out (viasupabase.auth.signOut()
).I was able to fix this behavior by instead using NextJS's
cookies()
module. I simply setconst cookieStore = cookies()
then replacedawait setItemAsync(storage, ${storageKey}-code-verifier, storedCodeVerifier)
withcookieStore.set(${storageKey}-code-verifier, storedCodeVerifier)
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
redirectTo
should be set to a route.ts filesupabase.auth.exchangeCodeForSession(code)
to handle the second step of the login process.setItemAsync()
function. I usedconst cookieStore = cookies()
andconsole.log(cookieStore)
. This helps reveal exactly what cookies thesetItemAsync()
function is setting.rm -rf .next
andyarn dev
to clear the cached Next files and start the dev serversetItemAsync()
shows the expected cookies.supabase.auth.signOut()
Steps to temporarily fix:
getCodeChallengeAndMethod
function, addconst cookieStore = cookies()
then replaceawait setItemAsync(storage, ${storageKey}-code-verifier, storedCodeVerifier)
withcookieStore.set(
${storageKey}-code-verifier, storedCodeVerifier)
rm -rf .next
, then runyarn dev
. Repeat steps 5-7 above to see that it now works.System information
Additional context
Discussion that lead to the decision to file this Issue: https://discord.com/channels/839993398554656828/1274475845028675688/1277988844024631406
The text was updated successfully, but these errors were encountered: