Expo authSession未完成请求



我是应用程序开发的新手,在尝试设置谷歌身份验证时遇到了一个错误,但请求似乎还没有完成加载。

(错误消息为:[未处理的承诺拒绝:错误:在请求完成加载之前无法提示进行身份验证。](

我不确定如何解决这个问题,也许一些更有经验的开发人员会回答我的问题?

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({

我也通过了。

我修复了在处理程序挂钩的依赖项列表中添加"promptAsync"的问题

const [request, response, promptAsync] = Google.useAuthRequest(...)
const handlerClick = useCallback(() => {
promptAsync(...)
}, []) // THROWS ERROR

//FIX
const [request, response, promptAsync] = Google.useAuthRequest(...)
const handlerClick = useCallback(() => {
promptAsync(...)
}, [promptAsync])// IT WORKS

最新更新