Commit 8ec34053 by Nattana Chaiyamat

Merge branch 'DEV' of https://mygit.myhr.co.th/angular/myAppraisal into DEV

parents 44e63790 7f4e7e75
import { Injectable } from '@angular/core';
import { jwtDecode } from "jwt-decode";
const TOKEN_KEY = 'accessToken';
@Injectable({
......@@ -9,13 +8,23 @@ export class TokenService {
constructor() {
}
public getUser(): any {
const user = jwtDecode(window.sessionStorage.getItem(TOKEN_KEY)!)
const user = this.decodeJWT(window.sessionStorage.getItem(TOKEN_KEY)!)
if (user) {
return user;
}
return ;
}
decodeJWT(token: string) {
let base64Url = token.split('.')[1]; // ดึงส่วนที่เป็น Payload
let base64 = base64Url.replace('-', '+').replace('_', '/'); // แก้ไข base64 ให้ถูกต้อง
let jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
return JSON.parse(jsonPayload);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment