This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Request, Response, NextFunction } from "express"; | |
| import { PassportStatic } from "passport"; | |
| export function checkRoleWithPassport(roles: string[], passport: PassportStatic, strategy: string, opts: any) { | |
| return function (req: Request, res: Response, next: NextFunction) { | |
| passport.authenticate(strategy, opts, function (err, user) { | |
| if (err) res.status(401).json({ message: "Unauthenticated" }); | |
| else if (!user) res.status(401).json({ message: "Unauthenticated" }); | |
| else { | |
| if (roles.length == 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import passport from "passport"; | |
| import passportLocal from "passport-local"; | |
| import passportJwt from "passport-jwt"; | |
| import { User } from "../models/User"; | |
| import { Request, Response, NextFunction } from "express"; | |
| import _ from "lodash"; | |
| import { KEY_SECRET } from "../util/secrets"; | |
| const LocalStrategy = passportLocal.Strategy; | |
| const JWTstrategy = passportJwt.Strategy; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * POST /signin | |
| * Sign in for Token | |
| */ | |
| export const signIn = async (req: Request, res: Response, next: NextFunction) => { | |
| const errors = validationResult(req); | |
| if (!errors.isEmpty()) { | |
| return res.status(422).json(errors.mapped()); | |
| } | |
| passport.authenticate("login", async (err, user, info) => { |