【问题标题】:Request not being completed with Expo authSession请求未通过 Expo authSession 完成
【发布时间】: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


【解决方案1】:

我也通过了。

我修复了它在处理程序挂钩的依赖列表中添加“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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 2021-10-24
    • 2023-02-19
    相关资源
    最近更新 更多