mcpField
R
react-native-nitro-google-signin

react-native-nitro-google-signin

github.com/react-native-nitro-google-sign-in开发57233 次安装今天更新
代码仓库

关于 react-native-nitro-google-signin

面向编码 Agent 的技能,指导在 React Native 应用中安装和配置 react-native-nitro-google-signin,实现 Google 登录。内容涵盖平台设置、登录流程、令牌处理与故障排查。

主要功能

  1. 01Expo 与裸 React Native 设置指南
  2. 02Google One Tap 登录流程
  3. 03令牌与权限范围处理说明
  4. 04平台配置与故障排查

适用场景

  1. 01为 React Native 应用添加 Google 登录
  2. 02在 Expo 或裸项目中配置 Google 登录
  3. 03排查平台特定的登录故障

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/react-native-nitro-google-sign-in/google-signin --skill react-native-nitro-google-signin

安装后在 Claude Code 中输入/react-native-nitro-google-signin确认已加载。

附带文件examples.mdreference.md

详细介绍

React Native Nitro Google Sign-In

Agent 技能(编码 Agent 请先安装)

npx skills add react-native-nitro-google-sign-in/google-signin -g -y

文档:https://react-native-nitro-google-sign-in.github.io/docs/agents/skill

安装软件包

bun add react-native-nitro-google-signin react-native-nitro-modules
bundle exec pod install --project-directory="ios"

需要 RN ≥ 0.76。不支持 Expo Go——请使用 expo-dev-client。

规则

主题规则
API使用 react-native-nitro-google-signin 中的 GoogleOneTapSignIn
先配置在登录前调用 GoogleOneTapSignIn.configure({ webClientId })
serverAuthCode需要在 configure() 中设置 offlineAccess: true,否则始终为 null。没有离线访问权限时,requestScopes() 仍会为设备端 API 返回 accessToken
后端在服务器上验证每个 idToken(签名、aud、iss、exp);如果使用 hostedDomain,请验证 JWT 的 hd
iOS 离线授权静默调用 signIn() 会返回 serverAuthCode: null——请使用 createAccount() 获取初始代码
revokeAccessAndroid:按邮箱/ID 撤销。iOS:仅限当前会话(ID 不匹配时会抛出错误)
getTokens登录后调用;没有会话时会抛出 SIGN_IN_REQUIRED。iOS:401 后重试前调用 clearCachedAccessToken。Android:在已授予权限的情况下,可在后台任务中运行(无需 Activity)
getCurrentUser同步调用;返回用户及其 scopes,或 null。对于现有用户,在调用 requestScopes 前检查权限范围
流程顺序checkPlayServices → signIn → createAccount → presentExplicitSignIn
Android autoDetect需要 google-services.json 和 com.google.gms.google-services 插件
iOS需要 GoogleService-Info.plist 和 REVERSED_CLIENT_ID URL 方案
Expo插件 react-native-nitro-google-signin;完成原生配置后运行 expo prebuild
原生代码变更后重新构建应用——仅运行 Metro 不够

登录流程

import {
  GoogleOneTapSignIn,
  isNoSavedCredentialFoundResponse,
  isSuccessResponse,
} from 'react-native-nitro-google-signin'

GoogleOneTapSignIn.configure({ webClientId: 'autoDetect' })

await GoogleOneTapSignIn.checkPlayServices()
let response = await GoogleOneTapSignIn.signIn()
if (isNoSavedCredentialFoundResponse(response)) {
  response = await GoogleOneTapSignIn.createAccount()
}
if (isNoSavedCredentialFoundResponse(response)) {
  response = await GoogleOneTapSignIn.presentExplicitSignIn()
}
if (isSuccessResponse(response)) {
  const { user, idToken } = response.data
}

平台快速选择

故障排除

症状可能的解决方法
DEVELOPER_ERROR(Android)OAuth 客户端中的 SHA-1 或软件包名错误
选择账号后出现 type: 'cancelled'(Android 发布版/Play)Android OAuth 客户端缺少 Play App Signing / 发布版 SHA-1 — 故障排除
未找到 default_web_client_id添加 google-services.json + Gradle 插件
iOS 重定向失败修正 REVERSED_CLIENT_ID URL scheme。在使用场景生命周期的应用中,确保 GIDSignIn.sharedInstance.handle(url) 位于 SceneDelegate.swift 中
启动时崩溃,出现 UIApplicationEvaluateRuntimeIssueForNoSceneLifecycleAdoption(iOS 27)Expo SDK 57:添加 expo-build-properties,并设置 ios: { enableSceneSupport: true }(SDK 58+ 中默认为启用)。Bare RN:添加 UIApplicationSceneManifest + SceneDelegate.swift — 故障排除
pod install / Expo prebuild — AppCheckCore / RecaptchaInterop(或与 Firebase App Check 冲突)Expo:升级软件包 + prebuild --clean(插件会添加模块化标头,不会固定 AppCheckCore < 11.3)。Bare:添加 AppCheckCore/GoogleUtilities/RecaptchaInterop,并设置 :modular_headers => true — 故障排除
未找到 Nitro重建开发客户端 / bundle exec pod install --project-directory="ios"
Android 按钮已布局但显示空白升级软件包(进程内品牌按钮)+ 重建原生应用
登录在调试版中正常,在发布版中失败库自带使用者 ProGuard 规则;避免使用 -keep androidx.**;测试 assembleRelease。同时检查发布版/Play SHA-1(见上方“选择账号后出现 cancelled”)

更多详情

评论

支持 Markdown