Skip to content

Commit

Permalink
fix: failure redirect not working properly (#103)
Browse files Browse the repository at this point in the history
* fix: failure redirect not working properly

* handle failure redirect not set
  • Loading branch information
adrien2p authored Oct 24, 2023
1 parent e043edd commit 5a10308
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/medusa-plugin-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medusa-plugin-auth",
"version": "1.5.1",
"version": "1.6.0",
"description": "Social authentication plugin for medusajs",
"keywords": [
"social",
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa-plugin-auth/src/core/passport/Strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function PassportStrategy<T extends Type<any> = any>(
const validateResult = await this.validate(...params);
done(null, validateResult);
} catch (err) {
done(err, null);
done(null, null, { msg: err.message });
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,27 @@ export function passportAuthRoutesBuilder({

next();
},
passport.authenticate(strategyName, {
...passportCallbackAuthenticateMiddlewareOptions,
session: false,
}),
callbackHandler
function (req, res, next) {
passport.authenticate(
strategyName,
Object.assign({}, passportCallbackAuthenticateMiddlewareOptions, {
session: false,
failureRedirect: false,
}),
(err, user, options) => {
if (options?.msg) {
if (passportCallbackAuthenticateMiddlewareOptions?.failureRedirect) {
return res.redirect(
passportCallbackAuthenticateMiddlewareOptions.failureRedirect + '?message=' + options.msg
);
} else {
return res.status(401).json({ message: options.msg });
}
}
return callbackHandler(req, res);
}
)(req, res, next);
}
);

return router;
Expand Down

1 comment on commit 5a10308

@vercel
Copy link

@vercel vercel bot commented on 5a10308 Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

medusa-plugins – ./

medusa-plugins-adrien2p.vercel.app
medusa-plugins-git-main-adrien2p.vercel.app
medusa-plugins.vercel.app

Please sign in to comment.