Created
May 13, 2020 11:38
-
-
Save adambouchard/107e3fc76ecf9c6e97f38d2e4a0d1fe5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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