Skip to content

Commit

Permalink
remove unused login function, auth token change (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwn04 authored May 19, 2024
1 parent 6a1e1e7 commit 1ee1b5a
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions services/UserAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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';
import UserAccountService from './UserAccountService';

interface AuthToken {
uuid: Uuid;
admin: boolean;
accessType: UserAccessType;
}

@Service()
Expand Down Expand Up @@ -111,30 +111,6 @@ export default class UserAuthService {
return user;
}

public async login(email: string, pass: string): Promise<string> {
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<UserModel> {
const authenticatedUser = await this.transactions.readWrite(async (txn) => {
const user = await Repositories
Expand All @@ -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 });
}
Expand Down

0 comments on commit 1ee1b5a

Please sign in to comment.