Skip to content

Commit

Permalink
fix: more accurate error message for createResetPasswordToken (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
rombat committed Mar 11, 2024
1 parent 23f7759 commit ced07f6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion services/auth/lib/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,13 @@ const createResetPasswordToken = async (req, res) => {
}

if (!user.identities?.local?.id) {
return helpers.forbidden(res, new Error('user does not have a local identity provider'));
const availableProviders = req.authProviders;
const existingProvidersIdentities = Object.entries(user.identities || {})
.filter(([key, value]) => !!availableProviders[key] && !!value?.id)
.map(([key, value]) => key);
// user.identities can have keys not related to providers, like invitation keys, and thus can be not fully created. at this point we consider it as not found.
const errorMessage = existingProvidersIdentities.length ? 'user does not have a local identity provider' : 'User not found';
return helpers.forbidden(res, new Error(errorMessage));
}
const opts = req.authProvider.options;

Expand Down

0 comments on commit ced07f6

Please sign in to comment.