React Native :Android设备中的Firebase OTP问题

ars1skjm  于 2022-12-09  发布在  Android
关注(0)|答案(1)|浏览(142)

我已经实现了firebase OTP的功能,用于对我的应用程序的用户进行身份验证。当我创建构建时,OTP功能在IOS中工作正常,但在Android中不工作,在Android中OTP很快就会过期。以下是这种情况:

案例1

  • Android设备A
  • 设备A中安装的App,并注册到设备A(同一设备)的移动的号码,
  • 我获得了OTP,但当我输入时,它显示OTP无效,因为OTP已过期
    案例2
  • Android设备A和Android设备B
  • 设备A中安装的应用程序,并注册了设备B的移动的号码,
  • 我在设备B上得到了OTP,我在安装应用程序的设备A中输入了它,它工作正常。

下面是我的代码和配置

import React, { Fragment, Component } from 'react';
import {
  SafeAreaView,
  StyleSheet,
  ScrollView,
  View,
  Text,
  StatusBar,
  TextInput,
  Button,
  Animated,
} from 'react-native';
import auth from '@react-native-firebase/auth';
import { COLORS } from './App/Auth/Colors';
import { STRINGS } from './App/Resource/Strings';
import { Animation_Open, Animation_Close } from './App/Auth/Functions';

export default class Demo extends Component {

  constructor(props) {
    super(props);
    this.animatedValue = new Animated.Value(-500);

    this.state = {
      phone: '+91',
      code: '',
      confirm: null,
    };
  }

  componentDidMount() {
    console.log('componentDidMount Demo');
  }

  OnPressContinue = async () => {
    auth()
      .signInWithPhoneNumber(this.state.phone)
      .then(confirmResult => {
        console.log('confirmResult', confirmResult);
        this.setState({ confirm: confirmResult });
      })
      .catch(error => {
        console.log('My Error', error);
      });
  }
  OnPressCodeSent = async () => {
    try {
      var a = await this.state.confirm.confirm(this.state.code);
      console.log('a', a);
    } catch (error) {
      console.log('Invalid code.', error);
    }
  }
  render() {
    return (
      <SafeAreaView style={styles.container}>
        <StatusBar />
        <View>
          <View>
            <TextInput
              placeholder="Enter A Number"
              value={this.state.phone}
              onChangeText={(text) => this.setState({ phone: text })}
              keyboardType="numeric"
              style={{ padding: 10, borderBottomWidth: 1, width: '100%', color: 'black' }}
            />
            <View style={{ marginTop: 20 }}>
              <Button
                title="Continue"
                onPress={() => this.OnPressContinue()} />
            </View>
          </View>
          <View style={{ marginTop: 20 }}>
            <TextInput
              placeholder="Enter Code"
              value={this.state.code}
              onChangeText={(text) => this.setState({ code: text })}
              style={{ padding: 10, borderBottomWidth: 1, width: '100%', color: 'black' }}
            />
            <View style={{ marginTop: 20 }}>
              <Button
                title="Send"
                onPress={() => this.OnPressCodeSent()} />
            </View>
          </View>
        </View>
        {/* //! Toster */}

      </SafeAreaView>
    );
  }
}

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

cotxawn71#

问题已解决:如果OTP将在同一设备中接收,我们将自动添加并比较。

相关问题