🛂 security: fix auth token validation flow
This commit is contained in:
@ -9,7 +9,7 @@ export const jwtDecode = (payload: string) => {
|
||||
try {
|
||||
const decodedPayload = jwt.verify(payload, JWTKey);
|
||||
return decodedPayload as JWTAuthToken;
|
||||
} catch (error) {
|
||||
throw new AppError(401, "Invalid or expired token", error);
|
||||
} catch {
|
||||
throw new AppError(403, "Invalid or expired token");
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { AppError } from "../../../../helpers/error/instances/app";
|
||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||
import { jwtDecode } from "../../../../helpers/http/jwt/decode";
|
||||
|
||||
export const tokenValidationService = (payload: string) => {
|
||||
try {
|
||||
if (!payload) return null;
|
||||
if (!payload || payload.trim() === "")
|
||||
throw new AppError(401, "Unauthorized: No token provided");
|
||||
const decoded = jwtDecode(payload);
|
||||
return decoded;
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user