Skip to content
Snippets Groups Projects
Commit 1b517081 authored by michael.minelli's avatar michael.minelli
Browse files

Add Session Manager

parent adc7bb61
No related branches found
No related tags found
No related merge requests found
import * as jwt from 'jsonwebtoken';
import User from '../models/User';
import LocalConfig from '../Config/LocalConfig/LocalConfig';
import LocalConfigKeys from '../Config/LocalConfig/LocalConfigKeys';
class SessionManager {
private _token: string | null = null;
public profile: User = new User();
constructor() { }
private static _instance: SessionManager;
public static get instance(): SessionManager {
if ( !SessionManager._instance ) {
SessionManager._instance = new SessionManager();
}
return SessionManager._instance;
}
get isLogged(): boolean {
return this._token !== null;
}
get token(): string {
return this._token || '';
}
set token(token: string) {
this._token = token;
const payload = jwt.decode(token);
if ( payload && typeof payload === 'object' && payload.profile ) {
this.profile = User.createFromJson(payload.profile);
}
LocalConfig.updateConfig(LocalConfigKeys.API_TOKEN, token);
}
}
export default SessionManager.instance;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment