source: ReserveNGo-frontend/src/PiniaStores/UserStore.js@ c3d3266

Last change on this file since c3d3266 was c3d3266, checked in by Aleksandarj03 <138524804+Aleksandarj03@…>, 3 months ago

Ne rabote fetcho

  • Property mode set to 100644
File size: 1.1 KB
Line 
1
2import { defineStore } from 'pinia'
3
4
5
6export const userStore = defineStore('userStore', {
7
8 state() {
9 return {
10
11 data: {
12 id: 0,
13 firstName: "",
14 lastName: "",
15 email: "",
16 phoneNumber: "",
17 role: "UN_AUTHENTICATED",
18 token: ""
19 }
20
21 }
22 },
23 actions: {
24
25 setLocalStorage(jsonObject) {
26 //console.log("Local Storage object", jsonObject)
27
28 this.data = jsonObject
29
30 console.log("Local Storage data", this.data.firstName, this.data.lastName)
31
32 localStorage.setItem('userData', JSON.stringify(jsonObject));
33
34 },
35 getLocalStorage() {
36 let nonparsed = localStorage.getItem('userData');
37 if (nonparsed !== null) {
38 this.data = JSON.parse(nonparsed);
39 }
40 },
41 clearLocalStorage() {
42
43 this.data = {
44 id: 0,
45 firstName: "",
46 lastName: "",
47 email: "",
48 phoneNumber: "",
49 role: "UN_AUTHENTICATED",
50 token: ""
51 }
52 localStorage.setItem('userData', JSON.stringify(this.data));
53
54 }
55
56
57
58 },
59 getters: {
60 getToken(){
61 return 'Bearer ' + this.data.token;
62 }
63 }
64
65
66
67
68
69
70})
Note: See TracBrowser for help on using the repository browser.