passport-spotify
passport-spotify copied to clipboard
`VerifyFunction` parameters are passed in the wrong order
Hey everyone, I was trying to setup an express-api where users would always authorize and authenticate via spotify, for this I wanted to use passport-spotify
.
I'm also using typescript and a mongoDB. From the documentation, this was the setup to use the SpotifyStrategy
:
passport.use(
new SpotifyStrategy(
{
clientID: client_id,
clientSecret: client_secret,
callbackURL: 'http://localhost:8888/auth/spotify/callback',
},
function (accessToken, refreshToken, expires_in, profile, done) {
User.findOrCreate({spotifyId: profile.id}, function (err, user) {
return done(err, user);
});
}
)
);
Problem However, the arguments seem to be passed in in the wrong order, at least the typescript compiler will complain about it, i.e.

Therefore, it seems to be that the right order of function parameters for the VerifyFunction
should be as followed:
async(_req, accessToken, refreshToken, profile, done, expires_in) => {...}
However, when this is being done, I will get the following mongoose validation errors :
{ Error: User validation failed: spotifyId: Path `spotifyId` is required., userName: Path `userName` is required.
at ValidationError.inspect (/Users/nilssutter/Desktop/spotify_swipes/node_modules/mongoose/lib/error/validation.js:47:26)
at formatValue (internal/util/inspect.js:522:31)
at inspect (internal/util/inspect.js:197:10)
at formatWithOptions (internal/util/inspect.js:1390:12)
at Console.(anonymous function) (internal/console/constructor.js:277:10)
at Console.log (internal/console/constructor.js:287:61)
at Function.UserRepository.findAndUpdateOrCreate
The reason for this is that profile
is still undefined.
Workaround It might be that I'm messing something up, but my current workaround is smart-casting the parameter to the type they actually should have, i.e.:

So yeah, I'm a bit confused :D
This currently works well for me but I suppose the arguments for the VerifyFunction
should come in in another order in the first place?
I think the issue is that @types/passport-spotify specifies the wrong order for the arguments. I'm going to create an MR to add types to the library. That is the recommended approach for libraries these days.
Hey @alexstaroselsky . Thanks for pointing this out :)
I created a PR for @types/passport-spotify. Once that is approved/merged at least that issue for the verity function signature should be resolved. That being said, you still would likely need to use type casting or similar for passport.authenticate
as showDialog
(if you are using that) is not supported by AuthenticateOptions
I created a PR for @types/passport-spotify. Once that is approved/merged at least that issue for the verity function signature should be resolved. That being said, you still would likely need to use type casting or similar for
passport.authenticate
asshowDialog
(if you are using that) is not supported by AuthenticateOptions
Hi! Your PR didnt pass.