Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix incorrect auth redirects

Blue Mouse0277adfde8f5
diff --git a/web/app/providers/AuthProvider.tsx b/web/app/providers/AuthProvider.tsx
index 434c6d8d4..eba6ac927 100644
--- a/web/app/providers/AuthProvider.tsx
+++ b/web/app/providers/AuthProvider.tsx
@@ -3,7 +3,9 @@ import { createContext, useCallback, useContext, useEffect, useState } from 'rea
import { authMe } from '~/api'
import { User } from '~/lib/models/User'
+import { getAccessToken } from '~/utils/accessToken'
import { logout as logoutCookies } from '~/utils/auth'
+import { getRefreshToken } from '~/utils/refreshToken'
interface AuthContextType {
isAuthenticated: boolean
@@ -83,6 +85,27 @@ export const AuthProvider = ({ children, initialIsAuthenticated }: AuthProviderP
return () => abortController.abort()
}, [initialIsAuthenticated, loadUser])
+ useEffect(() => {
+ const abortController = new AbortController()
+
+ if (initialIsAuthenticated) {
+ loadUser(abortController.signal)
+ return () => abortController.abort()
+ }
+
+ // Client-side rehydration: if tokens exist but SSR did not receive cookies
+ const hasClientToken = Boolean(getAccessToken() || getRefreshToken())
+
+ if (hasClientToken) {
+ setIsLoading(true)
+ loadUser(abortController.signal)
+ return () => abortController.abort()
+ }
+
+ setIsLoading(false)
+ return () => abortController.abort()
+ }, [initialIsAuthenticated, loadUser])
+
return (
<AuthContext.Provider
value={{