Skip to content

Commit

Permalink
define events on the usermanager to link user to store
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfgebhardt committed Apr 16, 2024
1 parent 7a4c9fd commit 2f79a3d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions frontend/src/services/AuthService.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand All @@ -33,6 +44,8 @@ export default class AuthService {
}

public signOut() {
const auth = useAuthStore()
auth.clear()
window.location.href = AUTH.AUTHORITY_SIGNOUT_URI
}

Expand Down

0 comments on commit 2f79a3d

Please sign in to comment.