🔧 chore: change selected data when create user session
These changes include: 1. Changes to the response structure when logging in with a third-party provider, by wrapping the token in `authToken` instead of directly entering it in the return data section. 2. Adding a type to user session creation by taking only the important elements. This is to prevent data leaks because important data is in jwt.
This commit is contained in:
@ -2,22 +2,46 @@ import { Prisma } from "@prisma/client";
|
||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||
import { userSessionModel } from "../userSession.model";
|
||||
|
||||
type CreateUserSessionResponse = Prisma.UserSessionGetPayload<{
|
||||
select: {
|
||||
id: true;
|
||||
deviceType: true;
|
||||
isAuthenticated: true;
|
||||
validUntil: true;
|
||||
user: {
|
||||
select: {
|
||||
id: true;
|
||||
name: true;
|
||||
email: true;
|
||||
username: true;
|
||||
avatar: true;
|
||||
birthDate: true;
|
||||
bioProfile: true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}>;
|
||||
|
||||
export const createUserSessionRepository = async (
|
||||
data: Prisma.UserSessionUncheckedCreateInput
|
||||
) => {
|
||||
try {
|
||||
return await userSessionModel.create({
|
||||
data,
|
||||
include: {
|
||||
select: {
|
||||
id: true,
|
||||
deviceType: true,
|
||||
isAuthenticated: true,
|
||||
validUntil: true,
|
||||
user: {
|
||||
omit: {
|
||||
password: true,
|
||||
providerToken: true,
|
||||
providerPayload: true,
|
||||
deletedAt: true,
|
||||
},
|
||||
include: {
|
||||
preference: true,
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
username: true,
|
||||
avatar: true,
|
||||
birthDate: true,
|
||||
bioProfile: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user