🚩 create user session when provision
create a user session after provisioning authentication if the account has been created previously.
This commit is contained in:
@ -0,0 +1,15 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||
import { userSessionModel } from "../userSession.model";
|
||||
|
||||
export const createUserSessionRepository = async (
|
||||
data: Prisma.UserSessionUncheckedCreateInput
|
||||
) => {
|
||||
try {
|
||||
return await userSessionModel.create({
|
||||
data,
|
||||
});
|
||||
} catch (error) {
|
||||
ErrorForwarder(error);
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,28 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { UserHeaderInformation } from "../../../helpers/http/userHeader/getUserHeaderInformation/types";
|
||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||
import { createUserSessionRepository } from "../repositories/createUserSession.repository";
|
||||
|
||||
export const createUserSessionService = async (
|
||||
userId: string,
|
||||
userHeaderInfo: UserHeaderInformation
|
||||
) => {
|
||||
try {
|
||||
const generateTokenExpirationDate =
|
||||
Date.now() + Number(process.env.SESSION_EXPIRE!) * 1000;
|
||||
|
||||
const constructData = {
|
||||
userId,
|
||||
isAuthenticated: true,
|
||||
deviceType: userHeaderInfo.deviceType,
|
||||
deviceOs: userHeaderInfo.deviceOS,
|
||||
deviceIp: userHeaderInfo.ip,
|
||||
browser: userHeaderInfo.browser,
|
||||
validUntil: new Date(generateTokenExpirationDate),
|
||||
} as Prisma.UserSessionUncheckedCreateInput;
|
||||
|
||||
return createUserSessionRepository(constructData);
|
||||
} catch (error) {
|
||||
ErrorForwarder(error);
|
||||
}
|
||||
};
|
||||
3
src/modules/userSession/userSession.model.ts
Normal file
3
src/modules/userSession/userSession.model.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { prisma } from "../../utils/databases/prisma/connection";
|
||||
|
||||
export const userSessionModel = prisma.userSession;
|
||||
Reference in New Issue
Block a user