🔒 security: add auth token validation via Redis and DB check
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
import { AppError } from "../../../helpers/error/instances/app";
|
||||
import { userSessionModel } from "../userSession.model";
|
||||
|
||||
export const checkUserSessionRepository = async (sessionId: string) => {
|
||||
try {
|
||||
return await userSessionModel.findUnique({
|
||||
where: {
|
||||
id: sessionId,
|
||||
isAuthenticated: true,
|
||||
deletedAt: null,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
throw new AppError(500, "Database error during session validation", error);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,13 @@
|
||||
import { ErrorForwarder } from "../../../../helpers/error/instances/forwarder";
|
||||
import { checkUserSessionRepository } from "../../repositories/checkUserSession.repository";
|
||||
|
||||
export const checkUserSessionInDBService = async (
|
||||
sessionId: string,
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const dbValidationResult = await checkUserSessionRepository(sessionId);
|
||||
return dbValidationResult ? true : false;
|
||||
} catch (error) {
|
||||
ErrorForwarder(error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user