Skip to content

Commit

Permalink
Merge pull request #89 from abes-esr/fix-persistance
Browse files Browse the repository at this point in the history
fix  persistance login et store
  • Loading branch information
jvk88511334 authored Jul 10, 2024
2 parents 90966f2 + 97677f1 commit 5b4dc09
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/store/authStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { defineStore } from 'pinia';

export const useAuthStore = defineStore('auth', {
state: () => ({
authenticated: false,
user: null,
token: null
user: JSON.parse(sessionStorage.getItem('user')),
token: sessionStorage.getItem('token'),
authenticated: !!this.token,
}),
getters: {
getUser: (state) => state.user,
Expand All @@ -16,11 +16,15 @@ export const useAuthStore = defineStore('auth', {
this.authenticated = true;
this.user = user;
this.token = token;
sessionStorage.setItem('user', JSON.stringify(this.user));
sessionStorage.setItem('token', this.token);
},
logout() {
this.authenticated = false;
this.user = null;
this.token = null;
sessionStorage.setItem('user', JSON.stringify(this.user))
sessionStorage.setItem('token', this.token);
},
setToken(token) {
this.token = token;
Expand All @@ -29,5 +33,4 @@ export const useAuthStore = defineStore('auth', {
this.user = user;
}
},
persist: true // This will persist the store to localStorage
});

0 comments on commit 5b4dc09

Please sign in to comment.