【发布时间】:2022-12-11 02:34:46
【问题描述】:
我是应用程序开发的新手,在尝试设置 Google 身份验证时遇到错误,但请求似乎尚未完成加载。
(错误信息是:[未处理的承诺拒绝:错误:在请求完成加载之前无法提示进行身份验证。])
我不确定如何解决这个问题,也许一些更有经验的开发人员会回答我的问题?
import React, { useState, useEffect } from 'react';
import { View, Text, Button, StyleSheet, TextInput } from 'react-native';
import { useAuthRequest } from 'expo-auth-session';
import * as WebBrowser from 'expo-web-browser';
WebBrowser.maybeCompleteAuthSession();
const App = () => {
const [accessToken, setAccessToken] = useState();
const [request, response, promptAsync] = useAuthRequest({
iosClientId: "id",
expoClientId: "id",
//androidClientId: "",
});
useEffect(() => {
if (response?.type === "success") {
setAccessToken(response.authentication.accessToken);
}
}, [response]);
return (
<View>
<Button styles={styles.button} title="Sign-in with Google" /* google login button */
onPress={() => { promptAsync({useProxy: false, showInRecents: true}) }}/>
</View>
);
}
编辑:对于那些感兴趣的人,我确实找到了这个错误的修复方法,这是一个奇怪的问题,但我只改变了第三行和第十行。
// third
import * as Google from 'expo-auth-session/providers/google';
// tenth
const [request, response, promptAsync] = Google.useAuthRequest({
【问题讨论】:
-
检查
import { useAuthRequest } from 'expo-auth-session/providers/google';是否有效
标签: javascript react-native authentication