0

I am developing a react native app with firebase backend, and I want to store user data when a user signs up. I have written the following code to store user data.

export const signUp = async function signUp(data) {
    try {
        const response = await Firebase.auth().createUserWithEmailAndPassword(data.email,data.password);
        if(response.user.uid) {
            const user = {
                email: data.email,
                name: data.name,
            }
            await db.collection('users').doc(response.user.uid).set(user)
        }
    } 
    catch (error) {
        alert(error)
    }
}

function call

state = {
    name: '',
    email: '',
    password: ''
  }

  handleChange = (name, value) => {
    this.setState({ [name]: value });
    console.log(this.state)
  }

handleSubmit = () => {
    signUp(this.state);
  }

The user is created successfully by firebase auth but the user data is not being inserted to the firestore database. What can I do to insert the data into the database?

EDIT: I am not getting any errors, but I get the following warnings

Promise Rejection Handled (id: 5)
This means you can ignore any previous messages of the form "Possible Unhandled Promise Rejection (id: 5):"
- node_modules\react-native\Libraries\YellowBox\YellowBox.js:71:8 in console.warn
- node_modules\expo\build\environment\muteWarnings.fx.js:18:23 in warn
- node_modules\react-native\Libraries\Promise.js:44:19 in require.enable$argument_0.onHandled  
- node_modules\promise\setimmediate\rejection-tracking.js:87:26 in onHandled
- node_modules\promise\setimmediate\rejection-tracking.js:33:18 in Promise._37
- node_modules\promise\setimmediate\core.js:93:16 in handle
- node_modules\promise\setimmediate\core.js:77:9 in Promise.prototype.then
* http://192.168.1.3:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:194624:27 in Xr
* http://192.168.1.3:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:194600:19 in qr
- node_modules\@firebase\firestore\dist\index.cjs.js:7482:12 in e.__awaiter$argument_3
* http://192.168.1.3:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:190811:59 in m
- node_modules\@firebase\auth\dist\auth.js:304:58 in k.set
* http://192.168.1.3:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:173029:11 in <unknown>
- node_modules\@firebase\util\dist\index.cjs.js:1462:8 in errorPrefix
- node_modules\@firebase\util\dist\index.cjs.js:1571:23 in stringToByteArray$1
- node_modules\@firebase\util\dist\index.cjs.js:1560:12 in stringToByteArray$1
- node_modules\@firebase\util\dist\index.cjs.js:1550:13 in stringToByteArray$1
- node_modules\@firebase\util\dist\index.cjs.js:1270:21 in ObserverProxy.prototype.subscribe   
- node_modules\promise\setimmediate\core.js:37:14 in tryCallOne
- node_modules\promise\setimmediate\core.js:123:25 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:146:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:194:17 in _callImmediatesPass    
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:458:30 in callImmediates
* [native code]:null in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:407:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:143:6 in __guard$argument_0- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:142:17 in __guard$argument_0
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue
[Unhandled promise rejection: ReferenceError: Can't find variable: atob]
- node_modules\@firebase\firestore\dist\index.cjs.js:9614:16 in t.prototype.wr
- node_modules\@firebase\storage\dist\index.cjs.js:630:12 in NetworkXhrIo.prototype.send       
- node_modules\@firebase\firestore\dist\index.cjs.js:1444:0 in <global>
* http://192.168.1.3:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:194625:28 in <unknown>
- node_modules\promise\setimmediate\core.js:37:14 in tryCallOne
- node_modules\promise\setimmediate\core.js:123:25 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:146:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:194:17 in _callImmediatesPass    
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:458:30 in callImmediates
* [native code]:null in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:407:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:143:6 in __guard$argument_0- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:142:17 in __guard$argument_0
* [native code]:null in flushedQueue
* [native code]:null in callFunctionReturnFlushedQueue
JayaniH
  • 293
  • 1
  • 2
  • 9

1 Answers1

0

I found a solution to the problem in another thread

I installed the base-64 package and imported it globally in App.js.

import {decode, encode} from 'base-64'

if (!global.btoa) {  global.btoa = encode }

if (!global.atob) { global.atob = decode }
JayaniH
  • 293
  • 1
  • 2
  • 9