-
-
Save amandeepmittal/3f10c00fadc3465ab78eec8bec740c64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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