diff --git a/.gitignore b/.gitignore index 8a20513..38250d9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ node_modules .env.example .env.prod package-lock.json -prisma/generated/ \ No newline at end of file +prisma/generated/ +dist \ No newline at end of file diff --git a/src/app.ts b/src/app.ts index 7e60569..4a328f8 100644 --- a/src/app.ts +++ b/src/app.ts @@ -15,7 +15,7 @@ app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec)); // middleware app.use(cors({ - origin: ["http://localhost:3000"], + origin: ["http://localhost:5173"], methods: ["GET", "POST", "PATCH", "DELETE", "PUT"], credentials: true })) diff --git a/src/app/modules/account/account.controller.ts b/src/app/modules/account/account.controller.ts index 114f159..5fe1c1d 100644 --- a/src/app/modules/account/account.controller.ts +++ b/src/app/modules/account/account.controller.ts @@ -37,7 +37,7 @@ const login_user = catchAsync(async (req, res) => { const result = await account_services.login_user_into_db(req); // set access token into cookie - res.cookie("access_token", result, { + res.cookie("access_token", result.accessToken, { secure: configs.env === "production", httpOnly: true, }); @@ -46,9 +46,7 @@ const login_user = catchAsync(async (req, res) => { statusCode: 200, success: true, message: "User logged in successfully", - data: { - accessToken: result, - }, + data: result, }); }); const get_user_account = catchAsync(async (req, res) => { diff --git a/src/app/modules/account/account.service.ts b/src/app/modules/account/account.service.ts index 1ce71a7..f2d33f8 100644 --- a/src/app/modules/account/account.service.ts +++ b/src/app/modules/account/account.service.ts @@ -22,7 +22,7 @@ const create_account_into_db = async (req: Request) => { const hashPassword = bcrypt.hashSync(payload.password, 10); // create account and profile - const result = await prisma.$transaction(async (tx:any) => { + const result = await prisma.$transaction(async (tx: any) => { const account = await tx.account.create({ data: { email: payload.email, @@ -160,6 +160,15 @@ const login_user_into_db = async (req: Request) => { where: { email: payload.email, }, + select: { + id: true, + email: true, + role: true, + isAccountVerified: true, + isDeleted: true, + password: true, + profile: true, + }, }); // 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_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) => {