首页 > 解决方案 > 未找到 AWS 放大 react-native IdentityPool

问题描述

我正在尝试使用 AWS amplify 实现基本身份验证,当前代码没有给我红屏或警告。使用 console.log 的唯一一行显示了这一点 IdentityPool 'eu-west-1:fbbc514e-e3eb-4176-855c-d0fae5a0eca4' not found. at node_modules/@aws-sdk/client-cognito-identity/dist/cjs/protocols/Aws_json1_1.js:803:40 in deserializeAws_json1_1GetIdCommandError

import React, { useState, useEffect } from 'react'

import { StyleSheet, Text, View, Button } from 'react-native'
import Amplify, { Auth, Hub } from 'aws-amplify'
import awsconfig from './src/aws-exports'
Amplify.configure(awsconfig)
export default function App () {
  const [user, setUser] = useState('')
  const [isLoggedIn, setIsLoggedIn] = useState(false)

  useEffect(() => {
    Hub.listen('auth', ({ payload: { event, data } }) => {
      console.log(data)
      switch (event) {
        case 'signIn':
          setUser(data)
          setIsLoggedIn(true)
          console.log('User logged in: ', data)
          break
        case 'signOut':
          setUser('')
          setIsLoggedIn(false)
          console.log('User logged out: ', data)
          break
        case 'customOAuthState':
          setUser(data)
      }
    })
  }, []) //call Hub listen only on component mount & unmount

  return (
    <React.Fragment>
      {isLoggedIn ? (
        <View style={styles.container}>
          <Text>User logged in as {user.username}</Text>
        </View>
      ) : (
        <View style={styles.container}>
          <Button
            title='FacebookSignIn'
            onPress={() => {
              Auth.federatedSignIn({ provider: 'Facebook' })
            }}
          />
        </View>
      )}
    </React.Fragment>
  )
}

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

请指教

标签: react-nativeaws-amplify

解决方案


推荐阅读