Open elomapezoumon opened 4 years ago
Could you tell me what you've tried so far or share some code?
Hi guy, ok..
FIREBASE.JS import firebase from 'firebase'; import 'firebase/functions'; export const fns = firebase.functions(); import { API_KEY, AUTH_DOMAIN, DATABASE_URL, PROJECT_ID, STORAGE_BUCKET, MESSAGE_SENDER_ID, APP_ID, } from 'react-native-dotenv';
const config = { apiKey: API_KEY, authDomain: AUTH_DOMAIN, databaseURL: DATABASE_URL, projectId: PROJECT_ID, storageBucket: STORAGE_BUCKET, messagingSenderId: MESSAGE_SENDER_ID, appId: APP_ID, }; const Firebase = firebase.initializeApp(config); export default Firebase;
INDEX.JS const functions = require("firebase-functions"); const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
exports.registerUser = functions.https.onCall(async (data) => { const { email, password } = data;
if (email === null || password === null) { // We are throwing an error if either the email or the password is missing // We should also ideally validate these on the frontend so the request is never made if those fields are missing throw new functions.https.HttpsError("invalid-argument", "email and password are required fields"); }
try { // We create our user using the firebase admin sdk const userRecord = await admin.auth().createUser({ email, password });
// We set our user role and the x-hasura-user-id claims
// Remember, the x-hasura-user-id is what Hasura uses to check
// if the user is allow to read/update a record
const customClaims = {
"https://hasura.io/jwt/claims": {
"x-hasura-default-role": "user",
"x-hasura-allowed-roles": ["user"],
"x-hasura-user-id": userRecord.uid
}
};
await admin.auth().setCustomUserClaims(userRecord.uid, customClaims);
return userRecord.toJSON();
} catch (e) { let errorCode = "unknown"; let msg = "Something went wrong, please try again later"; if (e.code === "auth/email-already-exists") { // If a user that already has an account tries to sign up // we want to show them a proper error and instruct them to log in errorCode = "already-exists"; msg = e.message; } throw new functions.https.HttpsError(errorCode, msg, JSON.stringify(e) ); } });
Hi Guys !
I get this error after including and deploy firebase functions : *Firebase: No Firebase App '[DEFAULT] has been created - call Firebase App.initializeApp() (app/no-app) Help Me please !