Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement spacetime login #1847

Closed
cloutiertyler opened this issue Oct 11, 2024 · 2 comments · Fixed by #1878
Closed

Implement spacetime login #1847

cloutiertyler opened this issue Oct 11, 2024 · 2 comments · Fixed by #1878
Assignees

Comments

@cloutiertyler
Copy link
Contributor

cloutiertyler commented Oct 11, 2024

Steps:

  1. The CLI starts a websocket connection to https://spacetimedb.com/login-cli
  2. It passes in a random nonce that it created to the websocket
  3. Zeke figures out how to open the default browser and set the url to be https://spacetimedb.com/login-cli?nonce={the nonce}
  4. The user logs in on the browser
  5. The API backend sends the session token to the CLI over the websocket connection
  6. The CLI provides the session token on every subsequent request to the website API
  7. The CLI hits the /v1/identity endpoint to receive a SpacetimeDB token
  8. The CLI provides this token to all SpacetimeDB requests (unless they are flagged --anonymous.
@bfops
Copy link
Collaborator

bfops commented Oct 11, 2024

ChatGPT:

fn open_browser(url: &str) {
    let open_command = match env::consts::OS {
        "windows" => Command::new("cmd").args(&["/C", "start", url]),
        "macos" => Command::new("open").arg(url),
        "linux" => Command::new("xdg-open").arg(url),
        _ => {
            eprintln!("Unsupported OS");
            return;
        }
    };

    if let Err(e) = open_command.status() {
        eprintln!("Failed to open browser: {}", e);
    }
}

Instead of "unsupported OS", we'd probably just print the URL and wait to hear back on the websocket. Other CLIs do this.

@PuruVJ
Copy link
Contributor

PuruVJ commented Oct 11, 2024

I saw that we also pull in this crate somewhere in spacetimedb https://crates.io/crates/webbrowser, so caninstead just reuse it

This was referenced Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants