(req)
| 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) { |
no test coverage detected