skdb icon indicating copy to clipboard operation
skdb copied to clipboard

Server using most recently created user?

Open ltique opened this issue 1 year ago • 3 comments

If I start the dev server and then the CLI I am logged in as root:

$ npx skdb --dev --db chat-app --remote-repl
root@ws://localhost:3586/chat-app>

If I then create a user with the CLI I get credentials I can use but (and I think this is sensible) nothing is put in ~/.skdb/credentials:

$ npx skdb --dev --create-user --db chat-app
Successfully created user:  {
  f8a0ksyieWZ5aWIU9iLrXGMqsV4: '...'
}
$ cat ~/.skdb/credentials
{}

However now when I start the CLI I am logged in as that recently created user:

$ npx skdb --dev --db chat-app --remote-repl
f8a0ksyieWZ5aWIU9iLrXGMqsV4@ws://localhost:3586/chat-app>

This surprises me because I have an empty credentials file and --help says:

$ npx skdb --help
Usage: node_modules/.bin/skdb-cli [--help]                      
...   
    [--access-key <key>]  -- Access key to use. Default: first specified in credentials file.

Indeed, I can't see any file anywhere on my file system which contains the string "f8a0ksyieWZ5aWIU9iLrXGMqsV4". Interestingly, if I create more users with --create-user I am still logged in as "f8a0ksyieWZ5aWIU9iLrXGMqsV4".

My best guess is that the server has the following logic:

  1. If no users have been created, use root as the access key.
  2. If one or more users have been created, use the first of those as the access key.

This isn't necessarily wrong or bad behaviour, but I'm also not sure if it's what's intended or not. And, perhaps, I'm completely missing out on something and there is state locally on my machine that I'm not aware of!

ltique avatar Feb 18 '24 08:02 ltique

Pass —user to control who you’re logged in as.

In dev mode credentials are fetched from the server itself. If you don’t specify a user, it uses the first in the map. First depends on the map implementation. Based on what you describe it seems the data structure sorts keys and is returning the first user alphabetically. This will be the first you create as our uuids order by time and begin with ‘f’ so sort before ‘root’.

gregsexton avatar Feb 18 '24 09:02 gregsexton

I wonder if we should force/suggest that people always specify --user (well, my version still seems to require --access-key https://github.com/SkipLabs/skdb/issues/119) so that they're very clear which user they're logging in as?

ltique avatar Feb 18 '24 09:02 ltique

I meant --access-key.

Probably we should. Probably we should re-write the CLI interface to make this and your other issues clearer. Something that takes an operation (like how git, or skdb itself work) and then tells you what the valid flags are would make sense to me.

gregsexton avatar Feb 19 '24 10:02 gregsexton

Closing skdb-specific issues as skdb in its current form is being deprecated.

beauby avatar Sep 30 '24 18:09 beauby