feat/logout #17
@ -9,7 +9,7 @@ export const jwtDecode = (payload: string) => {
|
|||||||
try {
|
try {
|
||||||
const decodedPayload = jwt.verify(payload, JWTKey);
|
const decodedPayload = jwt.verify(payload, JWTKey);
|
||||||
return decodedPayload as JWTAuthToken;
|
return decodedPayload as JWTAuthToken;
|
||||||
} catch (error) {
|
} catch {
|
||||||
throw new AppError(401, "Invalid or expired token", error);
|
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 { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||||
import { jwtDecode } from "../../../../helpers/http/jwt/decode";
|
import { jwtDecode } from "../../../../helpers/http/jwt/decode";
|
||||||
|
|
||||||
export const tokenValidationService = (payload: string) => {
|
export const tokenValidationService = (payload: string) => {
|
||||||
try {
|
try {
|
||||||
if (!payload) return null;
|
if (!payload || payload.trim() === "")
|
||||||
|
throw new AppError(401, "Unauthorized: No token provided");
|
||||||
const decoded = jwtDecode(payload);
|
const decoded = jwtDecode(payload);
|
||||||
return decoded;
|
return decoded;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user