-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.ts
30 lines (24 loc) · 940 Bytes
/
login.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Request, Response } from 'express';
function login(req: Request, res: Response, options: any) {
let {auth, passport} = options;
passport.authenticate('local', (err?: any, user?: any) => {
if(err) {
res.render(auth.options.loginFile, {options: auth.options, errorMessage: 'Internal error.'});
console.error(err);
return;
}
if(!user) {
res.render(auth.options.loginFile, {options: auth.options, errorMessage: 'Invalid email or password.'});
return;
}
req.logIn(user, (err: any) => {
if (err) {
res.render(auth.options.loginFile, {options: auth.options, errorMessage: 'Internal error.'});
console.error(err);
return;
}
res.redirect(auth.options.authRedirect);
});
})(req, res, options.next);
}
export { login };