Skip to content

Commit

Permalink
Update login.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
evereq authored Dec 1, 2023
1 parent b068384 commit 0cb10b4
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions apps/web/pages/api/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -96,6 +89,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
});
}

loginResponse = acceptInviteRes.data;
}

Expand All @@ -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;
Expand All @@ -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(
Expand Down

0 comments on commit 0cb10b4

Please sign in to comment.