MCPcopy
hub / github.com/ever-co/ever-demand / UsersAuthService

Class UsersAuthService

packages/core/src/services/users/UsersAuthService.ts:32–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30@injectable()
31@routerName('user-auth')
32export class UsersAuthService extends EntityService<User>
33 implements IUserAuthRouter, IService {
34 readonly DBObject: any = User;
35
36 // TODO: why it's not in the settings and hardcoded to some default value here?
37 private static IS_INVITES_SYSTEM_ON: boolean = false;
38
39 protected readonly log: Logger = createEverLogger({
40 name: 'userAuthService',
41 });
42
43 private readonly authService: AuthService<User>;
44
45 constructor(
46 private readonly usersService: UsersService,
47 private readonly invitesService: InvitesService,
48 @inject('Factory<AuthService>')
49 private readonly authServiceFactory: AuthServiceFactory
50 ) {
51 super();
52
53 this.authService = this.authServiceFactory({
54 role: 'user',
55 Entity: User,
56 saltRounds: env.USER_PASSWORD_BCRYPT_SALT_ROUNDS,
57 });
58 }
59
60 /**
61 * Register Customer.
62 * Throw NotInvitedError if customer not invited and invites system enabled
63 *
64 *
65 * @param {IUserRegistrationInput} input
66 * @returns {Promise<User>}
67 * @memberof UsersAuthService
68 */
69 @asyncListener()
70 async register(input: IUserRegistrationInput): Promise<User> {
71 if (
72 UsersAuthService.IS_INVITES_SYSTEM_ON &&
73 !(await this._isInvited(input.user))
74 ) {
75 throw new NotInvitedError();
76 }
77
78 if (input.user.firstName === '') {
79 delete input.user.firstName;
80 }
81
82 if (input.user.lastName === '') {
83 delete input.user.lastName;
84 }
85
86 if (input.user.email === '') {
87 delete input.user.email;
88 }
89

Callers

nothing calls this directly

Calls 1

createEverLoggerFunction · 0.90

Tested by

no test coverage detected