-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
throw Parse.Error in Custom Authentication Module doesn't get treated as Parse.Error #6467
Comments
Can you share the code (or at least a piece) of your custom adapter throwing the error? |
actually the code are already in the npm package. but if you need let me share you here the simplified version:
The error occurs only when i make my module as an npm package. if you straight away put it inside the Parse-Server/src/Adapters/Auth/, it will work as expected. But since Custom Authentication is allowed here I think there should be some problem here that doesn't accept the Parse.Error i throw as an Error object. Extra Explanation: When i try to throw the ParseError in the script here, it still shows that it is an instance of Parse.Error. But once it went to middlewares.js handleParseErrors function, it treat it as undefined situation and become uncaught server error. |
Here i also attach a trace indicates the path from where until the middlewares.js handleParseErrors function, hope it helps:
|
try with the following and let me know: let error = {
code: Parse.Error.OBJECT_NOT_FOUND,
message: 'Google auth is invalid for this user.'
}; |
Hi @davimacedo The code doesn't work for me. Currently what i temporary do is to modify the function handleParseErrors in middlewares.js to check not only ParseError but also if the err thrown has the structure of code & message. I'm not sure if this is proper or not. But the weird thing is some parts in the parse-server change the error i throw from ParseError to unknown object type with the structure totally same as ParseError. This is something that I feel like might need investigation? |
Error handling is weird. There is a PR open for this issue. I think it would fix it. If not can you open a PR? |
I thunk it happens probably because your adapter is using parse-server in its dependencies but with a version different from the one you are using in your main project, causing npm to duplicate parse-server so your have two versions of Parse.Error. In your adapter project's package.json, try to move parse-server from dependencies to peerDependencies. You can learn more about this problem here: https://lexi-lambda.github.io/blog/2016/08/24/understanding-the-npm-dependency-model/ |
Hi @davimacedo , Hereby i attached my package.json. I did try to use the peerDependencies but it doesn't seems help.
|
Can you also share the package.json of your main project? |
@davimacedo , sure. Here is my main project package.json
|
I have the exact same issue. Trying to create a custom auth module. Can't respond properly to invalid authentication attempts. |
@appxplore-tech Did you find a way to resolve this? |
@Dealerpriest could you share your adapter code and the error that you have? |
I eventually got it to work now. My solution was to not add any dependency from parse in my custom auth adapters package.json. Instead rely on parse being available for it when injected into the parse config. So the top of my custom auth code currently looks like this: // DON'T ADD THIS DEPENDENCY TO PACKAGE.JSON. IT WILL BE AVAILABLE WHEN THIS FILE IS INJECTED IN THE PARSE CONFIG
const Parse = require('parse/node').Parse;
const {verify, decode} = require('jsonwebtoken');
const getPem = require('rsa-pem-from-mod-exp');
const axios = require('axios').default; and my package.json looks like this:
Note that there is no dependency of parse or parse-server in the package.json |
Yes. I think that's the right way to do. Add parse only as a peerDependency but not as a dependency nor a devDependency. I'm closing this issue. |
Issue Description
I write my own custom Authentication Module due to some features that are not available here and I did throw some Parse.Error in the custom Authentication Module and I expect that I did receive the ParseError in my client instead of Internal server error code.
Steps to reproduce
"google":{module:"parse-server-auth-google"}
url: https://<>/parse/users
method: POST
Body: {"authData":{"google":{"id":"111"}}}
Headers: (Normal Headers as usual to call parse-server, for eg. X-Parse-Application-Id, Content-Type)
Expected Results
Receive a response with HTTP-Status: 404 with Body as below:
Actual Outcome
Receive a response with HTTP-Status: 500 with Body as below:
Environment Setup
Server
Database
Logs/Trace
Below are the logs that shown in my pm2. I found that during my own module file, the error i throw is still a Parse.Error type, but when it comes to middlewares.js, the function handleParseErrors will not treated it as a Parse.Error type.
Please let me know if I'm doing it wrong. thank you.
The text was updated successfully, but these errors were encountered: