20 lines
430 B
TypeScript
20 lines
430 B
TypeScript
import passport from 'koa-passport';
|
|
import { Strategy } from 'passport-local';
|
|
|
|
import Auth from '../model/auth';
|
|
|
|
export const localStrategy = passport.use(
|
|
new Strategy(async (username, password, done) => {
|
|
const user = await Auth.findOne({
|
|
where: {
|
|
username,
|
|
}
|
|
}).catch();
|
|
if (user && user.authenticate(password)) {
|
|
done(null, user);
|
|
} else {
|
|
done(null, false);
|
|
}
|
|
})
|
|
);
|