javascriptfirebasefirebase-realtime-databasefirebase-authenticationgoogle-cloud-functions

Firebase functions.auth.user().onCreate no triggering


i am trying create user with custom claim. I am using Firebase Cloud Functions. The problem is, when i create (Sign Up) an user, the onCreate not trigger. I am following this tutorial of provided by google. https://firebase.google.com/docs/auth/admin/custom-claims I Deployed my functions and the region is us-central1

Cloud functions version :

 firebase-admin": "^8.9.0
 firebase-functions": "^3.3.0

I am using Vue JS as Front-end

My functions/Index.js

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();


exports.ProccessSignUp = functions.auth.user().onCreate(async (user) =>{
   console.log("Email"+user.email);

   if (user.email){

        const customClaims = {
            admin:true
        };

        return admin.auth().setCustomUserClaims(user.uid,customClaims)
            .then(() =>{
                const metadataRef = admin.database().ref('metadata/' +user.uid);
                return metadataRef.set({refeshTime:new Date().getTime()})
            }).catch(err =>{
                console.log(err.message)
            })
    }



});

My SignUpWithEmailAndPassword

userSignUp({dispatch},payload){
            firebase.auth().createUserWithEmailAndPassword(payload.email, payload.password)
                .then(user =>{
                        user.user.sendEmailVerification()
                            .then(() =>
                                alert('Your account has been created! Please, verify your account'),
                                dispatch('userSignOut'),
                            ).catch(err =>{
                                console.log(err.message)
                        })
                }).catch(err =>{
                     console.log(err.message)
            })
        },

oAuthStateChanged

router.beforeEach(async (to, from, next) => {
    const user = await new Promise((resolve) => {
        firebase.auth().onAuthStateChanged(async user => {
            await store.dispatch("autoSignIn", user);
            resolve(user)
        });
    });

    const requiresAuth = to.matched.some(record => record.meta.requiresAuth)



    if (requiresAuth) {
        if (!user){
            next(false)
        }else {
            if (user.emailVerified){

                next();
            }else {

                alert('Please verify your account')
                await store.dispatch("userSignOut", user);
            }
        }

    } else {

        next()

    }
});



Solution

  • As explained in the doc, with Cloud Functions you can "emit a log line from your function, use standard JavaScript logging calls such as console.log and console.error".

    Then the Cloud Functions logs are viewable either in the Firebase console, Stackdriver Logging UI, or via the firebase command-line tool.

    So you should be able to confirm that your Cloud Function runs correctly (or not) by looking at, for exemple, the Firebase console.