Оптимизировал проверки

jwt
Rinsvent 2 years ago
parent 4f02f56f85
commit 3c76c7dc09
  1. 16
      functions/token.ts

@ -62,12 +62,22 @@ export const grabTokenData = (token: string): TokenData|null => {
if (!isClient()) { if (!isClient()) {
return null return null
} }
const parts = token.split('.') const parts = token.split('.')
let payload = 3 === parts.length && parts[1] ? JSON.parse(window.atob(parts[1])) : null if (parts.length !== 3) {
let headers = 3 === parts.length && parts[0] ? JSON.parse(window.atob(parts[0])) : null return null
if (!payload || !headers){ }
let payload = JSON.parse(window.atob(parts[1]))
if (!payload){
return null return null
} }
let headers = JSON.parse(window.atob(parts[0]))
if (!headers){
return null
}
return { return {
payload, payload,
headers, headers,

Loading…
Cancel
Save