I am developing an application that allows access for students, staff, and non-teaching staff.
Here is how my form data is structured:
formData: {
name: "",
email: "",
password: "",
select: null
},
options: ["Student", "Staff", "Non-Teaching Staff"],
When it comes to registering users in Vuex store, I use the following method:
registerUsers({}, payload) {
firebaseAuth.createUserWithEmailAndPassword(payload.email, payload.password)
.then(res => {
const userId = firebaseAuth.currentUser.uid;
console.log(res)
Notify.create({
message: 'Registration Successful!',
color: 'primary',
classes: 'quick'
})
//set user role
firebaseDb.ref(`users/'${userId}`).set({
name: payload.name,
email: payload.email,
select: payload.select
});
})
.catch(err => {
console.log(err)
Notify.create({
message: `${err.message}`,
classes: 'quick',
color: 'negative'
})
})
For logging in users, I have implemented the following method:
loginUsers({}, payload) {
firebaseAuth.signInWithEmailAndPassword(payload.email, payload.password)
.then(res => {
console.log(res);
Notify.create({
message: 'Success!',
classes: 'quick',
color: 'positive'
})
})
.catch(err => {
console.log();
Notify.create({
message: `${err.message}`,
classes: 'quick',
color: 'negative'
})
})
},
The problem arises with this piece of code:
handleAuthStateChange() {
firebaseAuth.onAuthStateChanged(user => {
if (user) {
//set user role
const userId = firebaseAuth.currentUser.uid;
console.log(userId)
firebaseDb.ref(`users/${userId}`).once('value', snapshot => {
console.log(snapshot.val())
})
}
})
},
The `snapshot.val()` is returning null in the console output.
Please help me identify what I might be doing wrong here.