Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions controllers/UserController/messaging.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable camelcase */
import { IUser } from '../../@types';
import axios from 'axios';
import { ServerError } from "../../middlewares/error";
// const { EMAIL_SERVICE_URL, AUTH_FRONTEND_URL } = process.env;
const {
AUTH_FRONTEND_URL,
Expand Down Expand Up @@ -32,6 +33,21 @@ export const sendSignUpNotification = async (user: IUser, token: string) => {
return 'Failed to send verification email';
}
};
export const resendSignupNotification = async (user: IUser, token: string) => {
// const verificationLink = ${AUTH_FRONTEND_URL}/auth/verification-complete?token=${token};
const verificationLink = `${VERIFY_EMAIL_ENDPOINT_LIVE}?token=${token}`;
const jsonData = {
recipient: user.email,
name: user.firstName,
verification_link: verificationLink,
};
try {
await axios.post(EMAIL_SERVICE_VERIFY_EMAIL_URL, jsonData);
return 'Verification email sent successfully.';
} catch (error) {
throw new ServerError('Failed to send verification email');
}
};
/**
*
* @param recipient
Expand All @@ -48,9 +64,9 @@ export const resetPasswordNotification = async (user: IUser, token: string) => {
};
try {
await axios.post(EMAIL_SERVICE_PASSWORD_RESET_URL, jsonData);
return 'Verification email sent successfully.';
return 'Password reset email sent successfully.';
} catch (error) {
return 'Failed to send verification email';
throw new ServerError('Failed to send reset password email');
}
};
/**
Expand All @@ -69,7 +85,7 @@ export const twoFactorAuthNotification = async (user: IUser, code: string) => {
await axios.post(EMAIL_SERVICE_2FA_URL, jsonData);
return '2FA code email sent successfully.';
} catch (error) {
return 'Failed to send 2FA code email';
throw new ServerError('Failed to send 2FA code email');
}
};
/**
Expand All @@ -88,6 +104,6 @@ export const welcomeEmailNotification = async (user: IUser) => {
await axios.post(EMAIL_SERVICE_WELCOME_URL, jsonData);
return 'Welcome email sent successfully.';
} catch (error) {
return 'Failed to send welcome email';
throw new ServerError('Failed to send welcome email');
}
};
3 changes: 2 additions & 1 deletion services/UserService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
resetPasswordNotification,
sendSignUpNotification,
twoFactorAuthNotification,
resendSignupNotification,
welcomeEmailNotification,
} from '../../controllers/UserController/messaging';
import {
Expand Down Expand Up @@ -532,7 +533,7 @@ class UserService implements IUserService {

const token = generateToken(user);

const response = await sendSignUpNotification(user, token);
const response = await resendSignupNotification(user, token);
return response;
} catch (error) {
throw new HttpError(error.status || 500, error.message);
Expand Down