-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Authentication throws are treated as valid reply() #1581
Comments
Everything looks okay, although it's worth noting that passing two callbacks to |
Can you tell which |
Thanks for the replies! As far as I can tell, none of the It does not even look like the method that's supposed to resolve a promise is being called. I modified my code for simplicity:
and
|
Did you put a console.log before the testPromise code? Also, the error in your initial issue means that some reply is being called, or the route would just hang. You need to figure out which one is returning. Also, can you post the route config for one route you are trying to authenticate with this? |
A console.log before the testPromise code prints.
This is an example of a route config:
and the handler code:
You're right, the route just hangs if I don't make any function calls in the authenticate function:
If we call just any random function, we immediately get the error:
|
So your first example says |
@bendrucker Exactly, I must be doing something really wrong. For example,
Full stack trace:
|
Are you sure you have your |
@bendrucker Can you please elaborate on what you mean? Anyway, if you look at my later code snippets, I stopped using |
Actually there's no bind property globally available for the server. So never mind that. I'm assuming your dummy code is as-written and you're calling non-existent functions and triggering ReferenceErrors. Yes? |
Nope, I fleshed out dummy functions as well.
|
Your var authenticate = Authentication.authenticate;
authenticate(); // => TypeError undefined has no method 'testPromise' This may seem contrived but with a framework it's hard to know how your methods will be called. You should assume that the context will be lost unless the docs specify otherwise. Take a look at where your strategy will actually be called. |
Although this does unearth a separate issue, which is that authentication functions swallow exceptions |
@bendrucker Thanks for your help! I fixed my code by using closures to retain the reference to 'this':
|
@bendrucker nice catch. The issue is that when the function throws, it is treated as a valid reply call. |
I upgraded to hapi v4.0 from v1.2 and had to make some changes to my authentication strategy due to breaking changes introduced in 2.x.
I believe that because my authenticate() function contains a promise, it finishes executing before the promise is resolved and results in the following error:
This is my authenticate() function:
And wiring it up:
Everything was working fine in v1.2. Can someone please tell me what I'm doing wrong?
Thanks,
Shaun
The text was updated successfully, but these errors were encountered: