Skip to content

Instantly share code, notes, and snippets.

@adambouchard
Created May 13, 2020 11:38
Show Gist options
  • Save adambouchard/107e3fc76ecf9c6e97f38d2e4a0d1fe5 to your computer and use it in GitHub Desktop.
Save adambouchard/107e3fc76ecf9c6e97f38d2e4a0d1fe5 to your computer and use it in GitHub Desktop.
import api from "api.js";
import jwt_decode from 'jwt-decode';
$(function(){
//Login Button
$('#btn-login').click(function() {
login()
}
//Select/Read/Parse/Display Config File
$('#configFile').change(function() {
//code here...
}
//..other event functions
}
function login() {
api.getAccessToken(params)
.then(resp => {
const accessToken = resp && resp.data && resp.data.token;
localStorage.setItem("accessToken", accessToken);
const decodedToken = jwt_decode(token)
console.log(decodedToken)
const name = `${decodedToken.data.user.firstName} ${decodedToken.data.user.lastName}`
localStorage.setItem(“currentUsername”, name);
})
.catch(err => {
console.log(err)
localStorage.removeItem("accessToken");
localStorage.removeItem("refreshToken");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment