sveltekit redirectTo component option not working
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") ?? "/";
Is there any progress with this issue?
Just checking if there are any updates on this issue.
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.
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.