1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-10 09:02:50 +00:00
Files
classic-wow-forums/client/app/services/user.service.ts
2018-01-08 22:27:21 -06:00

25 lines
628 B
TypeScript

import axios from '../axios/axios';
import { UserModel } from '../model';
export class UserService {
public static storeUser(user: UserModel): void {
localStorage.setItem('user', JSON.stringify(user));
}
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);
}
}
}