![](/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.