From 2f79a3d040b6ff3ef0841a6bed2056157f1e06d1 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 16 Apr 2024 12:38:49 +0200 Subject: [PATCH] define events on the usermanager to link user to store --- frontend/src/services/AuthService.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/frontend/src/services/AuthService.ts b/frontend/src/services/AuthService.ts index aa905c5930..f12000d23b 100644 --- a/frontend/src/services/AuthService.ts +++ b/frontend/src/services/AuthService.ts @@ -1,6 +1,7 @@ import { UserManager } from 'oidc-client-ts' import { AUTH } from '#src/env' +import { useAuthStore } from '#stores/authStore.js' export default class AuthService { userManager: UserManager @@ -14,6 +15,16 @@ export default class AuthService { scope: AUTH.SCOPE, loadUserInfo: true, }) + + this.userManager.events.addUserLoaded(async () => { + const auth = useAuthStore() + auth.save(await this.userManager.getUser()) + }) + + this.userManager.events.addUserUnloaded(() => { + const auth = useAuthStore() + auth.clear() + }) } public signUp() { @@ -33,6 +44,8 @@ export default class AuthService { } public signOut() { + const auth = useAuthStore() + auth.clear() window.location.href = AUTH.AUTHORITY_SIGNOUT_URI }