Skip to content

Commit

Permalink
Add onAuthChecked
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanrevell committed Sep 8, 2021
1 parent 462bf3d commit 2d1ae32
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/vue-user-composition.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const globals = {
initialized : false,
user : null,
authenticated : false,
authChecked : false,
onAuth : new CallbackController(),
onUnauth : new CallbackController()
onUnauth : new CallbackController(),
onAuthChecked : new CallbackController()
};


Expand All @@ -35,18 +37,27 @@ function initialize(auth) {
*/
function updateUserAuth(firebaseAuth) {
if(firebaseAuth) {
globals.authenticated.value = true;
globals.user.value = {
email: firebaseAuth.email,
uid: firebaseAuth.uid
};
return globals.onAuth.run(globals.user.value);
globals.onAuth.run(globals.user.value);

} else {
globals.authenticated.value = false;
globals.user.value = null;
return globals.onUnauth.run(globals.user.value);
globals.onUnauth.run(globals.user.value);
}
globals.authChecked = true;
globals.onAuthChecked.run(globals.user.value);
}

/**
* @typedef {object} VueUserCompositionResult
* @property {object}
*/

/**
*
* @param {import("@types/firebase")} auth
Expand All @@ -57,6 +68,7 @@ export function VueUserComposition(auth) {
user : globals.user,
authenticated : globals.authenticated,
onAuth : (cb) => globals.onAuth.add(cb),
onUnauth : (cb) => globals.onUnauth.add(cb)
onUnauth : (cb) => globals.onUnauth.add(cb),
onAuthChecked : (cb) => globals.onAuthChecked.add(cb)
};
}

0 comments on commit 2d1ae32

Please sign in to comment.