Last change
on this file was 17c7d5e, checked in by Aleksandarj03 <138524804+Aleksandarj03@…>, 8 days ago |
Major design overhauls pre prototype presentation 2
|
-
Property mode
set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[17bf12d] | 1 | import { defineStore } from 'pinia'
|
---|
| 2 |
|
---|
| 3 | export const userStore = defineStore('userStore', {
|
---|
| 4 |
|
---|
| 5 | state() {
|
---|
| 6 | return {
|
---|
| 7 | data: {
|
---|
| 8 | id: 0,
|
---|
| 9 | firstName: "",
|
---|
| 10 | lastName: "",
|
---|
| 11 | email: "",
|
---|
| 12 | phoneNumber: "",
|
---|
| 13 | role: "UN_AUTHENTICATED",
|
---|
| 14 | token: ""
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | }
|
---|
| 18 | },
|
---|
| 19 | actions: {
|
---|
| 20 |
|
---|
| 21 | setLocalStorage(jsonObject) {
|
---|
| 22 |
|
---|
| 23 | this.data = jsonObject
|
---|
| 24 |
|
---|
| 25 | localStorage.setItem('userData', JSON.stringify(jsonObject));
|
---|
| 26 |
|
---|
| 27 | },
|
---|
[32d1959] | 28 | setNewEditedDataToLocalStorage(jsonObject) {
|
---|
| 29 | const {firstName, lastName, phoneNumber} = jsonObject;
|
---|
| 30 | this.data.firstName = firstName;
|
---|
| 31 | this.data.lastName = lastName;
|
---|
| 32 | this.data.phoneNumber = phoneNumber;
|
---|
| 33 |
|
---|
| 34 | localStorage.setItem('userData', JSON.stringify(this.data));
|
---|
| 35 | },
|
---|
| 36 | setNewEmailToLocalStorage(jsonObject) {
|
---|
| 37 | const {email, jwt} = jsonObject;
|
---|
| 38 | this.data.email = email;
|
---|
| 39 | this.data.token = jwt;
|
---|
| 40 |
|
---|
| 41 | localStorage.setItem('userData', JSON.stringify(this.data));
|
---|
| 42 | },
|
---|
[17bf12d] | 43 | getLocalStorage() {
|
---|
| 44 | let nonparsed = localStorage.getItem('userData');
|
---|
| 45 | if (nonparsed !== null) {
|
---|
| 46 | this.data = JSON.parse(nonparsed);
|
---|
| 47 | }
|
---|
[2a2614e] | 48 | },
|
---|
| 49 | clearLocalStorage() {
|
---|
| 50 |
|
---|
| 51 | this.data = {
|
---|
| 52 | id: 0,
|
---|
| 53 | firstName: "",
|
---|
| 54 | lastName: "",
|
---|
| 55 | email: "",
|
---|
| 56 | phoneNumber: "",
|
---|
| 57 | role: "UN_AUTHENTICATED",
|
---|
| 58 | token: ""
|
---|
| 59 | }
|
---|
| 60 | localStorage.setItem('userData', JSON.stringify(this.data));
|
---|
| 61 |
|
---|
[17bf12d] | 62 | }
|
---|
[c3d3266] | 63 | },
|
---|
| 64 | getters: {
|
---|
| 65 | getToken(){
|
---|
| 66 | return 'Bearer ' + this.data.token;
|
---|
| 67 | }
|
---|
[17bf12d] | 68 | }
|
---|
| 69 | })
|
---|
Note:
See
TracBrowser
for help on using the repository browser.