简体   繁体   中英

Does firebase auth store user data by default in my app storage?

I tried using firebase auth service today and it worked. But after a reload, I use another number, it still worked. It returns an object even if my data is turned off, and the phone number doesn't match my current local state. But it still navigates the user into the app. Also printing that I've exceeded my daily quota, but it still logs them in.

Decided to clear my app storage and start from begining, then an error shows up, saying the object doesn't exist.

heres the codes THE FIRST SCREEN FOR NEW USERS, I CALL REGISTER SCREEN

 import { React, useState, StyleSheet, View, useRef, } from '../../imports/all_RnComponents'; import { AppInput, InputsGroup, AppButton, FormTitle, Link, } from '../../imports/all_files'; import {PhoneInput} from '../../imports/all_packages'; import {colors, width, height, universalPadding} from '../../config/config'; const Register = ({navigation}) => { /// const [value, setValue] = useState(''); const [formattedValue, setFormattedValue] = useState(''); const [valid, setValid] = useState(false); const [showMessage, setShowMessage] = useState(false); const phoneInput = useRef(null); /// const handleSubmit = () => navigation.navigate('confirmation', {phoneNumber: formattedValue}); return ( <View style={styles.container}> <FormTitle title={'Enter Phone Number'} subheading="" /> <InputsGroup> <PhoneInput ref={phoneInput} defaultValue={value} defaultCode="NG" layout="first" onChangeText={text => { setValue(text); }} onChangeFormattedText={text => { setFormattedValue(text); }} withDarkTheme withShadow autoFocus /> </InputsGroup> <AppButton wideButton disabled={value.length > 10 ? false : true} title="Send Verification Code" // onPress={() => navigation.navigate('confirmation')} onPress={handleSubmit} /> </View> ); }; export default Register; const styles = StyleSheet.create({ container: { flex: 1, width: width, backgroundColor: colors.brandColor, alignContent: 'center', justifyContent: 'center', paddingHorizontal: universalPadding, }, });

 //the Confirmation screen after inputing phone number import { React, StyleSheet, View, useEffect, useState, } from '../../imports/all_RnComponents'; import { AppInput, InputsGroup, AppButton, FormTitle, Link, Lock, commonFunctions, } from '../../imports/all_files'; import {colors, width, height, universalPadding} from '../../config/config'; //firebase auth service import auth from '@react-native-firebase/auth'; const Confirmation = ({navigation, route, choiceOfAlert = 'Phone Number'}) => { //don't bother checking if theres a number or not, users wont get here if they dont add a number. const {phoneNumber} = route.params; //hold the state until firebase connects finishe... const [initializing, setInitializing] = useState(true); const [user, setUser] = useState(); // If null, no SMS has been sent const [confirm, setConfirm] = useState(null); const [code, setCode] = useState(''); const signInWithPhone = async () => { try { const confirmation = await auth().signInWithPhoneNumber(phoneNumber); setConfirm(confirmation); //if verified, navigation.navigate('mainNavigation') } catch (error) { commonFunctions.showToast('failed', error.message, 'error'); } }; function onAuthStateChangedCallBack(user) { console.log('auth is running'); if (user) { setUser(user); console.log( 'there is user, ', user, ' the state user, => ', phoneNumber, ); //to prevent going back to login screen navigation.navigate('welcome'); return navigation.reset({ index: 0, routes: [{name: 'welcome'}], }); ///////// } else console.log(user, ' doesnt match, => ', phoneNumber); } useEffect(() => { signInWithPhone(); }, []); useEffect(() => { const subscriber = auth().onAuthStateChanged(onAuthStateChangedCallBack); return subscriber; // unsubscribe on unmount }, []); ///called on manual click const verifyPhoneNumber = async () => { console.log(code, ' state code'); try { await confirm.confirm(code); } catch (error) { console.log('Invalid code.'); } }; return ( <View style={styles.container}> <View style={styles.padLock}> <Lock /> </View> <FormTitle title={''} subheading={`Enter the code sent to your ${choiceOfAlert}`} /> <InputsGroup> <AppInput keyboardType="number-pad" label="Enter Code" onChangeText={text => { console.log(text, ' your text'); setCode(text); }} /> </InputsGroup> <AppButton disabled={confirm !== null ? false : true} title="Verify" wideButton onPress={verifyPhoneNumber} /> <Link text={'re-send code'} onPress={() => signInWithPhone()} /> <Link text={'edit phone number'} onPress={() => navigation.navigate('register')} /> </View> ); }; export default Confirmation; const styles = StyleSheet.create({ container: { flex: 1, width: width, backgroundColor: colors.brandColor, alignContent: 'center', justifyContent: 'center', paddingHorizontal: universalPadding, }, padLock: { width: '100%', justifyContent: 'center', alignItems: 'center', }, });

the code looks a bit ugly but trust me, i don't wanna get into clean code without understanding everything going on here...

for a recap..

i cleared my storage in my local app not yet published, i then deleted every user in my auth db in firebase.. I used my real number and this time...i got what i wanted smoothly...i then cleared storage out to try another time again, it printed "TOO MANY REQUESTS, THIS PROJECT HAS EXCEEDED IT QUOTAS for this operation" i still see the previous number that registered successfully in my db..

as a side note... it will be of help if i can test this phone auth with fb without getting limits cuz its just in production and i can't wait everyday to try again..

thanks in advance

As OGB also said: Firebase automatically stores user credentials in local storage, and restores them from there when the app restarts. At that point it tried to re-validates those credentials with a call to the server, and it clears them when the server rejects them (for example of the account was disabled). If the SDK can't reach the server, it assumes that the user is still signed in, until it can check with the server.

It's hard to say more without seeing the API calls you do, and the exact results you get back from them.


Update after your edit:

it will be of help if i can test this phone auth with fb without getting limits

You might want to check the documentation on Test with fictional phone numbers .

step 1:

     **import auth from '@react-native-firebase/auth';**

step 2: (when click signout button)

    **auth().signOut();** //This is only for Firebase Authentication. If you 
                          //are save data in app session then also clear 
                          //that

Firebase automatically caches data for offline use on mobile. That would explain why clearing your cache loses the data.

However, I strongly suspect you are doing something very wrong. Per the details. I can't help you though without additional info like the specific implementation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM