🔧 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:
@ -10,13 +10,10 @@ export const githubCallbackController = async (
|
|||||||
try {
|
try {
|
||||||
const userHeaderInfo = getUserHeaderInformation(ctx);
|
const userHeaderInfo = getUserHeaderInformation(ctx);
|
||||||
|
|
||||||
const userData = await githubCallbackService(ctx.query, userHeaderInfo);
|
const authToken = await githubCallbackService(ctx.query, userHeaderInfo);
|
||||||
return returnWriteResponse(
|
return returnWriteResponse(ctx.set, 200, "Authenticated successfully!", {
|
||||||
ctx.set,
|
authToken,
|
||||||
200,
|
});
|
||||||
"Authenticated successfully!",
|
|
||||||
userData
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return mainErrorHandler(ctx.set, error);
|
return mainErrorHandler(ctx.set, error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,13 +10,10 @@ export const googleCallbackController = async (
|
|||||||
try {
|
try {
|
||||||
const userHeaderInfo = getUserHeaderInformation(ctx);
|
const userHeaderInfo = getUserHeaderInformation(ctx);
|
||||||
|
|
||||||
const userData = await googleCallbackService(ctx.query, userHeaderInfo);
|
const authToken = await googleCallbackService(ctx.query, userHeaderInfo);
|
||||||
return returnReadResponse(
|
return returnReadResponse(ctx.set, 200, "Authenticated successfully!", {
|
||||||
ctx.set,
|
authToken,
|
||||||
200,
|
});
|
||||||
"Authenticated successfully!",
|
|
||||||
userData
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return mainErrorHandler(ctx.set, error);
|
return mainErrorHandler(ctx.set, error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,22 +2,46 @@ import { Prisma } from "@prisma/client";
|
|||||||
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
import { ErrorForwarder } from "../../../helpers/error/instances/forwarder";
|
||||||
import { userSessionModel } from "../userSession.model";
|
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 (
|
export const createUserSessionRepository = async (
|
||||||
data: Prisma.UserSessionUncheckedCreateInput
|
data: Prisma.UserSessionUncheckedCreateInput
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
return await userSessionModel.create({
|
return await userSessionModel.create({
|
||||||
data,
|
data,
|
||||||
include: {
|
select: {
|
||||||
|
id: true,
|
||||||
|
deviceType: true,
|
||||||
|
isAuthenticated: true,
|
||||||
|
validUntil: true,
|
||||||
user: {
|
user: {
|
||||||
omit: {
|
select: {
|
||||||
password: true,
|
id: true,
|
||||||
providerToken: true,
|
name: true,
|
||||||
providerPayload: true,
|
email: true,
|
||||||
deletedAt: true,
|
username: true,
|
||||||
},
|
avatar: true,
|
||||||
include: {
|
birthDate: true,
|
||||||
preference: true,
|
bioProfile: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user