-
-
Notifications
You must be signed in to change notification settings - Fork 372
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
Express quick start example fails due to incorrect whoami request port #767
Comments
also happy to contribute the fix!! |
that would be lovely, @Benehiko can you please assist? |
Strange, we have e2e tests for this which are green on master, so not sure how this is failing here. |
Are the e2e tests using the exact same instructions as the OP suggested? |
I believe so, since we check that the session exists afterwards containing the registered email here. I don't see how we would have a redirect loop then if we return to the application "dashboard" showing the session information. |
So do the docs or e2e tests need to be adjusted to follow the same commands? |
We should just update the documentation, it seems we don't give enough in the step by step process to build the example correctly. We should also indicate that the sdk will call whichever url the browser is currently requesting from, e.g. browser is on |
@ammanvedi could you please copy the code given on GitHub directly? Try reproduce the error and take note of the differences in code that you currently have vs the GitHub clone. I think the steps given in the guide isn't specific enough. |
@Benehiko sure i will try ! |
Sorry for the delay i will try this tonight |
Okay i have tried this and here are my steps
i then edit the proxy npm script so it contains the sdk url envar which is the same as it would be in the tests
then
then in my browser i visit http://localhost:4000/ and this works fine. i can sign up etc. However if i use my own sdk url
then it breaks; Screen.Recording.2022-04-26.at.18.59.06.movWHY?i think it has something to do with // code-examples/protect-page-login/expressjs/routes/index.js
baseUrl: '/.ory' this baseUrl property is not specified by the sdk config, the config actually accepts basePath. When basePath is not found the default becomes // code-examples/protect-page-login/expressjs/node_modules/@ory/client/base.ts
export const BASE_PATH = "https://playground.projects.oryapis.com".replace(/\/+$/, "");
this.basePath = configuration.basePath || this.basePath; i think this could be why the tests work because the base path that gets set is not a local path, its an absolute url, because it gets defaulted to that, and the SDK_URL in tests is playground also SOLUTIONthe solution could be to make the following change var ory = new sdk.V0alpha2Api(
new sdk.Configuration({
basePath: 'http://localhost:4000/.ory'
})
)
would probably need to match the ports in express app to the test setup so this url work in both places
was a bit of rabbit hole but would appreciate a sanity check on this |
Hi @ammanvedi Thank you for the detailed write-up. I will take a look today at it using the steps you provided |
It seems like the SDK is not getting the current origin the browser is on e.g. localhost:4000 and so it defaults to localhost:80 which obviously doesn't have anything hosted on it and thus the express middleware ends up in a redirect loop trying to go back to the login screen. Here is an example of the error that is caught just before redirecting to Error: connect ECONNREFUSED 127.0.0.1:80
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 80,
config: {
url: '/.ory/sessions/whoami', We need to update the example to something like the go example https://github.com/ory/docs/blob/master/code-examples/protect-page-login/go/main.go#L16-L24 |
Nice find, thank you @Benehiko ! Could you make those changes to the example? :) |
Yeah I'll work on that soon, could you assign me to the issue? |
Preflight checklist
Describe the bug
https://www.ory.sh/docs/guides/protect-page-login/expressjs#require-login-to-access-the-home-page
.toSession
seems to want to make a call to/.ory/.../whoami
through the proxy. However i think axios wants to make this call at localhost port 80, leading to the following errorSo we need to tell axios it should match the port we used when we started the proxy
"dev:proxy": "ory proxy --no-jwt --port 8000 http://localhost:8001/"
some solutions at the doc level
These both work and i am also wondering
https://github.com/ory/docs/blob/master/code-examples/protect-page-login/expressjs/routes/index.js
Reproducing the bug
Relevant log output
No response
Relevant configuration
No response
Version
"@ory/client": "^0.0.1-alpha.167"
On which operating system are you observing this issue?
macOS
In which environment are you deploying?
Ory Cloud
Additional Context
No response
The text was updated successfully, but these errors were encountered: