First pass at v2_api

This commit is contained in:
Dessalines 2020-12-23 20:58:27 -05:00
parent 6ffe0c530d
commit ea317af269
41 changed files with 2217 additions and 2466 deletions

View file

@ -1,8 +1,10 @@
// import Cookies from 'js-cookie';
import IsomorphicCookie from 'isomorphic-cookie';
import { User, LoginResponse } from 'lemmy-js-client';
import { User_, LoginResponse } from 'lemmy-js-client';
import jwt_decode from 'jwt-decode';
import { Subject, BehaviorSubject } from 'rxjs';
import { i18n } from '../i18next';
import { toast } from '../utils';
interface Claims {
id: number;
@ -11,7 +13,7 @@ interface Claims {
export class UserService {
private static _instance: UserService;
public user: User;
public user: User_;
public claims: Claims;
public jwtSub: Subject<string> = new Subject<string>();
public unreadCountSub: BehaviorSubject<number> = new BehaviorSubject<number>(
@ -48,6 +50,15 @@ export class UserService {
return IsomorphicCookie.load('jwt');
}
public authField(throwErr: boolean = true): string {
if (this.auth == null && throwErr) {
toast(i18n.t('not_logged_in'), 'danger');
throw 'Not logged in';
} else {
return this.auth;
}
}
private setClaims(jwt: string) {
this.claims = jwt_decode(jwt);
this.jwtSub.next(jwt);