0

我正在尝试使用护照在我的 NextJS 应用程序中对用户进行身份验证。不幸的是,当我在我的 api 路由上使用 passport.authenticate() 时,它不会重定向。

// /middleware/passport.js

import passport from "passport";
import { Strategy as DiscordStrategy } from "passport-discord";

passport.serializeUser((user, done) => {
  done(null, "theusersID");
});

passport.deserializeUser((id, done) => {
  done(null, id);
});

//

async function passportCallback(accessToken, refreshToken, profile, done) {
  console.log(profile);
  done(null, profile);
}

//

passport.use(
  new DiscordStrategy(
    {
      clientID: "875935703324848128",
      clientSecret: "raQw1qUp8lJ9uDeslTJxu2wQ2i62Jbhi",
      callbackURL: "/auth/landing",
      scope: ["email"],
    },
    passportCallback
  )
);

export default passport;

// /pages/api/hello.js
import nc from "next-connect";
import all from "@/middleware/all";
import passport from "@/middleware/passport";

const handler = nc();

handler.use(all);

handler.get(passport.authenticate("discord"));

export default handler;

我正在使用 passport-discord 通过 Discord 对用户进行身份验证。

4

0 回答 0