0
votes

I have been learning how to go about firebase cloud functions and have slowly understood how the HTTPS requests work, however I'm stuck on retrieving data for the users email.

I want to check if the specific email that they enter in the app is already taken in my firebase project, I was going to do it on the client side but learnt that its more secure if I do it through cloud functions.

import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
import { response } from 'express';
admin.initializeApp()

export const getEmail = functions.https.onRequest((request, response) => {
    admin.auth().getUserByEmail(email)
    .then(snapshot => {
        const data = snapshot.data()
        response.send(data)
    })
    .catch(error => {
        //Handle error
        console.log(error)
        response.status(500).send(error)
    })
})

I keep on receiving an error that the data object does not exist on type 'userRecord'.

Error message (update): Property 'data' does not exist on type 'UserRecord'

1
Could you update the post with the error message? - jmkmay
@jmkmay yep, done - user9722951

1 Answers

2
votes

So admin.auth().getUserByEmail returns a Promise containing non-null UserRecord.

UserRecord doesn't appear to have a method data(). If you want to get the JSON representation of this UserRecord, use:

const data = snapshot.toJSON()

If you only need to access the email, use:

const data = snapshot.email