![](/img/trans.png)
[英]React Native Firebase apple auth Error: [auth/invalid-credential] The supplied auth credential is malformed or has expired
[英]React Native Firebase Phone Auth - auth/session-expired error. (Android)
这是我来自 rnfirebase.io 的代码。
按下登录按钮后,我收到了 SMS 代码。 但是在输入验证码后,firebase 给我返回了这个 [auth/session-expired] 错误。
[错误:[auth/session-expired] 短信代码已过期。 请重新发送验证码重试。]
setConfirm(confirmation) 也不起作用。 它再次返回 null。
我怎么解决这个问题? 谢谢!
import React, { useState } from "react";
import { View, Text, StyleSheet, Button, TextInput } from "react-native";
import auth from "@react-native-firebase/auth";
import colors from "../../config/colors";
// create a component
const UyeOlScreen = () => {
// If null, no SMS has been sent
const [confirm, setConfirm] = useState(null);
const [code, setCode] = useState("");
// Handle the button press
async function signInWithPhoneNumber(phoneNumber) {
const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
setConfirm(confirmation);
}
async function confirmCode() {
try {
await confirm.confirm(code);
} catch (error) {
console.log(error);
}
}
if (!confirm) {
return (
<Button
title="Phone Number Sign In"
onPress={() => signInWithPhoneNumber(`+123456789`)}
/>
);
}
return (
<>
<TextInput value={code} onChangeText={(text) => setCode(text)} />
<Button title="Confirm Code" onPress={() => confirmCode()} />
</>
);
};
//make this component available to the app
export default UyeOlScreen; ```
这帮助我解决了这个问题: How to use Firebase's 'verifyPhoneNumber()' to Confirm phone # Ownership without using # to sign-in?
当然,我必须进行一些调整才能使其适合我。 具体来说,我拿出了代码:
firebase
.firestore()
.collection('users')
.where('phoneNumber', '==', this.state.phoneNumber)
.get()
.then((querySnapshot) => {
if (!querySnapshot.empty) {
// User found with this phone number.
throw new Error('already-exists');
}
我认为这是处理可以与我不使用的 firebase 一起使用的存储。
我还拿出来:
let fbWorkerApp = firebase.apps.find(app => app.name === 'auth-worker')
|| firebase.initializeApp(firebase.app().options, 'auth-worker');
fbWorkerAuth = fbWorkerApp.auth();
fbWorkerAuth.setPersistence(firebase.auth.Auth.Persistence.NONE); // disables caching of account credentials
并且只是使用“auth()”代替 fbWorkerAuth,因为我已经在做:
import auth from '@react-native-firebase/auth';
在其中一个具有“错误”的 catch 块中还有一个小错误,它应该是“错误”。
否则它为我解决了这个问题。 太糟糕了,所有与此相关的文档都将我们指向一个不起作用的示例!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.