PasswordAuthMethod: fix findUserByIdentifier()

This commit is contained in:
Alice Gaudon 2020-11-14 18:16:05 +01:00
parent b75b227ca1
commit f8c4906a51
1 changed files with 6 additions and 4 deletions

View File

@ -12,7 +12,6 @@ import Controller from "../../Controller";
import UserPasswordComponent from "./UserPasswordComponent";
import UserNameComponent, {USERNAME_REGEXP} from "../models/UserNameComponent";
import ModelFactory from "../../db/ModelFactory";
import {WhereOperator, WhereTest} from "../../db/ModelQuery";
import {ServerError} from "../../HttpError";
export default class PasswordAuthMethod implements AuthMethod<PasswordAuthProof> {
@ -30,12 +29,15 @@ export default class PasswordAuthMethod implements AuthMethod<PasswordAuthProof>
.with('user')
.where('email', identifier);
const user = (await query
.first())?.user.getOrFail();
if (user) return user;
if (ModelFactory.get(User).hasComponent(UserNameComponent)) {
query.where('name', identifier, WhereTest.EQ, WhereOperator.OR);
return await User.select().where('name', identifier).first();
}
return (await query
.first())?.user.getOrFail() || null;
return null;
}
public async getProofsForSession(session: Express.Session): Promise<PasswordAuthProof[]> {