fix(login): pass callbackUrl so local auth redirects to app after sign-in
All checks were successful
PR Checks / lint-test-and-docker-build (pull_request) Successful in 2m15s
All checks were successful
PR Checks / lint-test-and-docker-build (pull_request) Successful in 2m15s
After a successful Credentials sign-in, Auth.js was redirecting to its own built-in /auth/signin page because no callbackUrl was provided. Add a callbackUrl hidden field (pointing to the app root) so Auth.js redirects back to the application after local login completes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,10 +10,12 @@ const resolveErrorMessage = (value: string | null): string | null => {
|
||||
export const load: PageServerLoad = async ({ url }) => {
|
||||
const authUrl = process.env.AUTH_URL ?? env.AUTH_URL ?? '';
|
||||
const localAuthEnabled = (process.env.LOCAL_AUTH_ENABLED ?? env.LOCAL_AUTH_ENABLED) === 'true';
|
||||
const appRoot = authUrl.replace(/\/auth$/, '');
|
||||
|
||||
return {
|
||||
signinUrl: `${authUrl}/signin/synology`,
|
||||
localSigninUrl: `${authUrl}/signin/local`,
|
||||
callbackUrl: appRoot,
|
||||
localAuthEnabled,
|
||||
error: resolveErrorMessage(url.searchParams.get('error'))
|
||||
};
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
{#if data.localAuthEnabled}
|
||||
<form method="POST" action={data.localSigninUrl} class="mt-6 space-y-4">
|
||||
<input type="hidden" name="csrfToken" />
|
||||
<input type="hidden" name="callbackUrl" value={data.callbackUrl} />
|
||||
<div>
|
||||
<label class="text-sm font-medium text-slate-700" for="identifier">
|
||||
Username or email
|
||||
|
||||
Reference in New Issue
Block a user