onAuthStateChanged returns null when the verification mail is sent form ionic app where as in angular the same setup works

浪子不回头ぞ 提交于 2020-01-06 12:29:10

问题


I have an email verification page in angular and the sign up page in ionic app. When I create a user from angular, everything works well but when I sign up a user from ionic application onAuthStateChanged, it doesn't return any user. Stuck here for a long time guys help me out

To send the verification email I am using AngularFireAuth.auth.currentUser.sendEmailVerification() this signup process is done in the ionic app.

The action link which I specified in firebase is a route in angular site.To handle the verification I am using THE following snippet on ngOnInit life cycle hook.

AngularFireAuth.auth.onAuthStateChanged((user) => {
 if(user){
  console.log("user verified")
 } else {
  console.log("there are no user state changes");
 }
});

The user is always null when the verification link is sent from ionic where as I tried the same in angular it worked and user gets verified.I am using the same API credentials in both angular and ionic applications.Can anyone help me out to resolve this issue


回答1:


Hello dev's I found out the solution for this a long time back thought of posting it over here. Please refer Firebase user management!

import* as admin from 'firebase-admin';
import polyfill from 'babel-polyfill';
import serviceAccount from '../google-services.json'


admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'your firebase database URL'
});

    const user = () => {
    return new Promise((resolve, reject) => {
        admin.auth().getUserByEmail(req.body.email).then(data=> {
            if(data.emailVerified != true)
            {
                admin.auth().updateUser(data.uid, { emailVerified : true});
                console.log("verify", data);
                resolve(data);
            }
            reject();
            console.log("else result");
        });
    }); 
}

You can Trigger the firebaseAuthStateChanged manually by changing the email verification state in firebase using the firebase admin. All you have to do is get the user by uid or email and then update the emailVerified field to true.



来源:https://stackoverflow.com/questions/54250772/onauthstatechanged-returns-null-when-the-verification-mail-is-sent-form-ionic-ap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!