Merge pull request #46 from KevinMidboe/fix/admin-from-jwt
Fix/admin from jwt
This commit is contained in:
@@ -24,6 +24,7 @@ import storage from '../storage'
|
|||||||
import SeasonedInput from '@/components/ui/SeasonedInput'
|
import SeasonedInput from '@/components/ui/SeasonedInput'
|
||||||
import SeasonedButton from '@/components/ui/SeasonedButton'
|
import SeasonedButton from '@/components/ui/SeasonedButton'
|
||||||
import SeasonedMessages from '@/components/ui/SeasonedMessages'
|
import SeasonedMessages from '@/components/ui/SeasonedMessages'
|
||||||
|
import { parseJwt } from '@/utils'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { SeasonedInput, SeasonedButton, SeasonedMessages },
|
components: { SeasonedInput, SeasonedButton, SeasonedMessages },
|
||||||
@@ -45,9 +46,10 @@ export default {
|
|||||||
login(username, password)
|
login(username, password)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.success){
|
if (data.success){
|
||||||
|
const jwtData = parseJwt(data.token)
|
||||||
localStorage.setItem('token', data.token);
|
localStorage.setItem('token', data.token);
|
||||||
localStorage.setItem('username', username);
|
localStorage.setItem('username', jwtData['username']);
|
||||||
localStorage.setItem('admin', data.admin || false);
|
localStorage.setItem('admin', jwtData['admin'] || false);
|
||||||
|
|
||||||
eventHub.$emit('setUserStatus');
|
eventHub.$emit('setUserStatus');
|
||||||
this.$router.push({ name: 'profile' })
|
this.$router.push({ name: 'profile' })
|
||||||
|
|||||||
14
src/utils.js
14
src/utils.js
@@ -7,7 +7,17 @@ const sortableSize = (string) => {
|
|||||||
|
|
||||||
const exponent = UNITS.indexOf(unit) * 3
|
const exponent = UNITS.indexOf(unit) * 3
|
||||||
return numStr * (Math.pow(10, exponent))
|
return numStr * (Math.pow(10, exponent))
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const parseJwt = (token) => {
|
||||||
|
var base64Url = token.split('.')[1];
|
||||||
|
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
||||||
|
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
|
||||||
|
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
||||||
|
}).join(''));
|
||||||
|
|
||||||
|
return JSON.parse(jsonPayload);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
export { sortableSize }
|
export { sortableSize, parseJwt }
|
||||||
Reference in New Issue
Block a user