import bcrypt from 'bcrypt' ; import { UserEntity } from '../server/models/User/entities/User.entity' ; export default async function authenticate ( email , password ) { try { const user = await UserEntity . createQueryBuilder ( 'user' ) . where ( 'user.email = :email' , { email } ) . getOne ( ) ; if ( ! user ?. passwordEncrypted ) { throw new Error ( 'Invalid user.' ) ; } const matched = await bcrypt . compare ( password , user . passwordEncrypted ) ; if ( matched && user . isAdmin ) { return { ... user } ; } } catch ( e ) { } return false ; }