mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-23 04:09:58 +00:00
Implement local storage service and add access token propery for user model
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
export default class User {
|
export default class User {
|
||||||
constructor({ email, password, walletName = '' }) {
|
constructor({ email, password, walletName = '', accessToken = '' }) {
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.walletName = walletName;
|
this.walletName = walletName;
|
||||||
|
this.accessToken = accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
static createIdUser() {
|
static createIdUser() {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
class LocalStorageService {
|
||||||
|
constructor() {
|
||||||
|
this.localStorage = localStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
add(key, value) {
|
||||||
|
this.localStorage.setItem(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get(key) {
|
||||||
|
this.localStorage.getItem(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
static remove(key) {
|
||||||
|
this.localStorage.removeItem(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
static clear() {
|
||||||
|
this.localStorage.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new LocalStorageService();
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { createToken } from '../helpers/helpers';
|
import { createToken } from '../helpers/helpers';
|
||||||
import User from '../models/user';
|
import User from '../models/user';
|
||||||
import CommonService from './commonService';
|
import CommonService from './commonService';
|
||||||
|
import LocalStorageService from './localStorageService';
|
||||||
|
|
||||||
export default class UserService extends CommonService {
|
export default class UserService extends CommonService {
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -62,5 +63,7 @@ export default class UserService extends CommonService {
|
|||||||
newUserData.accessToken = createToken();
|
newUserData.accessToken = createToken();
|
||||||
|
|
||||||
this.save(newUserData, this.defaultPath + id);
|
this.save(newUserData, this.defaultPath + id);
|
||||||
|
|
||||||
|
LocalStorageService.add('accessToken', newUserData.accessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user