Skip to content

Instantly share code, notes, and snippets.

@amandeepmittal
Created November 4, 2018 16:07
Show Gist options
  • Save amandeepmittal/3f10c00fadc3465ab78eec8bec740c64 to your computer and use it in GitHub Desktop.
Save amandeepmittal/3f10c00fadc3465ab78eec8bec740c64 to your computer and use it in GitHub Desktop.
import { signout } from '../../utils/api-auth.js';
const auth = {
isAuthenticated() {
if (typeof window == 'undefined') return false;
if (sessionStorage.getItem('jwt'))
return JSON.parse(sessionStorage.getItem('jwt'));
else return false;
},
authenticate(jwt, cb) {
if (typeof window !== 'undefined')
sessionStorage.setItem('jwt', JSON.stringify(jwt));
cb();
},
signout(cb) {
if (typeof window !== 'undefined') sessionStorage.removeItem('jwt');
cb();
//optional
signout().then(data => {
document.cookie = 't=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
});
}
};
export default auth;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment