Skip to content

Commit

Permalink
fix persistance login et store
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelQuetin committed Jul 10, 2024
1 parent 90966f2 commit 97677f1
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 97677f1

Please sign in to comment.