Fix redirect loop after admin setup by invalidating setup cache
Build and Push Docker Image / build (push) Successful in 2m9s
Details
Build and Push Docker Image / build (push) Successful in 2m9s
Details
The setupCheckHandle hook caches whether setup is needed for 1 minute. After creating the admin, this cache wasn't cleared, causing a redirect loop between /login and /setup. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
274b13fe1e
commit
6be67e2329
|
|
@ -11,6 +11,14 @@ import { supabaseAdmin } from '$lib/server/supabase';
|
||||||
let setupCheckCache: { needsSetup: boolean; checkedAt: number } | null = null;
|
let setupCheckCache: { needsSetup: boolean; checkedAt: number } | null = null;
|
||||||
const SETUP_CACHE_TTL = 60000; // 1 minute cache
|
const SETUP_CACHE_TTL = 60000; // 1 minute cache
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidate the setup check cache
|
||||||
|
* Call this after creating the first admin user
|
||||||
|
*/
|
||||||
|
export function invalidateSetupCache() {
|
||||||
|
setupCheckCache = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supabase authentication hook
|
* Supabase authentication hook
|
||||||
* Sets up the Supabase client with cookie handling for SSR
|
* Sets up the Supabase client with cookie handling for SSR
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { fail, redirect } from '@sveltejs/kit';
|
||||||
import type { Actions, PageServerLoad } from './$types';
|
import type { Actions, PageServerLoad } from './$types';
|
||||||
import { supabaseAdmin } from '$lib/server/supabase';
|
import { supabaseAdmin } from '$lib/server/supabase';
|
||||||
import { sendEmail, wrapInMonacoTemplate } from '$lib/server/email';
|
import { sendEmail, wrapInMonacoTemplate } from '$lib/server/email';
|
||||||
|
import { invalidateSetupCache } from '../../hooks.server';
|
||||||
|
|
||||||
export const load: PageServerLoad = async () => {
|
export const load: PageServerLoad = async () => {
|
||||||
// Check if any users exist in the system
|
// Check if any users exist in the system
|
||||||
|
|
@ -249,6 +250,9 @@ export const actions: Actions = {
|
||||||
// Non-critical - continue anyway since the account was created successfully
|
// Non-critical - continue anyway since the account was created successfully
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the setup cache so other routes don't redirect back to /setup
|
||||||
|
invalidateSetupCache();
|
||||||
|
|
||||||
// Success - redirect to login
|
// Success - redirect to login
|
||||||
throw redirect(303, '/login?setup=complete');
|
throw redirect(303, '/login?setup=complete');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue