next-auth icon indicating copy to clipboard operation
next-auth copied to clipboard

sveltekit redirectTo component option not working

Open kinglouie opened this issue 1 year ago • 4 comments

Environment

System: OS: macOS 14.2.1 CPU: (10) arm64 Apple M2 Pro Memory: 97.36 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.7.0 - /opt/homebrew/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 10.1.0 - /opt/homebrew/bin/npm Browsers: Chrome: 122.0.6261.69 Safari: 17.2.1

Reproduction URL

https://github.com/kinglouie/authjsrepro2/

Describe the issue

After the user logs in I want to redirect to the original requested url, to achieve this I want to leverage the options prop of the SignIn.svelte component as seen here in the repro.

This feature is unfortunately broken at the moment. The redirectTo url is successfully transmitted by the hidden form input but the sveltekit specific signIn action is buggy in this snippet: https://github.com/nextauthjs/next-auth/blob/fbb8af526b075b9161e0bf7642c9ee730c3212b0/packages/frameworks-sveltekit/src/lib/actions.ts#L22-L28 the options obj does not contain the key redirectTo, instead the redirect url is in the callbackUrl and also in the redirect key. Options looks like this when logging it in my repro:

{
  callbackUrl: '/test',
  redirect: '/test',
  email: '[email protected]',
  password: 'test'
}

How to reproduce

Run the repro repository and click the sign in button on the index page, notice how it does not redirect to the /test url This should be an easy fix by correctly reading the callbackUrl from the options, my testing fix looks like this:

const callbackUrl = options.callbackUrl?.toString() ?? headers.get("Referer") ?? "/";

kinglouie avatar Feb 26 '24 17:02 kinglouie

Is there any progress with this issue?

onursoyer avatar May 07 '24 11:05 onursoyer

Just checking if there are any updates on this issue.

onursoyer avatar Oct 16 '24 01:10 onursoyer

Unfortunately I think non of the core maintainers spent any significant time on the sveltekit integration.

I tried this lib 8 months ago and hit several roadblocks for which I raised issues. None of them have been addressed or even acknowledged.

kinglouie avatar Oct 16 '24 06:10 kinglouie

Hi @kinglouie,

Did you end up finding a better approach or library that works more smoothly with SvelteKit? I'd love to hear if you have any recommendations for handling authentication or similar functionality in SvelteKit.

onursoyer avatar Oct 17 '24 09:10 onursoyer