react-native-nitro-google-signin

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

React Native Nitro Google Sign-In

React Native Nitro Google Sign-In

Agent skill (install first for coding agents)

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

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

Package install

包安装

bash
bun add react-native-nitro-google-signin react-native-nitro-modules
bundle exec pod install --project-directory="ios"
Requires RN ≥ 0.76. Not Expo Go — use
expo-dev-client
.
bash
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

Rules

规则

TopicRule
API
GoogleOneTapSignIn
from
react-native-nitro-google-signin
Configure first
GoogleOneTapSignIn.configure({ webClientId })
before sign-in
serverAuthCode
Requires
offlineAccess: true
in
configure()
— otherwise always
null
.
requestScopes()
still returns
accessToken
for on-device APIs without offline access
BackendVerify every
idToken
on server (sig,
aud
,
iss
,
exp
); validate JWT
hd
if using
hostedDomain
iOS offline grantSilent
signIn()
returns
serverAuthCode: null
— use
createAccount()
for initial code
revokeAccess
Android: by email/id. iOS: current session only (throws if id mismatch)
getTokens
After sign-in; throws
SIGN_IN_REQUIRED
if no session. iOS: call
clearCachedAccessToken
before retry after 401
getCurrentUser
Sync; returns user +
scopes
or
null
. Check scopes before
requestScopes
for existing users
Flow order
checkPlayServices
signIn
createAccount
presentExplicitSignIn
Android
autoDetect
Needs
google-services.json
+
com.google.gms.google-services
plugin
iOS
GoogleService-Info.plist
+
REVERSED_CLIENT_ID
URL scheme
ExpoPlugin
react-native-nitro-google-signin
;
expo prebuild
after native config
After native changesRebuild app — Metro alone is insufficient
主题规则
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()
revokeAccess
Android:通过邮箱/ID撤销。iOS:仅撤销当前会话(若ID不匹配会抛出错误)
getTokens
登录后调用;若无会话会抛出
SIGN_IN_REQUIRED
。iOS:401错误后重试前需调用
clearCachedAccessToken
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 scheme
Expo插件
react-native-nitro-google-signin
;原生配置完成后执行
expo prebuild
原生代码修改后重新构建应用 — 仅用Metro打包不够

Sign-in flow

登录流程

ts
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
}
ts
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
}

Platform quick pick

平台快速选择

  • Expo → plugin +
    googleServicesFile
    in
    app.config.js
    reference.md#expo
  • Bare Android → SHA-1 + optional Google Services plugin → reference.md#android
  • Bare iOS → plist + URL scheme → reference.md#ios
  • Expo → 插件 + 在
    app.config.js
    中配置
    googleServicesFile
    reference.md#expo
  • 原生Android → SHA-1 + 可选Google Services插件 → reference.md#android
  • 原生iOS → plist文件 + URL scheme → reference.md#ios

Troubleshooting

故障排除

SymptomLikely fix
DEVELOPER_ERROR
(Android)
Wrong SHA-1 or package on OAuth client
type: 'cancelled'
after picking account (Android release/Play)
Missing Play App Signing / release SHA-1 on Android OAuth client — troubleshooting
default_web_client_id was not found
Add
google-services.json
+ Gradle plugin
iOS redirect failsFix
REVERSED_CLIENT_ID
URL scheme
pod install
/ Expo prebuild — AppCheckCore / RecaptchaInterop (or conflict with Firebase App Check)
Expo: upgrade package +
prebuild --clean
(plugin adds modular headers, no AppCheckCore
< 11.3
pin). Bare: add AppCheckCore/GoogleUtilities/RecaptchaInterop with
:modular_headers => true
troubleshooting
Nitro not foundRebuild dev client /
bundle exec pod install --project-directory="ios"
Android button laid out but blankUpgrade package (in-process branding button) + rebuild native app
Sign-in OK in debug, fails in releaseConsumer ProGuard rules ship with library; avoid
-keep androidx.**
; test
assembleRelease
. Also check release/Play SHA-1 (see cancelled-after-account-pick above)
症状可能的解决方法
DEVELOPER_ERROR
(Android)
OAuth客户端的SHA-1或包名错误
选择账户后返回
type: 'cancelled'
(Android发布版/Play商店)
Android OAuth客户端缺少Play应用签名/发布版SHA-1 — 故障排查
提示
default_web_client_id was not found
添加
google-services.json
+ Gradle插件
iOS重定向失败修复
REVERSED_CLIENT_ID
URL scheme
pod install
/Expo prebuild失败 — 涉及AppCheckCore/RecaptchaInterop(或与Firebase App Check冲突)
Expo:升级包 + 执行
prebuild --clean
(插件会添加模块化头文件,不要固定AppCheckCore版本
< 11.3
)。原生项目:添加AppCheckCore/GoogleUtilities/RecaptchaInterop并设置
:modular_headers => true
故障排查
提示Nitro未找到重新构建开发客户端 / 执行
bundle exec pod install --project-directory="ios"
Android登录按钮已布局但显示空白升级包(按钮品牌功能正在开发中) + 重新构建原生应用
调试环境登录正常,发布版失败库已包含消费者ProGuard规则;避免使用
-keep androidx.**
;测试
assembleRelease
。同时检查发布版/Play的SHA-1(见上文“选择账户后取消”的内容)

More detail

更多细节