'how to use passport in express(typescript)?
i have router and in this i call my passport
route.get(
"/signup",
passport.authenticate("signup", { session: false }),
(req: Request, res: Response) => {
console.log(req);
console.log("signup in admin routes");
res.send("admin routes");
}
);
and i call my passport in there file like this
const local = () => {
passport.use(
"signup",
new LocalStrategy(
{ usernameField: "username", passwordField: "password" },
async (username, password, done) => {
const result = await User.create({ username, password });
console.log(result);
return done(null, result);
}
)
);
};
export default local;
and when i call my router (postman) i have an error
Error: Unknown authentication strategy "signup"
at attempt (/run/media/afshin/New
Volume/final_kian_sarma/node_modules/passport/lib/middleware/authenticate.js:193:39)
at authenticate (/run/media/afshin/New
Volume/final_kian_sarma/node_modules/passport/lib/middleware/authenticate.js:370:7)
at Layer.handle [as handle_request] (/run/media/afshin/New
Volume/final_kian_sarma/node_modules/express/lib/router/layer.js:95:5)
at next (/run/media/afshin/New
Volume/final_kian_sarma/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/run/media/afshin/New Volume/final_kian_sarma/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/run/media/afshin/New Volume/final_kian_sarma/node_modules/express/lib/router/layer.js:95:5)
at /run/media/afshin/New Volume/final_kian_sarma/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/run/media/afshin/New Volume/final_kian_sarma/node_modules/express/lib/router/index.js:335:12)
at next (/run/media/afshin/New Volume/final_kian_sarma/node_modules/express/lib/router/index.js:275:10)
at Function.handle (/run/media/afshin/New Volume/final_kian_sarma/node_modules/express/lib/router/index.js:174:3)
please help what am i doning Tnks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
