discord-client/webpack/lib/authentication.js

45 lines
948 B
JavaScript
Raw Normal View History

import LocalStorageInterface from './local-storage-interface'
export default class Authentication{
/* (1) Constructs an Authentication object
*
*
---------------------------------------------------------*/
constructor(){
/* (1) Default localStorage Interface */
this.lsi = new LocalStorageInterface('__auth__', 5*60);
/* (2) Update token */
if( this.token !== null && this.user !== null ){
this.lsi.push('token', this.token);
this.lsi.push('user', this.user);
}
}
/* (2) facade
*
---------------------------------------------------------*/
// TOKEN
get token(){
let tok = this.lsi.fetch('token');
// redirect if on 'auth' page
if( tok === null && gs.get.authed )
document.location = '';
return tok;
}
set token(_token){ return this.lsi.push('token', _token); }
// USER DATA
get user(){ return this.lsi.fetch('user'); }
set user(_user){ return this.lsi.push('user', _user); }
}