feat(auth): add startup auth status check with device id fallback
Add AuthStatusChecker mounted in RootProviders to dispatch AuthStatusCheckSubmitted on mount. The new checkAuthStatusActor retrieves the device id, checks for an existing login or guest token, and falls back to a guest login API call when neither is present. Wires the new event/actor through the auth machine to enable automatic session restoration and guest-mode bootstrap.
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
*
|
||||
* 把所有功能 Provider 串起来:
|
||||
* AuthProvider → UserProvider → SidebarProvider → ChatProvider
|
||||
* + OAuthSessionSync 桥接器(监听 NextAuth session → auth machine)
|
||||
* + AuthStatusChecker(启动时一次:派发 AuthStatusCheckSubmitted)
|
||||
* + OAuthSessionSync (持续监听 NextAuth session → auth machine)
|
||||
*
|
||||
* 它们始终挂载,保证各页面直接 `use*State()` / `use*Dispatch()` 即可,
|
||||
* 无需在每个页面单独包裹。
|
||||
@@ -14,6 +15,7 @@
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
import { AuthProvider } from "@/stores/auth/auth-context";
|
||||
import { AuthStatusChecker } from "@/stores/auth/auth-status-checker";
|
||||
import { OAuthSessionSync } from "@/stores/auth/oauth-session-sync";
|
||||
import { ChatProvider } from "@/stores/chat/chat-context";
|
||||
import { SidebarProvider } from "@/stores/sidebar/sidebar-context";
|
||||
@@ -26,8 +28,10 @@ export interface RootProvidersProps {
|
||||
export function RootProviders({ children }: RootProvidersProps) {
|
||||
return (
|
||||
<AuthProvider>
|
||||
{/* OAuthSessionSync 必须放在 AuthProvider 内部(依赖 useAuthDispatch/useAuthState),
|
||||
* 也必须在 ChatProvider 外部(ChatProvider 内部组件可能在 sync 完成前就需要登录态) */}
|
||||
{/* AuthStatusChecker 必须在 AuthProvider 内部(依赖 useAuthDispatch),
|
||||
* 必须在 UserProvider/ChatProvider 外部(它们可能在 init 完成前就 mount) */}
|
||||
<AuthStatusChecker />
|
||||
{/* OAuthSessionSync 同样依赖 AuthProvider 上下文 */}
|
||||
<OAuthSessionSync />
|
||||
<UserProvider>
|
||||
<SidebarProvider>
|
||||
|
||||
Reference in New Issue
Block a user