类型错误:passport.SpotifyStrategy 不是构造函数

时间:2021-07-12 15:20:05

标签: node.js

请帮助我如何导入 Spotify 通行证策略? // //导入:

import * as passport from "passport-spotify";

//函数:

passport.use(
  new passport.SpotifyStrategy(
    {
      cliendID: process.env.CLIENT_ID,
      clientSecret: process.env.CLIENT_SECRET,
      callbackURL: process.env.REDIRECT_URI,
    },
    function (accessToken, refreshToken, expires_in, profile, done) {
      UserModel.findOrCreate({ spotifyId: profile.id }, function (err, user) {
        return done(err, user);
      });
    }
  )
);

The error..

1 个答案:

答案 0 :(得分:1)

根据 doc 页面的语法是这样的:

const SpotifyStrategy = require('passport-spotify').Strategy;

new SpotifyStrategy( ... );

所以如果你想使用它,你不能使用 passport.SpotifyStrategy 你应该使用 passport.Strategy

更清洁将使用:

import { Strategy as SpotifyStrategy } from 'passport-spotify'

然后

new SpotifyStrategy( ... );