19 lines
496 B
TypeScript
19 lines
496 B
TypeScript
import passport from 'koa-passport';
|
|
// eslint-disable-next-line import/named
|
|
import { Strategy as LocalStrategy } from 'passport-local';
|
|
|
|
import Auth from '../../model/auth';
|
|
|
|
export default new LocalStrategy(async (username: string, password: string, done: any) => {
|
|
const user = await Auth.findOne({
|
|
where: {
|
|
username,
|
|
},
|
|
}).catch();
|
|
if (user && user.authenticate(password)) {
|
|
done(null, user);
|
|
} else {
|
|
done(null, false);
|
|
}
|
|
});
|