instantdb / instant

The realtime client-side database
https://instantdb.com
Apache License 2.0
5.84k stars 136 forks source link

npx instant-cli login fails #167

Closed G2Jose closed 2 hours ago

G2Jose commented 1 week ago

I can't seem to login via instant-cli using the command yarn instant-cli login (also tried the same with npx).

Here's the error I'm seeing:

❯ yarn instant-cli login
node:internal/deps/undici/undici:13185
      Error.captureStackTrace(err);
            ^

TypeError: fetch failed
    at node:internal/deps/undici/undici:13185:13
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async fetchJson (file:///.../node_modules/instant-cli/index.js:498:15)
    at async Command.login (file:///.../node_modules/instant-cli/index.js:110:23) {
  [cause]: AggregateError [ECONNREFUSED]: 
      at internalConnectMultiple (node:net:1117:18)
      at afterConnectMultiple (node:net:1684:7) {
    code: 'ECONNREFUSED',
    [errors]: [
      Error: connect ECONNREFUSED ::1:8888
          at createConnectionError (node:net:1647:14)
          at afterConnectMultiple (node:net:1677:16) {
        errno: -61,
        code: 'ECONNREFUSED',
        syscall: 'connect',
        address: '::1',
        port: 8888
      },
      Error: connect ECONNREFUSED 127.0.0.1:8888
          at createConnectionError (node:net:1647:14)
          at afterConnectMultiple (node:net:1677:16) {
        errno: -61,
        code: 'ECONNREFUSED',
        syscall: 'connect',
        address: '127.0.0.1',
        port: 8888
      }
    ]
  }
}

Things I've tried:

Versions:

G2Jose commented 1 week ago

Explained by https://github.com/instantdb/instant/issues/168

I had DEV=true set in my environment. This was causing instant-cli to try to connect to a local instance of InstantDB instead of the cloud. Removing this fixes the issue.

I'd suggest instant-cli should take an explicit argument to connect to local vs cloud instances, as opposed to a rather generic environment variable.

stopachka commented 1 week ago

Great idea guys!

i.m.o:

  1. We should rename DEV to something like INSTANT_CLI_DEV
  2. We should add an INSTANT_CLI_API_URI env
  3. We can make a helper function called apiURI, which, does the following: a. if INSTANT_CLI_API_URI is set, we use that b. if INSTANT_CLI_DEV is set, we use localhost c. else we use instantdb.com
  4. We should update the docs inside cli/README.md, to talk about the dev and api uri env vars

We'll get to this, but if you guys want to pop in a PR for it, feel free!

cc @markyfyi if you think differently

markyfyi commented 2 hours ago

Added INSTANT_CLI_API_URI and INSTANT_CLI_DEV in v0.13.0! @G2Jose PTAL and let us know if you need anything else! cc @stopachka

G2Jose commented 2 hours ago

Added INSTANT_CLI_API_URI and INSTANT_CLI_DEV in v0.13.0! @G2Jose PTAL and let us know if you need anything else! cc @stopachka

That was so quick, thank you!