【问题标题】:express TSOA + passportexpress TSOA + passport
【发布时间】:2022-12-01 20:18:56
【问题描述】:
I'm trying to migrate a custom based controller API based on express to TSOA framework.
I was usingpassportto handle authentication before.
How can I use it with TSOA? It seems to be ignored.
【问题讨论】:
标签:
express
passport.js
tsoa
【解决方案1】:
I think that you need just to add app.use(passport.authenticate('jwt')); above RegisterRoutes(app); in your (propbaly) server.ts file.
Like this:
// ...
// passport.use('jwt',new JWTStrategy({<your_data_here>}));
// passport.initialize();
app.use(passport.authenticate('jwt'));
RegisterRoutes(app);
// ...
// const httpServer = createServer(app);
// httpServer.listen(82811, () => {
// console.log(`Server is running at http://localhost:82811`);
// });