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

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:
2026-02-22 14:53:45 -05:00
parent 345da2ef7a
commit 348aac996d
2 changed files with 3 additions and 0 deletions

View File

@@ -10,10 +10,12 @@ const resolveErrorMessage = (value: string | null): string | null => {
export const load: PageServerLoad = async ({ url }) => { export const load: PageServerLoad = async ({ url }) => {
const authUrl = process.env.AUTH_URL ?? env.AUTH_URL ?? ''; const authUrl = process.env.AUTH_URL ?? env.AUTH_URL ?? '';
const localAuthEnabled = (process.env.LOCAL_AUTH_ENABLED ?? env.LOCAL_AUTH_ENABLED) === 'true'; const localAuthEnabled = (process.env.LOCAL_AUTH_ENABLED ?? env.LOCAL_AUTH_ENABLED) === 'true';
const appRoot = authUrl.replace(/\/auth$/, '');
return { return {
signinUrl: `${authUrl}/signin/synology`, signinUrl: `${authUrl}/signin/synology`,
localSigninUrl: `${authUrl}/signin/local`, localSigninUrl: `${authUrl}/signin/local`,
callbackUrl: appRoot,
localAuthEnabled, localAuthEnabled,
error: resolveErrorMessage(url.searchParams.get('error')) error: resolveErrorMessage(url.searchParams.get('error'))
}; };

View File

@@ -45,6 +45,7 @@
{#if data.localAuthEnabled} {#if data.localAuthEnabled}
<form method="POST" action={data.localSigninUrl} class="mt-6 space-y-4"> <form method="POST" action={data.localSigninUrl} class="mt-6 space-y-4">
<input type="hidden" name="csrfToken" /> <input type="hidden" name="csrfToken" />
<input type="hidden" name="callbackUrl" value={data.callbackUrl} />
<div> <div>
<label class="text-sm font-medium text-slate-700" for="identifier"> <label class="text-sm font-medium text-slate-700" for="identifier">
Username or email Username or email