Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Express quick start example fails due to incorrect whoami request port

Aperta
#767 15 commenti 0 reazioni 1 assegnatario Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

bug
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 error

[0] Error: connect ECONNREFUSED ::1:80
[0]     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
[0]   errno: -61,
[0]   code: 'ECONNREFUSED',
[0]   syscall: 'connect',
[0]   address: '::1',
[0]   port: 80,
[0]   config: {
[0]     url: '/.ory/sessions/whoami',
[0]     method: 'get',
[0]     headers: {
[0]       Accept: 'application/json, text/plain, */*',
[0]       Cookie: '__cflb=0pg1QYeUHkKyPHC72r3PJ1fj2WK6WMwzqHhgHXum; csrf_token_a5d02dd42b4ef065bbbd5ed674b19b5d2e6dc4f2a3e4acc8684f15ae24c19b97=JGnPuz6b+Jqy10PCRqwvR2dgrw2UXJ1K96SHlDCWSag=; ory_session_greatgoldwasserlbe7q6kfiv=MTY1MDMwMTk3MnxnSmhfWkRBM2lSVkJwX1JpY0oyYUpGV21lbm9jel9PWkl0a2RwVzJ0eGRJT1lLSm9JMlZUUjZyc0xYalJyMS1naC0zS2FleWxaM0lsT0pxMjNSRkRGQVlTbjU2ZUtaYTAxVEQ4MWxoZUlfcFR6Rml3YkM4bE1XdmVQQms3SjhZR0NaQ2UwMklqcXc9PXygWBBkEKzVhZUiBc1uzDEO0KmKCRdEUET-qIkFgs5LkQ==',

So 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

  1. insist we pass a proxy to axios in development environments
.toSession(undefined, req.header('cookie'), {
    proxy: {
        host: 'localhost',
        port: 8000
    }
})
  1. in development make sure we pass the full base path inclusive of port
const ory = new orySDK.V0alpha2Api(
    new orySDK.Configuration(
        // @ts-ignore
        {basePath: 'http://localhost:8000/.ory',
            baseOptions: {
                withCredentials: true
            }
        }
    )
)

These both work and i am also wondering

  1. if there is a way to detect if we are proxying and on what port so this could be done automatically somehow
  2. perhaps having this as an envar like the sdk url

https://github.com/ory/docs/blob/master/code-examples/protect-page-login/expressjs/routes/index.js

Reproducing the bug
  1. follow example on https://www.ory.sh/docs/guides/protect-page-login/expressjs
  2. register a user
  3. observe redirect loop once user registered due to failing whoami request
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

Lingua principale
TypeScript
Stelle
161
Fork
1.9k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ory/docs

Tutte le issue di ory/docs

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.