nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
23.8k stars 3.27k forks source link

sveltekit redirectTo component option not working #10135

Open kinglouie opened 5 months ago

kinglouie commented 5 months ago

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: 'test@test.com',
  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") ?? "/";
onursoyer commented 3 months ago

Is there any progress with this issue?