Files
AnimeTV-Backend/src/modules/auth/services/http/logout.service.ts
Rafi Arrafif 63fcd8587b
All checks were successful
Integration Tests / integration-tests (pull_request) Successful in 37s
🚨 fix: resolve all linting errors
2026-02-15 23:08:07 +07:00

22 lines
803 B
TypeScript

import { AppError } from "../../../../helpers/error/instances/app";
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
import { jwtDecode } from "../../../../helpers/http/jwt/decode";
import { redis } from "../../../../utils/databases/redis/connection";
import { deleteUserSessionRepository } from "../../../userSession/repositories/deleteUserSession.repository";
export const logoutService = async (jwtToken?: string) => {
try {
if (!jwtToken) throw new AppError(403, "No auth token provided");
const jwtPayload = jwtDecode(jwtToken);
await redis.del(
`${process.env.APP_NAME}:users:${jwtPayload.user.id}:sessions:${jwtPayload.id}`,
);
return deleteUserSessionRepository(jwtPayload.id);
} catch (error) {
ErrorForwarder(error);
}
};