✨ feat: add logout module
This commit is contained in:
@ -1,15 +1,14 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
import { JWTSessionPayload } from "../../../../modules/auth/auth.types";
|
||||
import { JWTAuthToken } from "./types";
|
||||
import { AppError } from "../../../error/instances/app";
|
||||
|
||||
export const jwtDecode = (payload: string) => {
|
||||
// return payload;
|
||||
if (!payload) throw new AppError(401, "Unauthorized");
|
||||
const JWTKey = process.env.JWT_SECRET!;
|
||||
|
||||
try {
|
||||
const decodedPayload = jwt.verify(payload, JWTKey);
|
||||
return decodedPayload as JWTSessionPayload;
|
||||
return decodedPayload as JWTAuthToken;
|
||||
} catch (error) {
|
||||
throw new AppError(401, "Invalid or expired token", error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user