feat(server): remove phone number from authentication endpoints

This commit is contained in:
a.bouhuolia
2023-04-05 23:57:26 +02:00
parent 4a22576d88
commit 85b24c7a4f
9 changed files with 42 additions and 51 deletions

View File

@@ -1,27 +1,29 @@
import { Container, Service } from 'typedi';
import events from '@/subscribers/events';
import { IAuthSignedInEventPayload } from '@/interfaces';
@Service()
export default class ResetLoginThrottleSubscriber {
/**
* Attaches events with handlers.
* @param bus
* @param bus
*/
public attach(bus) {
bus.subscribe(events.auth.login, this.resetLoginThrottleOnceSuccessLogin);
bus.subscribe(events.auth.signIn, this.resetLoginThrottleOnceSuccessLogin);
}
/**
* Resets the login throttle once the login success.
* @param {IAuthSignedInEventPayload} payload -
*/
private async resetLoginThrottleOnceSuccessLogin(payload) {
const { emailOrPhone, password, user } = payload;
private async resetLoginThrottleOnceSuccessLogin(
payload: IAuthSignedInEventPayload
) {
const { email, user } = payload;
const loginThrottler = Container.get('rateLimiter.login');
// Reset the login throttle by the given email and phone number.
await loginThrottler.reset(user.email);
await loginThrottler.reset(user.phoneNumber);
await loginThrottler.reset(emailOrPhone);
await loginThrottler.reset(email);
}
}

View File

@@ -10,14 +10,14 @@ export default class AuthSendWelcomeMailSubscriber {
* Attaches events with handlers.
*/
public attach(bus) {
bus.subscribe(events.auth.register, this.sendWelcomeEmailOnceUserRegister);
bus.subscribe(events.auth.signUp, this.sendWelcomeEmailOnceUserRegister);
}
/**
* Sends welcome email once the user register.
*/
private sendWelcomeEmailOnceUserRegister = async (payload) => {
const { registerDTO, tenant, user } = payload;
const { tenant, user } = payload;
// Send welcome mail to the user.
await this.agenda.now('welcome-email', {

View File

@@ -3,13 +3,17 @@ export default {
* Authentication service.
*/
auth: {
login: 'onLogin',
logining: 'onLogining',
register: 'onRegister',
registering: 'onAuthRegistering',
sendResetPassword: 'onSendResetPassword',
signIn: 'onSignIn',
signingIn: 'onSigningIn',
signUp: 'onSignUp',
signingUp: 'onSigningUp',
sendingResetPassword: 'onSendingResetPassword',
sendResetPassword: 'onSendResetPassword',
resetPassword: 'onResetPassword',
resetingPassword: 'onResetingPassword'
},
/**