From f6a6ddab283ea34b62cde0ec732496461de84dff Mon Sep 17 00:00:00 2001 From: Abdulfetah Suudi Date: Mon, 9 Feb 2026 20:59:50 +0300 Subject: [PATCH] Enhance useAuth with hydration support This is real issue during development. HMR is followed subsequently by SSR at that time hydration isn't completed and it throws error. But if we check hydration completion and retrieve data independently things work smoothly. --- docs/start/framework/react/guide/authentication.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/start/framework/react/guide/authentication.md b/docs/start/framework/react/guide/authentication.md index f42fbc220fe..b64f38c43e8 100644 --- a/docs/start/framework/react/guide/authentication.md +++ b/docs/start/framework/react/guide/authentication.md @@ -154,8 +154,14 @@ export function AuthProvider({ children }: { children: ReactNode }) { } export function useAuth() { + const hydrated = useHydrated() const context = useContext(AuthContext) + if (!context) { + if (!hydrated) { + const { data: user, isLoading, refetch } = useServerFn(getCurrentUserFn) + return { user, isLoading, refetch } + } throw new Error('useAuth must be used within AuthProvider') } return context