From bb2ae41232e85719208ecd008ed0297ba5e45c05 Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 17 Jun 2026 10:06:07 +0800 Subject: [PATCH] fix(auth): include OAuth backend-sync phase in isLoading derivation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The AuthState.isLoading derivation in auth-context.tsx covered the OAuth redirect phase (loadingOAuth) but NOT the backend-sync phase that runs after the OAuth callback returns (syncingGoogleBackend / syncingFacebookBackend). Any UI that read isLoading would incorrectly report "not loading" during the backend token-exchange round-trip. Add the two missing state.matches() lines so isLoading is true for the entire OAuth login window (button click → OAuth redirect → callback → backend sync). Note: in the current OAuth flow the user is on /chat during the sync phase (NextAuth redirected them there), so the splash/auth button is not actually visible to reflect the new true value. The fix is still correct because: - Conceptually aligned: any in-flight login op is "loading" - Defense in depth: future UI on /chat that consumes isLoading will get accurate feedback - Non-regression: only makes isLoading more permissive (true more often), never false-fires A visible /chat overlay during the sync phase would be a separate, larger change — noted in the planning doc but not in this commit. --- src/stores/auth/auth-context.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stores/auth/auth-context.tsx b/src/stores/auth/auth-context.tsx index a255ea67..abf038ce 100644 --- a/src/stores/auth/auth-context.tsx +++ b/src/stores/auth/auth-context.tsx @@ -61,11 +61,14 @@ export function AuthProvider({ children }: AuthProviderProps) { password: state.context.password, username: state.context.username, confirmPassword: state.context.confirmPassword, - // isLoading 覆盖邮箱登录 / 邮箱注册 / OAuth 跳转(NextAuth 重定向期间)/ 显式游客登录 + // isLoading 覆盖邮箱登录 / 邮箱注册 / OAuth 跳转(NextAuth 重定向期间)/ + // OAuth 回调后端 sync / 显式游客登录 isLoading: state.matches("loadingEmailLogin") || state.matches("loadingEmailRegister") || state.matches("loadingOAuth") || + state.matches("syncingGoogleBackend") || + state.matches("syncingFacebookBackend") || state.matches("loadingGuestLogin"), errorMessage: state.context.errorMessage, loginStatus: state.context.loginStatus,