用途:为 Expo 构建的 React Native 应用提供认证实现参考,覆盖登录流程、Google/Apple 登录、令牌管理、会话保持与调试。
主要能力:使用 expo-auth-session 配合 expo-web-browser 实现 OAuth 流程(以 Google 为例,通过 Google.useAuthRequest 传入 iOS 与 Web 客户端 ID);用 expo-secure-store 保存 access token 与 refresh token(而非 AsyncStorage);提供基于 Context 的 AuthProvider 与 useAuth,在挂载时恢复并向后端校验会话;配合 Expo Router 的 useSegments/useRouter 实现受保护路由重定向;封装 authFetch 自动附加 Bearer 头并处理 401;后端部分给出 FastAPI 校验 Google ID token 的示例,并说明需使用 Web 客户端 ID。
必要用法:需在模块级调用 WebBrowser.maybeCompleteAuthSession();app.json 的 scheme 需与 Google Cloud Console 的 redirect URI 一致;可用 AuthSession.makeRedirectUri() 兼容 Expo Go 与独立构建的不同重定向地址。
适用场景:Expo 应用接入第三方登录、需要安全存储令牌、按登录状态切换路由、排查认证重定向问题。
限制:资料未提供具体定价、支持平台范围、版本兼容性及 Apple 登录的完整实现细节,暂未提供。