Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix post-logout Firekit initialisation #870

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ const navbarBlacklist = ref([

onBeforeMount(async () => {
await authStore.initFirekit();
authStore.setUser();

await authStore.initStateFromRedirect().then(async () => {
// @TODO: Refactor this callback as we should ideally use the useUserClaimsQuery and useUserDataQuery composables.
Expand Down
4 changes: 4 additions & 0 deletions src/composables/mutations/useSignOutMutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const useSignOutMutation = () => {
// Clear the query client to remove all cached data.
queryClient.clear();

// Re-initialize Firekit. This is necessary to ensure that Firekit is properly reset after
// sign-out in order to allow a new user to sign in.
await authStore.initFirekit();

// Redirect to sign-in page.
router.push({ path: APP_ROUTES.SIGN_IN });
},
Expand Down
23 changes: 14 additions & 9 deletions src/store/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const useAuthStore = () => {
routeToProfile: false,
ssoProvider: null,
showOptionalAssessments: false,
adminAuthStateListener: null,
appAuthStateListener: null,
};
},
getters: {
Expand Down Expand Up @@ -61,28 +63,32 @@ export const useAuthStore = () => {
//@TODO: Move to mutation since we cannot rotate query keys anymore.
await this.roarfirekit.completeAssessment(adminId, taskId);
},
setUser() {
onAuthStateChanged(this.roarfirekit?.admin.auth, async (user) => {
async initFirekit() {
try {
this.roarfirekit = await initNewFirekit();
this.setAuthStateListeners();
} catch (error) {
// @TODO: Improve error handling as this is a critical error.
console.error('Error initializing Firekit:', error);
}
},
setAuthStateListeners() {
this.adminAuthStateListener = onAuthStateChanged(this.roarfirekit?.admin.auth, async (user) => {
if (user) {
this.localFirekitInit = true;
this.firebaseUser.adminFirebaseUser = user;
} else {
this.firebaseUser.adminFirebaseUser = null;
}
});
onAuthStateChanged(this.roarfirekit?.app.auth, async (user) => {
this.appAuthStateListener = onAuthStateChanged(this.roarfirekit?.app.auth, async (user) => {
if (user) {
this.firebaseUser.appFirebaseUser = user;
} else {
this.firebaseUser.appFirebaseUser = null;
}
});
},
async initFirekit() {
this.roarfirekit = await initNewFirekit().then((firekit) => {
return firekit;
});
},
async getLegalDoc(docName) {
return await this.roarfirekit.getLegalDoc(docName);
},
Expand Down Expand Up @@ -182,7 +188,6 @@ export const useAuthStore = () => {
return this.roarfirekit.createLevanteUsersWithEmailPassword(userData);
},
},
// persist: true
persist: {
storage: sessionStorage,
debug: false,
Expand Down