mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 20:01:31 +00:00
Merge pull request #14 from Nez27/feat/impl-local-storage-service
Implement local storage service
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -11,9 +11,15 @@ export const MESSAGE = {
|
|||||||
DEFAULT_TITLE_ERROR_POPUP: 'Error',
|
DEFAULT_TITLE_ERROR_POPUP: 'Error',
|
||||||
USER_EXIST_ERROR: 'User is exists! Please try another email!',
|
USER_EXIST_ERROR: 'User is exists! Please try another email!',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const BTN_CONTENT = {
|
export const BTN_CONTENT = {
|
||||||
GOT_IT: 'Got it!',
|
GOT_IT: 'Got it!',
|
||||||
OK: 'Ok',
|
OK: 'Ok',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const LOCAL_STORAGE = {
|
||||||
|
ACCESS_TOKEN: 'accessToken',
|
||||||
|
};
|
||||||
|
|
||||||
export const TYPE_POPUP = { success: 'success', error: 'error' };
|
export const TYPE_POPUP = { success: 'success', error: 'error' };
|
||||||
export const MARK_ICON = { success: 'check', error: 'error' };
|
export const MARK_ICON = { success: 'check', error: 'error' };
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
export default class User {
|
export default class User {
|
||||||
constructor({ email, password, walletName = '' }) {
|
constructor({ email, password, walletName = '', accessToken = '' }) {
|
||||||
this.id = User.createIdUser();
|
this.id = User.createIdUser();
|
||||||
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
get(key) {
|
||||||
|
this.localStorage.getItem(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(key) {
|
||||||
|
this.localStorage.removeItem(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
this.localStorage.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new LocalStorageService();
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
|
import { LOCAL_STORAGE } from '../constants/constant';
|
||||||
import { createToken } from '../helpers/helpers';
|
import { createToken } from '../helpers/helpers';
|
||||||
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() {
|
||||||
@@ -76,6 +78,13 @@ export default class UserService extends CommonService {
|
|||||||
|
|
||||||
// Add token to user object
|
// Add token to user object
|
||||||
newUserData.accessToken = createToken();
|
newUserData.accessToken = createToken();
|
||||||
|
|
||||||
this.save(newUserData);
|
this.save(newUserData);
|
||||||
|
|
||||||
|
// Add access token to local storage
|
||||||
|
LocalStorageService.add(
|
||||||
|
LOCAL_STORAGE.ACCESS_TOKEN,
|
||||||
|
newUserData.accessToken,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user