PasswordAuthMethod: fix findUserByIdentifier()
This commit is contained in:
parent
b75b227ca1
commit
f8c4906a51
@ -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[]> {
|
||||
|
Loading…
Reference in New Issue
Block a user