Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strategy.authenticate is not a function (passport-facebook) #1000

Open
GolgothaAksanti opened this issue Sep 1, 2023 · 0 comments
Open

strategy.authenticate is not a function (passport-facebook) #1000

GolgothaAksanti opened this issue Sep 1, 2023 · 0 comments

Comments

@GolgothaAksanti
Copy link

GolgothaAksanti commented Sep 1, 2023

I need help please

Am having issue while trying to implement passport-facebook

here are my code
const express = require("express");
const bodyParser = require("body-parser");
const http = require("http");
const cors = require("cors");
require("dotenv/config");
const session = require("express-session");
const passport = require("passport");
const FacebookStrategy = require("passport-facebook").Strategy;

const app = express();
app.use(bodyParser.json());
const server = http.createServer(app);

passport.use(
  session({
    secret: "golgotha", // Change this to a secure secret
    resave: false,
    saveUninitialized: true,
    cookie: { maxAge: 60 * 60 * 1000 }, // 1 hour
  })
);
const appSecret = "b092af40cc815beccec4bc425e837611";
const appId = "204360395983397";

app.use(passport.initialize());
app.use(passport.session());

passport.use(
  new FacebookStrategy(
    {
      clientID: appId,
      clentSecret: appSecret,
      callbackURL:
        "https://d1f1-102-220-95-109.ngrok-free.app/api/facebook/callback",
    },
    (accessToken, refreshToken, profile, done) => {
      return done(null, profile);
    }
  )
);

passport.serializeUser((user, done) => {
  console.log(`serialize`, user);
  done(null, user);
});

passport.deserializeUser((user, done) => {
  console.log(`deserialize`, user);
  done(null, user);
});

app.get("/auth/facebook", (req, res, next) => {
  passport.authenticate("facebook", { scope: ["profile", "email"] })(
    req,
    res,
    next
  );
});

app.get(
  "/api/facebook/callback",
  passport.authenticate("facebook", {
    successRedirect: "/",
    failureRedirect: "/",
  })
);

const PORT = 3001;
server.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
and error is displaying in the browser

TypeError: strategy.authenticate is not a function at attempt (/home/golgotha/Documents/workspace/test/socket.io/node_modules/passport/lib/middleware/authenticate.js:369:16) at authenticate (/home/golgotha/Documents/workspace/test/socket.io/node_modules/passport/lib/middleware/authenticate.js:370:7) at Layer.handle [as handle_request] (/home/golgotha/Documents/workspace/test/socket.io/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/golgotha/Documents/workspace/test/socket.io/node_modules/express/lib/router/index.js:328:13) at /home/golgotha/Documents/workspace/test/socket.io/node_modules/express/lib/router/index.js:286:9 at Function.process_params (/home/golgotha/Documents/workspace/test/socket.io/node_modules/express/lib/router/index.js:346:12) at next (/home/golgotha/Documents/workspace/test/socket.io/node_modules/express/lib/router/index.js:280:10) at initialize (/home/golgotha/Documents/workspace/test/socket.io/node_modules/passport/lib/middleware/initialize.js:98:5) at Layer.handle [as handle_request] (/home/golgotha/Documents/workspace/test/socket.io/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/golgotha/Documents/workspace/test/socket.io/node_modules/express/lib/router/index.js:328:13)

  • Operating System: Ubuntu 22.04.3 LTS
  • Node version: v18.17.1
  • passport version: "passport": "^0.6.0"
@GolgothaAksanti GolgothaAksanti changed the title strategy.authenticate is not a function (passport-google-oauth20) strategy.authenticate is not a function (passport-facebook) Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant