mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-11 09:32:51 +00:00
client - refactor services
This commit is contained in:
@@ -1,24 +1,27 @@
|
||||
import axios from '../axios/axios';
|
||||
import { UserModel } from '../model';
|
||||
|
||||
export class UserService {
|
||||
const storeUser = (user: UserModel): void => {
|
||||
localStorage.setItem('user', JSON.stringify(user));
|
||||
}
|
||||
|
||||
public static storeUser(user: UserModel): void {
|
||||
localStorage.setItem('user', JSON.stringify(user));
|
||||
}
|
||||
const getUser = (): UserModel => {
|
||||
const u = localStorage.getItem('user');
|
||||
return u ? JSON.parse(u) : null;
|
||||
}
|
||||
|
||||
public static getUser(): UserModel {
|
||||
const u = localStorage.getItem('user');
|
||||
return u ? JSON.parse(u) : null;
|
||||
}
|
||||
|
||||
// fetch user and store in local storage
|
||||
public static async authorize(code: string): Promise<void> {
|
||||
try {
|
||||
const res = await axios.post('/api/battlenet/authorize', { code });
|
||||
UserService.storeUser(res.data.data);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
// fetch user and store in local storage
|
||||
const authorize = async (code: string): Promise<void> => {
|
||||
try {
|
||||
const res = await axios.post('/api/battlenet/authorize', { code });
|
||||
UserService.storeUser(res.data.data);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
export const UserService = {
|
||||
storeUser,
|
||||
getUser,
|
||||
authorize,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user