discord-client/webpack/lib/authentication.js

36 lines
841 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(){ return this.lsi.fetch('token'); }
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); }
}