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

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

Celosno funkcionalna logika na login/register/logout

  • Property mode set to 100644
File size: 1.0 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
60
61
62
63
64})
Note: See TracBrowser for help on using the repository browser.