feat(frontend): Added functionality to the frontend to log in.
This commit is contained in:
parent
4a1edbb6ff
commit
a28ec22f29
20 changed files with 395 additions and 33 deletions
40
frontend/src/store/auth-store.ts
Normal file
40
frontend/src/store/auth-store.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import {computed, reactive} from "vue";
|
||||
import authService, {type Role} from "@/services/auth-service.ts";
|
||||
import type {User} from "oidc-client-ts";
|
||||
|
||||
type AuthState = {
|
||||
user: User | null,
|
||||
accessToken: string | null,
|
||||
activeRole: Role | null
|
||||
};
|
||||
|
||||
export const authState = reactive<AuthState>({
|
||||
user: null,
|
||||
accessToken: null,
|
||||
activeRole: authService.getActiveRole() || null
|
||||
});
|
||||
|
||||
export const isLoggedIn = computed(() => authState.user !== null);
|
||||
|
||||
export async function loadUser(): Promise<void> {
|
||||
const user = await authService.getUser();
|
||||
authState.user = user;
|
||||
authState.accessToken = user?.access_token || null;
|
||||
authState.activeRole = authService.getActiveRole() || null;
|
||||
}
|
||||
|
||||
export async function handleLoginCallback(): Promise<void> {
|
||||
console.log("Hallooo");
|
||||
authState.user = await authService.handleRedirectCallback() || null;
|
||||
}
|
||||
|
||||
export async function loginAs(role: Role): Promise<void> {
|
||||
await authService.loginAs(role);
|
||||
}
|
||||
|
||||
export async function logout(): Promise<void> {
|
||||
await authService.logout();
|
||||
authState.user = null;
|
||||
authState.accessToken = null;
|
||||
authState.activeRole = null;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue