Kha*_*han 3 google-authentication firebase react-native firebase-authentication expo
我是个新手,正在尝试在 Expo RN 应用程序中设置 Firebase Google 身份验证,
世博文档代码片段如下:
https://docs.expo.dev/guides/authentication/#google
import * as React from 'react';
import * as WebBrowser from 'expo-web-browser';
import { ResponseType } from 'expo-auth-session';
import * as Google from 'expo-auth-session/providers/google';
import { initializeApp } from 'firebase/app';
import { getAuth, GoogleAuthProvider, signInWithCredential } from 'firebase/auth';
import { Button } from 'react-native';
// Initialize Firebase
initializeApp({
/* Config */
});
WebBrowser.maybeCompleteAuthSession();
export default function App() {
const [request, response, promptAsync] = Google.useIdTokenAuthRequest(
{
clientId: 'Your-Web-Client-ID.apps.googleusercontent.com',
},
);
React.useEffect(() => {
if (response?.type === 'success') {
const { id_token } = response.params;
const auth = getAuth();
const provider = new GoogleAuthProvider();
const credential = provider.credential(id_token);
signInWithCredential(auth, credential);
}
}, [response]);
return (
<Button
disabled={!request}
title="Login"
onPress={() => {
promptAsync();
}}
/>
);
}
Run Code Online (Sandbox Code Playgroud)
我收到类似这样的错误:
TypeError: provider.credential is not a function. (In 'provider.credential(_id_token)', 'provider.credential' is undefined)
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?
提前致谢
替换以下代码:
const provider = new GoogleAuthProvider();
const credential = provider.credential(id_token);
Run Code Online (Sandbox Code Playgroud)
和:
const credential = GoogleAuthProvider.credential(idToken);
Run Code Online (Sandbox Code Playgroud)
我认为世博会文档需要更新以反映这一点。
归档时间: |
|
查看次数: |
529 次 |
最近记录: |