Sunday, 19 April 2020

Im having difficulty posting user login credentials from Firebase to Node/DB

I have a RN app in which I am for simplicity sake trying to post the credentials of the user's email to MySQL database when those credentials are taken in by Firebase on first signup.I realize I need to understand GET syntax better. Here's my current setup from frontend to back..maybe someone can point me in the right direction? I'm honestly just confused on how to pass data from my 'registerUser' function and have Node take that data and insert it to my DB.FRONTENDregisterUser = (data) => { return axios({ method: 'post', url: `http://localhost:3000/api/db/:user`, data: { email: data.email, }, headers: { 'Content-Type': 'application/json' }}) .then(function (response) { //handle success return { type: "REGISTER_USER", payload: response.data, } }) .catch(function (err) { //handle error return { type: "REGISTER_USER_FAILED", payload: null } }); } handleLogin = () => { const { email, password } = this.state; firebase .auth() .signInWithEmailAndPassword(email, password) .catch(error => this.setState({ errorMessage: error.message })); }; componentDidMount(){ firebase.auth().onAuthStateChanged((user) => { const data = { email: 'email@emailman.com' } if (user != null) { registerUser(data).then((response) => { console.log(response) }) } }) } Then trying to receive 'data' from the Frontend POST request in Node....router.post('/:user', async (req, res, next) => { console.log('hitting the router.post') try { let results = await db.insert(req.params.user); res.json(results); } catch(e) { console.log(e); res.sendStatus(500); } }) Posting that info to my Database....db.insert = () => { return new Promise(( resolve, reject) => { pool.query(`INSERT INTO users(id, email) VALUES('273', 'fe.com')`, (err, results) => { if(err) { return reject(err); } return resolve(results[0]); }); }); } I know I need to replace whats in parenthesis for VALUES with my data, I just am unsure of how to get it to that point.Any insight greatly appreciated...i've been stuck on this for a few days.

Submitted April 19, 2020 at 08:42PM by gratefulmarmot

No comments:

Post a Comment