【问题标题】:How do I integrate AWS Amplify with Cognito into React-Native App?如何将 AWS Amplify 与 Cognito 集成到 React-Native 应用程序中?
【发布时间】:2021-03-01 10:10:42
【问题描述】:

我正在尝试将 AWS Amplify 与 Cognito 集成到现有的 React-Native 应用程序中。

这是我的 aws-exports.js 文件的内容。

const config = {
        identityPoolId: 'xxxxxxxx',
        region: 'xxxxx',
        userPoolId: 'xxxxx',
        userPoolWebClientId: 'xxxxxxx'
  }

export default config;

我在我的 index.js 文件中使用以下内容配置放大:

import Amplify from '@aws-amplify/core';
import awsConfig from './src/aws-exports'

Amplify.configure(awsConfig);

这是我尝试使用 Auth 方法注册用户等的地方:

import { Auth } from 'aws-amplify'

class AuthenticationService {
  confirmationResult: any
  phoneNumber: any

  signInWithPhoneNumber() {
    return new Promise((resolve, reject) => {
       const strippedPhone = phone.replace(/\D/g, '')
       const formattedPhone = `+1${strippedPhone}`

     
        Auth.signUp({
        username: 'jello',
        password: 'jello',
        attributes: {
          phone_number: formattedPhone
        }
      })
        .then((confirmationResult:any) => {
          this.confirmationResult = confirmationResult
          resolve(null)
        })
        .catch((error: any) => {
          reject(error)
        })
    })
  }

我在这里没有任何错误,但是我不断收到以下信息:

Unhandled JS Exception: Can't find variable: self

我已经搜索了一段时间,我偶然发现了"whatwg-fetch: 2.0.4" 但这并没有解决我的问题。

【问题讨论】:

    标签: reactjs amazon-web-services react-native amazon-cognito aws-amplify


    【解决方案1】:

    我设法在这里找到了答案,虽然很奇怪。我能够通过在我的 iOS 模拟器上启用远程调试来解决这个问题。不确定这两者是如何相关的,但这解决了问题。

    【讨论】:

      猜你喜欢
      • 2021-07-31
      • 2019-11-06
      • 2021-05-05
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 2018-12-19
      • 1970-01-01
      相关资源
      最近更新 更多