xataio / client-ts

Xata.io SDK for TypeScript and JavaScript
https://xata.io/docs/sdk/typescript/overview
Apache License 2.0
123 stars 8 forks source link

Provide debug information if an API key is invalid #491

Closed TejasQ closed 2 years ago

TejasQ commented 2 years ago

Describe the bug

Loom: https://www.loom.com/share/4612e5d993014dfc99b4ac797a58a56e

image

xata init always fails with Invalid API key when .env is present and contains an older API key, despite running xata auth login and provide a new API key.

To Reproduce

Expected behavior xata auth login, after successfully logging in, checks if there's an existing stale API key in .env and warns that this will still be used, with the choice to override it.

Software version @xata.io/cli/0.7.0 darwin-arm64 node-v16.15.1

Additional Context

  1. This occurred during a demo with another dev advocate
  2. ~This blocks creating content like a welcome video, unless we don't show the CLI 😬~
gimenete commented 2 years ago

Changing the title because xata auth login works as expected. This command only touches the credentials file, because it's a command for global mode, not project mode.

By design, an API key in an .env file will always take precedence over the api key in the credentials file. The reason is that in the near future you may have both but with different scopes, being the one in the .env file scoped to the database and thus preferred by operations done in the current database.

So, we'll just provide additional debug information in the error message, to at least let the user know where the API key is obtained from.

TejasQ commented 2 years ago

I feel like GitHub should add 💯 to the emoji reactions. If it did, I’d react with that. Thanks!