[CLI] immich login-key is a little fussy when it comes to the instanceUrl provided #2012

Closed
opened 2026-02-05 04:44:13 +03:00 by OVERLORD · 0 comments
Owner

Originally created by @Georift on GitHub (Jan 19, 2024).

The bug

One issue for a couple of problems I've noticed with the login-key command of the CLI.

  1. Providing a link to the root immich instance (eg. https://demo.immich.app/) doesn't fail:
root@5bc318f4d2ab:/work# immich login-key https://demo.immich.app/                        
Executing API key auth flow...
Logged in as undefined
Wrote auth info to /root/.config/immich/auth.yml

Despite not providing an API key it believe it's authenticated correctly as undefined. This is probably because it's getting a 200 OK from the login page.

Perhaps a suggestion to append /api could be useful if we get a response of Content-Type: text/html.

  1. Providing an instanceUrl with a trailing slash causes things to break
root@5bc318f4d2ab:/work# immich login-key https://demo.immich.app/api/ 123                                      
Executing API key auth flow...
/usr/local/lib/node_modules/@immich/cli/dist/src/services/session.service.js:44
            throw new login_error_1.LoginError(`Failed to connect to server ${instanceUrl}: ${error.message}`);
                  ^

LoginError: Failed to connect to server https://demo.immich.app/api/: Request failed with status code 404
    at /usr/local/lib/node_modules/@immich/cli/dist/src/services/session.service.js:44:19
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SessionService.keyLogin (/usr/local/lib/node_modules/@immich/cli/dist/src/services/session.service.js:43:36)
    at async LoginKey.run (/usr/local/lib/node_modules/@immich/cli/dist/src/commands/login/key.js:7:9)
    at async Command.<anonymous> (/usr/local/lib/node_modules/@immich/cli/dist/src/index.js:57:5)

Node.js v21.6.0

Perhaps we could make a nicer error here (as described in #5357) and allow for a trailing slash (or not) to be provided and handle it gracefully?

The OS that Immich Server is running on

Debian 11

Version of Immich Server

1.92.0

Version of Immich Mobile App

N/A

Platform with the issue

  • Server
  • Web
  • Mobile

Your docker-compose.yml content

Not relevant

Your .env content

Not relevant

Reproduction steps

Described above

Additional information

No response

Originally created by @Georift on GitHub (Jan 19, 2024). ### The bug One issue for a couple of problems I've noticed with the `login-key` command of the CLI. 1. Providing a link to the root immich instance (eg. `https://demo.immich.app/`) doesn't fail: ```console root@5bc318f4d2ab:/work# immich login-key https://demo.immich.app/ Executing API key auth flow... Logged in as undefined Wrote auth info to /root/.config/immich/auth.yml ``` Despite not providing an API key it believe it's authenticated correctly as `undefined`. This is probably because it's getting a 200 OK from the login page. Perhaps a suggestion to append `/api` could be useful if we get a response of `Content-Type: text/html`. 2. Providing an instanceUrl with a trailing slash causes things to break ```console root@5bc318f4d2ab:/work# immich login-key https://demo.immich.app/api/ 123 Executing API key auth flow... /usr/local/lib/node_modules/@immich/cli/dist/src/services/session.service.js:44 throw new login_error_1.LoginError(`Failed to connect to server ${instanceUrl}: ${error.message}`); ^ LoginError: Failed to connect to server https://demo.immich.app/api/: Request failed with status code 404 at /usr/local/lib/node_modules/@immich/cli/dist/src/services/session.service.js:44:19 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async SessionService.keyLogin (/usr/local/lib/node_modules/@immich/cli/dist/src/services/session.service.js:43:36) at async LoginKey.run (/usr/local/lib/node_modules/@immich/cli/dist/src/commands/login/key.js:7:9) at async Command.<anonymous> (/usr/local/lib/node_modules/@immich/cli/dist/src/index.js:57:5) Node.js v21.6.0 ``` Perhaps we could make a nicer error here (as described in #5357) and allow for a trailing slash (or not) to be provided and handle it gracefully? ### The OS that Immich Server is running on Debian 11 ### Version of Immich Server 1.92.0 ### Version of Immich Mobile App N/A ### Platform with the issue - [ ] Server - [ ] Web - [ ] Mobile ### Your docker-compose.yml content ```YAML Not relevant ``` ### Your .env content ```Shell Not relevant ``` ### Reproduction steps ```bash Described above ``` ### Additional information _No response_
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#2012