Add HOST_LINK environment variable and update related configurations. Normalize email addresses to lowercase in login and registration handlers. Enhance email notifications for approved and rejected applications with HOST_LINK.
This commit is contained in:
@@ -15,7 +15,7 @@ export const handler = safeHandler(async (
|
||||
): Promise<APIGatewayProxyResult> => {
|
||||
// Parse request body
|
||||
let body: { emailAddress?: string; userPassword?: string };
|
||||
|
||||
|
||||
try {
|
||||
body = event.body ? JSON.parse(event.body) : {};
|
||||
} catch (error) {
|
||||
@@ -28,7 +28,9 @@ export const handler = safeHandler(async (
|
||||
throw new ApiError(400, 'Email and password are required');
|
||||
}
|
||||
|
||||
const loginForHost = await hostService.loginForHost(emailAddress, userPassword);
|
||||
const emailToLowerCase = emailAddress.toLowerCase()
|
||||
|
||||
const loginForHost = await hostService.loginForHost(emailToLowerCase, userPassword);
|
||||
|
||||
if (!loginForHost) {
|
||||
throw new ApiError(400, 'Failed to login');
|
||||
@@ -40,7 +42,7 @@ export const handler = safeHandler(async (
|
||||
|
||||
const generateTokenForHost = await tokenService.generateAuthToken(
|
||||
loginForHost.id
|
||||
);
|
||||
);
|
||||
|
||||
if (!generateTokenForHost) {
|
||||
throw new ApiError(500, 'Failed to generate token');
|
||||
|
||||
@@ -7,6 +7,7 @@ import ApiError from '../../../../../common/utils/helper/ApiError';
|
||||
import { encryptUserId } from '../../../../../common/utils/helper/CodeGenerator';
|
||||
import { OtpGeneratorSixDigit } from '../../../../../common/utils/helper/OtpGenerator';
|
||||
import { HostService } from '../../../services/host.service';
|
||||
import { sendOtpEmailForHost } from '@/modules/host/services/sendOTPEmail.service';
|
||||
|
||||
const hostService = new HostService(prismaClient);
|
||||
|
||||
@@ -44,10 +45,12 @@ export const handler = safeHandler(async (
|
||||
throw new ApiError(400, 'Email is required');
|
||||
}
|
||||
|
||||
const emailToLowerCase = email.toLowerCase()
|
||||
|
||||
// Use a single transaction for user creation/lookup and OTP storage
|
||||
const transactionResult = await prismaClient.$transaction(async (tx) => {
|
||||
const user = await tx.user.findUnique({
|
||||
where: { emailAddress: email },
|
||||
where: { emailAddress: emailToLowerCase },
|
||||
select: { emailAddress: true, id: true, userPassword: true },
|
||||
});
|
||||
|
||||
@@ -65,7 +68,7 @@ export const handler = safeHandler(async (
|
||||
} else {
|
||||
// create new user record within the transaction
|
||||
newUserLocal = await tx.user.create({
|
||||
data: { emailAddress: email, roleXid: ROLE.HOST, userRefNumber: referenceNumber },
|
||||
data: { emailAddress: emailToLowerCase, roleXid: ROLE.HOST, userRefNumber: referenceNumber },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -100,7 +103,7 @@ export const handler = safeHandler(async (
|
||||
}
|
||||
|
||||
// Send OTP email outside the DB transaction
|
||||
// await sendOtpEmailForHost(transactionResult.newUser.emailAddress, transactionResult.otp);
|
||||
await sendOtpEmailForHost(transactionResult.newUser.emailAddress, transactionResult.otp);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
|
||||
Reference in New Issue
Block a user