Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: session validation timeouts
Kyle Mendella267b91506ec
diff --git a/backend/internal/api/auth_handler.go b/backend/internal/api/auth_handler.goindex 88ce9f2e4..773024401 100644--- a/backend/internal/api/auth_handler.go+++ b/backend/internal/api/auth_handler.go@@ -124,15 +124,13 @@ func (h *AuthHandler) Login(c *gin.Context) {}// Set token cookie- c.SetCookie(- "token",- tokenPair.AccessToken,- int(time.Until(tokenPair.ExpiresAt).Seconds()),- "/",- "",- c.Request.TLS != nil, // secure if HTTPS- true, // httpOnly- )+ c.SetSameSite(http.SameSiteLaxMode)+ maxAge := int(time.Until(tokenPair.ExpiresAt).Seconds())+ if maxAge < 0 {+ maxAge = 0+ }+ secure := c.Request.TLS != nil+ c.SetCookie("token", tokenPair.AccessToken, maxAge, "/", "", secure, true)// Return successful responsec.JSON(http.StatusOK, LoginResponse{@@ -228,15 +226,13 @@ func (h *AuthHandler) RefreshToken(c *gin.Context) {}// Set new token cookie- c.SetCookie(- "token",- tokenPair.AccessToken,- int(time.Until(tokenPair.ExpiresAt).Seconds()),- "/",- "",- c.Request.TLS != nil, // secure if HTTPS- true, // httpOnly- )+ c.SetSameSite(http.SameSiteLaxMode)+ maxAge := int(time.Until(tokenPair.ExpiresAt).Seconds())+ if maxAge < 0 {+ maxAge = 0+ }+ secure := c.Request.TLS != nil+ c.SetCookie("token", tokenPair.AccessToken, maxAge, "/", "", secure, true)c.JSON(http.StatusOK, gin.H{"success": true,diff --git a/backend/internal/api/oidc_handler.go b/backend/internal/api/oidc_handler.goindex 437d91fe6..7c9a2d057 100644--- a/backend/internal/api/oidc_handler.go+++ b/backend/internal/api/oidc_handler.go@@ -2,6 +2,7 @@ package apiimport ("net/http"+ "time""github.com/gin-gonic/gin""github.com/ofkm/arcane-backend/internal/config"@@ -118,15 +119,13 @@ func (h *OidcHandler) HandleOidcCallback(c *gin.Context) {return}- c.SetCookie(- "token",- tokenPair.AccessToken,- int(tokenPair.ExpiresAt.Unix()),- "/",- "",- c.Request.TLS != nil,- true,- )+ c.SetSameSite(http.SameSiteLaxMode)+ maxAge := int(time.Until(tokenPair.ExpiresAt).Seconds())+ if maxAge < 0 {+ maxAge = 0+ }+ secure := c.Request.TLS != nil+ c.SetCookie("token", tokenPair.AccessToken, maxAge, "/", "", secure, true)c.JSON(http.StatusOK, gin.H{"success": true,diff --git a/frontend/src/lib/utils/redirect.util.ts b/frontend/src/lib/utils/redirect.util.tsindex 62be7fe29..bcd1cb225 100644--- a/frontend/src/lib/utils/redirect.util.ts+++ b/frontend/src/lib/utils/redirect.util.ts@@ -1,8 +1,6 @@import type { User } from '$lib/types/user.type';import type { Settings } from '$lib/types/settings.type';-// Returns the path to redirect to based on the current path and user authentication status-// If no redirect is needed, it returns nullexport function getAuthRedirectPath(path: string, user: User | null, settings: Settings | null) {const isSignedIn = !!user;@@ -17,10 +15,14 @@ export function getAuthRedirectPath(path: string, user: User | null, settings: Spath.startsWith('/img') ||path === '/favicon.ico';- const isPublicPath = ['/health', '/healthz'].includes(path);+ // Root should not render; redirect explicitly+ if (path === '/') {+ return isSignedIn ? '/dashboard' : '/auth/login';+ }+const isOnboardingPath = path === '/onboarding' || path.startsWith('/onboarding');- if (!isSignedIn && !isUnauthenticatedOnlyPath && !isPublicPath) {+ if (!isSignedIn && !isUnauthenticatedOnlyPath) {return '/auth/login';}@@ -40,3 +42,34 @@ export function getAuthRedirectPath(path: string, user: User | null, settings: Sreturn null;}++// Lightweight session validator+async function validateSession(): Promise<boolean> {+ if (typeof window === 'undefined') return true; // SSR: skip+ try {+ const res = await fetch('/api/auth/validate', { credentials: 'include' });+ return res.ok;+ } catch {+ return false;+ }+}++// Session-aware redirect+export async function getAuthRedirectPathWithSessionCheck(+ path: string,+ user: User | null,+ settings: Settings | null+): Promise<string | null> {+ let effectiveUser = user;++ if (effectiveUser) {+ const valid = await validateSession();+ if (!valid) {+ effectiveUser = null;+ // Use normal logic for signed-out state; do not return '/'+ return getAuthRedirectPath(path, null, settings);+ }+ }++ return getAuthRedirectPath(path, effectiveUser, settings);+}diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelteindex a8a1e3d39..be030ba79 100644--- a/frontend/src/routes/+layout.svelte+++ b/frontend/src/routes/+layout.svelte@@ -9,7 +9,7 @@import { goto } from '$app/navigation';import userStore from '$lib/stores/user-store';import settingsStore from '$lib/stores/config-store';- import { getAuthRedirectPath } from '$lib/utils/redirect.util';+ import { getAuthRedirectPathWithSessionCheck } from '$lib/utils/redirect.util';import LoadingIndicator from '$lib/components/loading-indicator.svelte';let { children, data } = $props();@@ -30,10 +30,17 @@const currentUser = $userStore || user;const currentSettings = $settingsStore || settings;- const redirectPath = getAuthRedirectPath(page.url.pathname, currentUser, currentSettings);- if (redirectPath) {- goto(redirectPath);- }+ // Run session-aware redirect; avoid loops if already on the target path+ (async () => {+ const redirectPath = await getAuthRedirectPathWithSessionCheck(+ page.url.pathname,+ currentUser,+ currentSettings+ );+ if (redirectPath && redirectPath !== page.url.pathname) {+ goto(redirectPath);+ }+ })();});const isNavigating = $derived(navigating.type !== null);