Closed gorbulls456667 closed 3 months ago
I am unable to replicate your issue and it's working fine for me in both cases. Do you have a reproduction or can share your code with us?
Sure, this is a new Next.js project that I created: authkit-redirect-reproduction
To reproduce:
You need to set up a .env file with your WorkOS staging credentials:
WORKOS_CLIENT_ID="******"
WORKOS_API_KEY="******"
WORKOS_REDIRECT_URI="http://localhost:3000/auth/callback" # configured in the WorkOS dashboard
WORKOS_COOKIE_PASSWORD="NRjSk/Zwd/0cwnyl9PKQ3G7oK7YxGpSt"
Replace the asterisks with your WorkOS credentials.
Once the dependencies are installed and the server is running with npm run dev
, go to the page "http://localhost:3000/protected".
You will be redirected to the hosted Authkit page. Log in.
After logging in, instead of being redirected to the page "http://localhost:3000/protected", I am redirected to the page "http://localhost:3000/dashboard"."
I observed that the issue arises when trying to access a protected page (https://authkit-redirect-reproduction.vercel.app/protected) directly from the browser's address bar. When attempting to access this protected page (https://authkit-redirect-reproduction.vercel.app/protected) from the address bar and then logging in, the redirection defaults to "/dashboard" instead of navigating to the intended page, which should be "/protected".
Thanks, that helped us reproduce the issue. We've found a solution and will put out a fix soon!
Awesome! Thanks!
This new issue is a continuation of https://github.com/workos/authkit-nextjs/issues/11, which has been previously closed.
I'm currently trying out the new package renamed
@workos-inc/authkit-nextjs
version0.4.0
and I'm encountering an issue with post-login redirection within my next.js application.Currently, the default returnPathname in the callback route, is functioning correctly:
However, I've noticed that when I use
in a protected page and then successfully log in, I'm not redirected to the page I was originally trying to reach, but rather to the default returnPathname set in the callback route.
It seems that the current behavior is not what is desired. Similarly, as @PaulAsjes mentioned, "if your user tries to access a protected page (e.g. /admin) without being logged in, after authenticating via AuthKit they'll be redirected to the page they were trying to access rather than /."