✨ feat(account): update login response and modify CORS origin
- Changed the CORS origin from `http://localhost:3000` to `http://localhost:5173`. - Updated the login response to return a comprehensive object containing the `accessToken` and user profile data. - Modified cookie setup to directly use `result.accessToken` instead of `result`. - Refactored account service to include additional user fields in the login data returned. - Added `dist` to `.gitignore`.
This commit is contained in:
@@ -5,3 +5,4 @@ node_modules
|
|||||||
.env.prod
|
.env.prod
|
||||||
package-lock.json
|
package-lock.json
|
||||||
prisma/generated/
|
prisma/generated/
|
||||||
|
dist
|
||||||
+1
-1
@@ -15,7 +15,7 @@ app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
|
|||||||
|
|
||||||
// middleware
|
// middleware
|
||||||
app.use(cors({
|
app.use(cors({
|
||||||
origin: ["http://localhost:3000"],
|
origin: ["http://localhost:5173"],
|
||||||
methods: ["GET", "POST", "PATCH", "DELETE", "PUT"],
|
methods: ["GET", "POST", "PATCH", "DELETE", "PUT"],
|
||||||
credentials: true
|
credentials: true
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const login_user = catchAsync(async (req, res) => {
|
|||||||
const result = await account_services.login_user_into_db(req);
|
const result = await account_services.login_user_into_db(req);
|
||||||
|
|
||||||
// set access token into cookie
|
// set access token into cookie
|
||||||
res.cookie("access_token", result, {
|
res.cookie("access_token", result.accessToken, {
|
||||||
secure: configs.env === "production",
|
secure: configs.env === "production",
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
});
|
});
|
||||||
@@ -46,9 +46,7 @@ const login_user = catchAsync(async (req, res) => {
|
|||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
success: true,
|
success: true,
|
||||||
message: "User logged in successfully",
|
message: "User logged in successfully",
|
||||||
data: {
|
data: result,
|
||||||
accessToken: result,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const get_user_account = catchAsync(async (req, res) => {
|
const get_user_account = catchAsync(async (req, res) => {
|
||||||
|
|||||||
@@ -160,6 +160,15 @@ const login_user_into_db = async (req: Request) => {
|
|||||||
where: {
|
where: {
|
||||||
email: payload.email,
|
email: payload.email,
|
||||||
},
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
email: true,
|
||||||
|
role: true,
|
||||||
|
isAccountVerified: true,
|
||||||
|
isDeleted: true,
|
||||||
|
password: true,
|
||||||
|
profile: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// check if account exists
|
// check if account exists
|
||||||
@@ -196,7 +205,21 @@ const login_user_into_db = async (req: Request) => {
|
|||||||
configs.jwt.access_token as string,
|
configs.jwt.access_token as string,
|
||||||
configs.jwt.access_expires as string,
|
configs.jwt.access_expires as string,
|
||||||
);
|
);
|
||||||
return accessToken;
|
|
||||||
|
|
||||||
|
const finalOutputData = {
|
||||||
|
id: account.id,
|
||||||
|
email: account.email,
|
||||||
|
role: account.role,
|
||||||
|
shopName: account?.profile?.shopName,
|
||||||
|
shopLogo: account?.profile?.shopLogo,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
accessToken,
|
||||||
|
profile: finalOutputData
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const get_user_account_from_db = async (req: Request) => {
|
const get_user_account_from_db = async (req: Request) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user