🎨 (jwt helper) create type and add details in error scope
create a type for JWT encode and add error details in JWT decode error scope
This commit is contained in:
@ -11,6 +11,6 @@ export const jwtDecode = (payload: string) => {
|
||||
const decodedPayload = jwt.verify(payload, JWTKey);
|
||||
return decodedPayload as JWTSessionPayload;
|
||||
} catch (error) {
|
||||
throw new AppError(401, "Invalid or expired token");
|
||||
throw new AppError(401, "Invalid or expired token", error);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
export const jwtEncode = (payload: any) => {
|
||||
export const jwtEncode = <T extends object>(payload: T) => {
|
||||
const tokenLifetime = Number(process.env.SESSION_EXPIRE!);
|
||||
const jwtSecret = process.env.JWT_SECRET!;
|
||||
const jwtToken = jwt.sign(payload, jwtSecret, {
|
||||
|
||||
Reference in New Issue
Block a user