mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 13:38:43 +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',
|
||||
USER_EXIST_ERROR: 'User is exists! Please try another email!',
|
||||
};
|
||||
|
||||
export const BTN_CONTENT = {
|
||||
GOT_IT: 'Got it!',
|
||||
OK: 'Ok',
|
||||
};
|
||||
|
||||
export const LOCAL_STORAGE = {
|
||||
ACCESS_TOKEN: 'accessToken',
|
||||
};
|
||||
|
||||
export const TYPE_POPUP = { success: 'success', error: 'error' };
|
||||
export const MARK_ICON = { success: 'check', error: 'error' };
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
export default class User {
|
||||
constructor({ email, password, walletName = '' }) {
|
||||
constructor({ email, password, walletName = '', accessToken = '' }) {
|
||||
this.id = User.createIdUser();
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.walletName = walletName;
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
|
||||
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 CommonService from './commonService';
|
||||
import LocalStorageService from './localStorageService';
|
||||
|
||||
export default class UserService extends CommonService {
|
||||
constructor() {
|
||||
@@ -76,6 +78,13 @@ export default class UserService extends CommonService {
|
||||
|
||||
// Add token to user object
|
||||
newUserData.accessToken = createToken();
|
||||
|
||||
this.save(newUserData);
|
||||
|
||||
// Add access token to local storage
|
||||
LocalStorageService.add(
|
||||
LOCAL_STORAGE.ACCESS_TOKEN,
|
||||
newUserData.accessToken,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user