如何解决如何在 react-native 和 supabase 中使用 Apple 和 Google 凭据登录 使用谷歌凭据有苹果证书
我一直在尝试使用以下库和 supabase 在裸 react-native 项目中通过谷歌和苹果实现登录。
它们在使用 firebase sdk 时与 here 所述的 firebase 配合得很好。 这个概念相当简单,苹果和谷歌的原生 sdk 签名在成功登录后返回用户凭据。以下是来自 https://rnfirebase.io/auth/social-auth
的示例使用谷歌凭据
import auth from '@react-native-firebase/auth';
import { GoogleSignin } from '@react-native-google-signin/google-signin';
async function onGoogleButtonPress() {
// Get the users ID token
const { idToken } = await GoogleSignin.signIn();
// Create a Google credential with the token
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
// Sign-in the user with the credential
return auth().signInWithCredential(googleCredential);
}
有苹果证书
import auth from '@react-native-firebase/auth';
import { appleAuth } from '@invertase/react-native-apple-authentication';
async function onAppleButtonPress() {
// Start the sign-in request
const appleAuthRequestResponse = await appleAuth.performRequest({
requestedOperation: appleAuth.Operation.LOGIN,requestedScopes: [appleAuth.Scope.EMAIL,appleAuth.Scope.FULL_NAME],});
// Ensure Apple returned a user identityToken
if (!appleAuthRequestResponse.identityToken) {
throw 'Apple Sign-In Failed - no identify token returned';
}
// Create a Firebase credential from the response
const { identityToken,nonce } = appleAuthRequestResponse;
const appleCredential = auth.AppleAuthProvider.credential(identityToken,nonce);
// Sign the user in with the credential
return auth().signInWithCredential(appleCredential);
}
我已经通过了 supabase 提供的身份验证 supabase-js auth 我能找到的与上述实现相关的最接近的事情是使用刷新令牌,如下所示 Sign in using a refresh token
// An example using Expo's `AuthSession`
const redirectUri = AuthSession.makeRedirectUri({ useProxy: false });
const provider = 'google';
AuthSession.startAsync({
authUrl: `https://MYSUPABASEAPP.supabase.co/auth/v1/authorize?provider=${provider}&redirect_to=${redirectUri}`,returnUrl: redirectUri,}).then(async (response: any) => {
if (!response) return;
const { user,session,error } = await supabase.auth.signIn({
refreshToken: response.params?.refresh_token,});
});
以上示例使用 refreshToken 参数 auth.sign() 为已注册的用户创建会话。
如果我错了,请纠正我。根据身份验证文档,没有任何方法允许使用身份验证凭据创建用户。这是因为 gotrue 社会身份验证是如何实现的。我现在能想到的唯一解决方案是将整个身份验证逻辑移到后端并在 Web 上进行处理。这一点都不优雅,因为它必须涉及丑陋的深层链接或 webview 实现才能使用 supabase 会话和访问令牌。
鉴于上述情况,有没有办法在 react-native 中使用原生社交 sdk 使用用户凭据在 supabase 中创建新用户帐户,而不必强制他们使用电子邮件链接、密码或网络?欢迎提出任何想法、答案或更正。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。