refactor(core): Decouple LDAP from internal hooks (no-changelog) (#10157)

Co-authored-by: Ricardo Espinoza <ricardo@n8n.io>
This commit is contained in:
Iván Ovejero
2024-07-24 09:49:06 +02:00
committed by GitHub
parent 30784fb76c
commit dea212659a
6 changed files with 105 additions and 49 deletions

View File

@@ -1,10 +1,10 @@
import type { User } from '@db/entities/User';
import { PasswordUtility } from '@/services/password.utility';
import { Container } from 'typedi';
import { InternalHooks } from '@/InternalHooks';
import { isLdapLoginEnabled } from '@/Ldap/helpers.ee';
import { UserRepository } from '@db/repositories/user.repository';
import { AuthError } from '@/errors/response-errors/auth.error';
import { EventService } from '@/eventbus/event.service';
export const handleEmailLogin = async (
email: string,
@@ -23,9 +23,7 @@ export const handleEmailLogin = async (
// so suggest to reset the password to gain access to the instance.
const ldapIdentity = user?.authIdentities?.find((i) => i.providerType === 'ldap');
if (user && ldapIdentity && !isLdapLoginEnabled()) {
void Container.get(InternalHooks).userLoginFailedDueToLdapDisabled({
user_id: user.id,
});
Container.get(EventService).emit('login-failed-due-to-ldap-disabled', { userId: user.id });
throw new AuthError('Reset your password to gain access to the instance.');
}