Fix auth throttling causing login loops by adding forced session checks
All checks were successful
Build And Push Image / docker (push) Successful in 3m27s

Add optional force parameter to checkAuth() to bypass throttling during
critical authentication flows like login, middleware, and initial auth
verification. This prevents iOS Safari login loops while maintaining
throttling for regular session checks.
This commit is contained in:
2025-08-07 17:01:01 +02:00
parent 2843bcf4f5
commit 616490dfef
4 changed files with 147 additions and 10 deletions

View File

@@ -66,9 +66,9 @@ export const useAuth = () => {
while (!sessionSuccess && attempts < maxAttempts) {
attempts++;
console.log(`🔄 Session check attempt ${attempts}/${maxAttempts}`);
console.log(`🔄 Forced session check attempt ${attempts}/${maxAttempts}`);
sessionSuccess = await checkAuth();
sessionSuccess = await checkAuth(true); // Force bypass throttling for login
if (!sessionSuccess && attempts < maxAttempts) {
console.log('⏳ Session not ready, waiting 500ms...');
@@ -154,18 +154,19 @@ export const useAuth = () => {
const lastSessionCheck = ref(0);
const SESSION_CHECK_THROTTLE = 5000; // 5 seconds minimum between checks
// Check authentication status with debouncing
const checkAuth = async () => {
// Check authentication status with smart throttling
const checkAuth = async (force = false) => {
const now = Date.now();
// Throttle session checks to prevent iOS Safari loops
if (now - lastSessionCheck.value < SESSION_CHECK_THROTTLE) {
// Allow forced checks to bypass throttling for critical operations
if (!force && now - lastSessionCheck.value < SESSION_CHECK_THROTTLE) {
console.log('🚫 Session check throttled, using cached result');
return !!user.value;
}
try {
console.log('🔄 Performing throttled session check...');
const logType = force ? 'forced' : 'throttled';
console.log(`🔄 Performing ${logType} session check...`);
lastSessionCheck.value = now;
const response = await $fetch<{