MCPcopy
hub / github.com/parse-community/parse-server / handleChallenge

Method handleChallenge

src/Routers/UsersRouter.js:675–803  ·  view source on GitHub ↗
(req)

Source from the content-addressed store, hash-verified

673 }
674
675 async handleChallenge(req) {
676 const { username, email, password, authData, challengeData } = req.body || {};
677
678 // if username or email provided with password try to authenticate the user by username
679 let user;
680 if (username || email) {
681 if (!password) {
682 throw new Parse.Error(
683 Parse.Error.OTHER_CAUSE,
684 'You provided username or email, you need to also provide password.'
685 );
686 }
687 user = await this._authenticateUserFromRequest(req);
688 }
689
690 if (!challengeData) {
691 throw new Parse.Error(Parse.Error.OTHER_CAUSE, 'Nothing to challenge.');
692 }
693
694 if (typeof challengeData !== 'object') {
695 throw new Parse.Error(Parse.Error.OTHER_CAUSE, 'challengeData should be an object.');
696 }
697
698 let request;
699 let parseUser;
700
701 // Try to find user by authData
702 if (authData) {
703 if (typeof authData !== 'object') {
704 throw new Parse.Error(Parse.Error.OTHER_CAUSE, 'authData should be an object.');
705 }
706 if (user) {
707 throw new Parse.Error(
708 Parse.Error.OTHER_CAUSE,
709 'You cannot provide username/email and authData, only use one identification method.'
710 );
711 }
712
713 for (const key of Object.keys(authData)) {
714 if (authData[key] !== null && (typeof authData[key] !== 'object' || Array.isArray(authData[key]))) {
715 throw new Parse.Error(
716 Parse.Error.OTHER_CAUSE,
717 `authData.${key} should be an object.`
718 );
719 }
720 }
721
722 if (Object.keys(authData).filter(key => authData[key] && authData[key].id).length > 1) {
723 throw new Parse.Error(
724 Parse.Error.OTHER_CAUSE,
725 'You cannot provide more than one authData provider with an id.'
726 );
727 }
728
729 const results = await Auth.findUsersWithAuthData(req.config, authData);
730
731 try {
732 if (!results[0] || results.length > 1) {

Callers 2

mountRoutesMethod · 0.95
loadFunction · 0.80

Calls 7

getRequestObjectFunction · 0.90
resolveErrorFunction · 0.90
validatorFunction · 0.85
filterMethod · 0.80
errorMethod · 0.80
findMethod · 0.65

Tested by

no test coverage detected