Reputation: 81
As per google docs, I've tried the below method to retrieve the current user details, but i'm getting null response from firebase v9.
Below is my code
ngOnInit(): void {
const app = initializeApp(environment.firebaseConfig);
const db = getDatabase(app);
const dbRef = ref(getDatabase(app));
const auth = getAuth();
onAuthStateChanged(auth, (user) => {
if (user) {
console.log(user);
const uid = user.uid;
console.log(uid);
}
});
onAuthStateChanged(auth, (user) => {
if (user) {
console.log(user);
const uid = user.uid;
console.log(uid);
}
});
}
I'm using ngx-auth-firebaseui
for authentication for login in my angular app.
Its not happening after login, When I directly visits the profile page, I'm getting null for currentuser,
Upvotes: 0
Views: 100
Reputation: 81
I found the solutions, this might help others
I've imported AuthProcessService
from ngx-auth-firebaseui
this.auth.user$.subscribe(res => {
if(res) {
console.log(res);
}
});
Now I can get the current logged in user
Upvotes: 1