first commit
This commit is contained in:
41
apps/frontend/src/stores/auth.ts
Normal file
41
apps/frontend/src/stores/auth.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
type AuthStatus = 'authenticated' | 'guest';
|
||||
|
||||
interface UserProfile {
|
||||
id: string;
|
||||
email: string;
|
||||
displayName: string;
|
||||
avatarUrl?: string;
|
||||
preferredCurrency: string;
|
||||
}
|
||||
|
||||
interface AuthState {
|
||||
status: AuthStatus;
|
||||
accessToken?: string;
|
||||
refreshToken?: string;
|
||||
profile?: UserProfile;
|
||||
}
|
||||
|
||||
export const useAuthStore = defineStore('auth', {
|
||||
state: (): AuthState => ({
|
||||
status: 'guest'
|
||||
}),
|
||||
getters: {
|
||||
isAuthenticated: (state) => state.status === 'authenticated'
|
||||
},
|
||||
actions: {
|
||||
setSession(tokens: { accessToken: string; refreshToken: string }, profile: UserProfile) {
|
||||
this.status = 'authenticated';
|
||||
this.accessToken = tokens.accessToken;
|
||||
this.refreshToken = tokens.refreshToken;
|
||||
this.profile = profile;
|
||||
},
|
||||
clearSession() {
|
||||
this.status = 'guest';
|
||||
this.accessToken = undefined;
|
||||
this.refreshToken = undefined;
|
||||
this.profile = undefined;
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user