oauth2.0 在使用暴露-身份验证-会话时响应本机问题

gr8qqesn  于 2023-03-07  发布在  其他
关注(0)|答案(1)|浏览(167)

当我在我的智能手机上构建应用程序时,我得到这个错误。我正在使用Expo with android divice。如果我去掉这个部分,应用程序工作正常:
const [request, response, promptAsync] = Google.useAuthRequest({ androidClientId:'', iosClientId:'', expoClientId:'', //Here i have my ids. })
错误:属性"ExpoCrypto"的HostObject::get中出现异常:java. lang.非法参数异常:没有主构造函数js引擎,无法将js值转换为枚举:Hermes
这是我的代码看起来像:

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button } from 'react-native';
import * as Google from 'expo-auth-session/providers/google'
import * as WebBrowser from 'expo-web-browser'
import React from 'react'

WebBrowser.maybeCompleteAuthSession();

export default function App() {
 const [accessToken, setAccessToken] = React.useState()
 const [data, setData] = React.useState()

 const [request, response, promptAsync] = Google.useAuthRequest({
  androidClientId:'',
  iosClientId:'',
  expoClientId:'',   //Here i have my ids.
 })

 React.useEffect(()=>{
  if(response?.type === 'success'){
    setAccessToken(response.authentication?.accessToken)
  }
 },[response])

 function showUserInfo(){
  if(data){
    return (
    <View>
      <Text>Welcome {data.name} </Text>
    </View>
    )
  }
 }
 
 async function getUserData(){
  let userInfoResponse = await fetch("https://www.googleapis.com/userinfo/v2/me",{
    headers:{
      Authorization :`Bearer ${accessToken}`
    }
  });
 userInfoResponse.json().then(data => setData(data))
 }

  return (
    <View style={styles.container}>
      {showUserInfo()}
      <Button
      title={accessToken ? "Get user data" : "Login"}
      onPress = {accessToken ? getUserData : () => promptAsync({showInRecents:true})}
      />
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
wgmfuz8q

wgmfuz8q1#

expo-crypto是expo-auth-session的一个依赖项,我试着按照requireNativeModule.js的错误检查代码init,看看是否将其注解掉

相关问题