From 0cb10b459c8b092fb9e434089f0d05c4ef2466cb Mon Sep 17 00:00:00 2001 From: Ruslan K Date: Fri, 1 Dec 2023 11:55:27 +0100 Subject: [PATCH] Update login.ts --- apps/web/pages/api/auth/login.ts | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/apps/web/pages/api/auth/login.ts b/apps/web/pages/api/auth/login.ts index 41dbbf216..e2c22b7a2 100644 --- a/apps/web/pages/api/auth/login.ts +++ b/apps/web/pages/api/auth/login.ts @@ -11,13 +11,6 @@ import { } from '@app/services/server/requests'; import { NextApiRequest, NextApiResponse } from 'next'; -// const notFound = (res: NextApiResponse) => -// res.status(400).json({ -// errors: { -// code: 'Authentication code or email address invalid' -// } -// }); - export default async function handler(req: NextApiRequest, res: NextApiResponse) { const body = req.body as ILoginDataAPI; let loginResponse: ILoginResponse | null = null; @@ -29,14 +22,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } /** - * Verify first if match with invite code + * Verify first if matches with invite code */ const inviteReq = await verifyInviteCodeRequest({ email: body.email, code: body.code }).catch(() => void 0); /** - * If the invite code verification failed then try again with auth code + * If the invite code verification failed then try again with the Auth code */ if (!inviteReq || !inviteReq.response.ok || (inviteReq.data as any).response?.statusCode) { try { @@ -65,8 +58,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } /** - * If provided code is an invite code and - * verified the accepte and register the related user + * If the provided code is an invite code and + * verified then accept and register the related user */ } else { // General a random password with 8 chars @@ -96,6 +89,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } }); } + loginResponse = acceptInviteRes.data; } @@ -108,7 +102,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } /** - * Get the first team from first organization + * Get the first team from the first organization */ const tenantId = loginResponse.user?.tenantId || ''; const access_token = loginResponse.token; @@ -134,13 +128,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const team = teams.items[0]; if (!team) { - setNoTeamPopupShowCookie(true); - // No need to check now if user is in any Team or not, as we are allowing to login and then user can Join/Create new Team - // return res.status(400).json({ - // errors: { - // email: "We couldn't find any teams associated to this account", - // }, - // }); + setNoTeamPopupShowCookie(true); } setAuthCookies(