fix: Add explicit error for missing auth token
This commit is contained in:
@@ -5,6 +5,9 @@ import { AuthenticationError } from "../errors";
|
|||||||
|
|
||||||
export function getJWTPayload(token: string) {
|
export function getJWTPayload(token: string) {
|
||||||
let payload;
|
let payload;
|
||||||
|
if (!token) {
|
||||||
|
throw AuthenticationError("Missing token");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
payload = JWT.decode(token);
|
payload = JWT.decode(token);
|
||||||
@@ -15,7 +18,7 @@ export function getJWTPayload(token: string) {
|
|||||||
|
|
||||||
return payload as JWT.JwtPayload;
|
return payload as JWT.JwtPayload;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw AuthenticationError("Unable to decode JWT token");
|
throw AuthenticationError("Unable to decode token");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user