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

Last change on this file since 32d1959 was 32d1959, checked in by Ljubomir Ilievski <ilievski.ljubomir@…>, 2 months ago

Complete Profile Page

  • Property mode set to 100644
File size: 1.6 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 setNewEditedDataToLocalStorage(jsonObject) {
36 const {firstName, lastName, phoneNumber} = jsonObject;
37 this.data.firstName = firstName;
38 this.data.lastName = lastName;
39 this.data.phoneNumber = phoneNumber;
40
41 localStorage.setItem('userData', JSON.stringify(this.data));
42 },
43 setNewEmailToLocalStorage(jsonObject) {
44 const {email, jwt} = jsonObject;
45 this.data.email = email;
46 this.data.token = jwt;
47
48 localStorage.setItem('userData', JSON.stringify(this.data));
49 },
50 getLocalStorage() {
51 let nonparsed = localStorage.getItem('userData');
52 if (nonparsed !== null) {
53 this.data = JSON.parse(nonparsed);
54 }
55 },
56 clearLocalStorage() {
57
58 this.data = {
59 id: 0,
60 firstName: "",
61 lastName: "",
62 email: "",
63 phoneNumber: "",
64 role: "UN_AUTHENTICATED",
65 token: ""
66 }
67 localStorage.setItem('userData', JSON.stringify(this.data));
68
69 }
70
71
72
73 },
74 getters: {
75 getToken(){
76 return 'Bearer ' + this.data.token;
77 }
78 }
79
80
81
82
83
84
85})
Note: See TracBrowser for help on using the repository browser.