Breaking down mega-package. Hello auth-db 1.0.0!
This commit is contained in:
17
lib/api/authenticate.ts
Normal file
17
lib/api/authenticate.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Auth, Log } from '..';
|
||||
import { Action } from '../../constants/action';
|
||||
import { getLoginToken } from '../utils/getLoginToken';
|
||||
|
||||
export const authenticate = async (username: string, password: string) => {
|
||||
const doc = await Auth.findByUsername(username).catch();
|
||||
if (!!doc && (await doc.authenticate(password))) {
|
||||
Log.add(doc.id, Action.AUTHENTICATE);
|
||||
return { ...doc, token: getLoginToken(doc) };
|
||||
}
|
||||
|
||||
if (doc) {
|
||||
Log.add(doc.id, Action.AUTHENTICATE_FAILURE);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
Reference in New Issue
Block a user