Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Firebase httpsCallable emulator thwrowing unhandled promise rejection in React Native

$
0
0

I have a Firebase function that searches for a user by uid:

export const findUserByUid = functions.https.onCall(async (data, context) => {    const foundUser = await admin.auth().getUser(data.uid);    if (foundUser) {        return {user: foundUser.email};    }    return {user: null};});

The functions are served by following command: npm run build && firebase emulators:start --only functions

In React Native I initialize Firebase this way:

import "firebase/firestore";import "firebase/functions";import firebase from "firebase";let firebaseConfig: Object = {   ...};const firebaseApp = firebase.initializeApp(firebaseConfig)const firebaseStore = firebaseApp.firestore();const firebaseAuth = firebaseApp.auth();const firebaseFunction = firebaseApp.functions();if (__DEV__) {    console.log("Initialize emulator for cloud functions");    firebaseFunction.useEmulator('localhost', 5001);    console.log(firebaseFunction)}export {firebaseStore, firebaseAuth, firebaseFunction};

Call of the firebase function:

const findUser = async (): Promise<void> => {        const findUserByUid = await firebaseFunction.httpsCallable('findUserByUid')({uid: "mock"});        const result = findUserByUid.data;        console.log(result)}

When I call findUser(), the follwing exception gets thrown:

[Unhandled promise rejection: Error: internal]- node_modules\@firebase\firestore\dist\rn\prebuilt.rn-31a90691.js:17759:5 in La#convertReference* http://packager.8e-sbz.exp.direct/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:244218:29 in _errorForResponse- node_modules\@firebase\functions\dist\index.esm.js:95:12 in codeForHTTPStatus- node_modules\@firebase\functions\dist\index.esm.js:461:8 in Service.prototype.useFunctionsEmulator

What am i doing wrong? Also there's nothing logged in the firebase emulator suite.

Update: Firebase function

export const findUserByUid = functions.https.onCall(async (data, context) => {    try {        const foundUser = await admin.auth().getUser(data.uid);        if (foundUser) {            return {user: foundUser.email};        }    } catch (error) {        return new https.HttpsError("not-found", error);    }    return {user: null};});

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>