From 1ee1b5a267d342eedeb5f11436404ab62f3f6064 Mon Sep 17 00:00:00 2001 From: Max Weng <73797155+maxwn04@users.noreply.github.com> Date: Sat, 18 May 2024 22:34:46 -0700 Subject: [PATCH] remove unused login function, auth token change (#398) --- services/UserAuthService.ts | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/services/UserAuthService.ts b/services/UserAuthService.ts index 0565fa73b..895954311 100644 --- a/services/UserAuthService.ts +++ b/services/UserAuthService.ts @@ -6,7 +6,7 @@ import { InjectManager } from 'typeorm-typedi-extensions'; import { EntityManager } from 'typeorm'; import { ExpressCheckinModel } from 'models/ExpressCheckinModel'; import { UserRepository } from '../repositories/UserRepository'; -import { Uuid, ActivityType, UserState, UserRegistration } from '../types'; +import { Uuid, ActivityType, UserState, UserRegistration, UserAccessType } from '../types'; import { Config } from '../config'; import { UserModel } from '../models/UserModel'; import Repositories, { TransactionsManager } from '../repositories'; @@ -14,7 +14,7 @@ import UserAccountService from './UserAccountService'; interface AuthToken { uuid: Uuid; - admin: boolean; + accessType: UserAccessType; } @Service() @@ -111,30 +111,6 @@ export default class UserAuthService { return user; } - public async login(email: string, pass: string): Promise { - const authenticatedUser = await this.transactions.readWrite(async (txn) => { - let user = await Repositories - .user(txn) - .findByEmail(email.toLowerCase()); - if (!user) throw new NotFoundError('There is no account associated with that email'); - if (user.isBlocked()) throw new ForbiddenError('Your account has been blocked'); - if (!(await user.verifyPass(pass))) throw new ForbiddenError('Incorrect password'); - await Repositories.activity(txn).logActivity({ - user, - type: ActivityType.ACCOUNT_LOGIN, - }); - if (user.state === UserState.PASSWORD_RESET) { - user = await Repositories.user(txn).upsertUser(user, { state: UserState.ACTIVE }); - } - return user; - }); - const token: AuthToken = { - uuid: authenticatedUser.uuid, - admin: authenticatedUser.isAdmin(), - }; - return jwt.sign(token, Config.auth.secret, { expiresIn: Config.auth.tokenLifespan }); - } - public async checkCredentials(email: string, pass: string): Promise { const authenticatedUser = await this.transactions.readWrite(async (txn) => { const user = await Repositories @@ -156,7 +132,7 @@ export default class UserAuthService { public static generateAuthToken(user: UserModel): string { const token: AuthToken = { uuid: user.uuid, - admin: user.isAdmin(), + accessType: user.accessType, }; return jwt.sign(token, Config.auth.secret, { expiresIn: Config.auth.tokenLifespan }); }