javascript - Firebase Passwordless Auth 在点击链接时显示网站未找到页面

标签 javascript firebase react-native firebase-authentication react-native-firebase

我对 react-nativefirebase 非常陌生,我正在尝试设置 Passwordless Auth

我写的代码:

import React, {Component} from 'react';
import {View, TextInput, Button} from 'react-native';
import auth from '@react-native-firebase/auth';
import AsyncStorage from '@react-native-community/async-storage';

class App extends Component {
  constructor(props) {
    super(props);

    this.state = {
      email: '',
      emailSent: false,
    };
  }

  setEmail = async email => {
    try {
      await AsyncStorage.setItem('emailLink', `${email}`);
    } catch (e) {
      // save error
    }

    console.log('Email is set');
  };

  getEmail = async () => {
    try {
      var value = await AsyncStorage.getItem('emailLink');
    } catch (e) {
      // read error
    }

    console.log('Got email: ', value);
  };

  sendEmailLink() {
    var actionCodeSettings = {
      // The URL to redirect to for sign-in completion. This is also the deep
      // link for mobile redirects. The domain (www.example.com) for this URL
      // must be whitelisted in the Firebase Console.
      url: 'https://passless.page.link/85EH',
      iOS: {
        bundleId: 'org.reactjs.native.example.passless',
      },
      android: {
        packageName: 'com.passless_auth',
        installApp: true,
        minimumVersion: '12',
      },
      // This must be true.
      handleCodeInApp: true,
    };
    auth()
      .sendSignInLinkToEmail(`${this.state.email}`, actionCodeSettings)
      .then(() => console.log('email is sent'))
      .then(() => this.setEmail(`${this.state.email}`))
      .catch(err => console.log('error sending email', err));
  }

  render() {
    return (
      <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
        <TextInput
          placeholder="email"
          onChangeText={email => this.setState({email: email})}
        />
        <Button title="SignUp/LogIn" onPress={() => this.sendEmailLink()} />
      </View>
    );
  }
}

export default App;

我已成功收到电子邮件,但链接无效。

这是我得到的错误, enter image description here

电子邮件中的链接会在浏览器而不是应用程序中打开。我该如何解决这个问题??

我想我已经在控制台中正确设置了链接,但我不确定我的代码。

我如何进一步进步?? 非常感谢您的帮助。

P.S 我正在使用 react-native-firebase v6

最佳答案

当您将重定向 URL 从默认重定向 URL 更改为其他未在 GCP 项目中注册的重定向 URL 时,就会发生这种情况。

确保您在 GCP oAuth 同意的 firebase 项目凭据部分将重定向 URL 列入白名单。

https://console.cloud.google.com/apis/credentials/consent

确保已将您的重定向 URL 列入白名单。

希望对您有所帮助。如果您遇到问题,请告诉我。

关于javascript - Firebase Passwordless Auth 在点击链接时显示网站未找到页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59236578/

相关文章:

reactjs - 在 React-Native 中定义静态 PropTypes 时 '.isRequired' 的含义

javascript - 与 API 交互时, header 键变为小写 - React native

javascript - JS : Resolve a Formula for x

javascript - 如何强制 IE 重新加载脚本元素?

ios - firebase/swift 4 - 等到 firebase 完成配置

angularjs - 如何获取经过身份验证的用户信息并在所有 Controller 和服务中使用?

javascript - 将字符串编码为 QR 码生成器的小尺寸

JavaScript 不会返回对象,它只返回代码部分

javascript - 如何从 Heroku 上的 Node.js 应用程序中的子文件夹重定向到静态 javascript 应用程序?

reactjs - 在 React Native 中本地化为 LTR 时使用 RTL 方向