auth: smart login/logout redirect back to original page
Some checks failed
CI / update (push) Failing after 0s

Login link now includes callbackUrl for the current page. Logout
redirects intelligently: stays on public pages, falls back to the
recipe detail for /edit/[name], to the recipe root for auth-only
sub-routes (add, favorites, to-try, admin), and to / for cospend.
This commit is contained in:
2026-02-26 19:25:43 +01:00
parent dd4680e946
commit 2f4c3ac1ae
3 changed files with 34 additions and 4 deletions

View File

@@ -6,7 +6,8 @@ export const load: PageServerLoad = async ({ fetch, locals, params }) => {
const session = await locals.auth();
if (!session?.user?.nickname) {
throw redirect(302, `/${params.recipeLang}`);
const callbackUrl = encodeURIComponent(`/${params.recipeLang}/favorites`);
throw redirect(302, `/login?callbackUrl=${callbackUrl}`);
}
try {

View File

@@ -6,7 +6,12 @@ import { dbConnect } from '$utils/db';
export const load: PageServerLoad = async ({ locals, params }) => {
const session = await locals.auth();
if (!session?.user?.groups?.includes('rezepte_users')) {
if (!session?.user) {
const callbackUrl = encodeURIComponent(`/${params.recipeLang}/to-try`);
throw redirect(302, `/login?callbackUrl=${callbackUrl}`);
}
if (!session.user.groups?.includes('rezepte_users')) {
throw redirect(302, `/${params.recipeLang}`);
}