Merge pull request #28 from rede5/codex/verificar-erro-de-login
Corrige login do marketplace quando token JWT ausente
This commit is contained in:
commit
fa726e5864
2 changed files with 5 additions and 1 deletions
|
|
@ -30,6 +30,9 @@ export function LoginPage() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { token } = await authService.login({ username, password })
|
const { token } = await authService.login({ username, password })
|
||||||
|
if (!token) {
|
||||||
|
throw new Error('Resposta de login inválida. Verifique o usuário e a senha.')
|
||||||
|
}
|
||||||
const payload = decodeJwtPayload<{ role?: string }>(token)
|
const payload = decodeJwtPayload<{ role?: string }>(token)
|
||||||
const role = resolveRole(payload?.role)
|
const role = resolveRole(payload?.role)
|
||||||
login(token, role, username)
|
login(token, role, username)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
const toBase64 = (value: string) =>
|
const toBase64 = (value: string) =>
|
||||||
value.replace(/-/g, '+').replace(/_/g, '/').padEnd(Math.ceil(value.length / 4) * 4, '=')
|
value.replace(/-/g, '+').replace(/_/g, '/').padEnd(Math.ceil(value.length / 4) * 4, '=')
|
||||||
|
|
||||||
export const decodeJwtPayload = <T extends Record<string, unknown>>(token: string): T | null => {
|
export const decodeJwtPayload = <T extends Record<string, unknown>>(token?: string): T | null => {
|
||||||
|
if (!token) return null
|
||||||
const [, payload] = token.split('.')
|
const [, payload] = token.split('.')
|
||||||
if (!payload) return null
|
if (!payload) return null
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue