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

svix-cli: Add interactive login #1846

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

svix-cli: Add interactive login #1846

wants to merge 1 commit into from

Conversation

svix-lucho
Copy link
Contributor

@svix-lucho svix-lucho commented Mar 28, 2025

Adds a selector when using svix login to log in using the dashboard.

Demo:

Screen.Recording.2025-03-28.at.3.14.15.PM.mov

@svix-lucho svix-lucho marked this pull request as ready for review March 28, 2025 18:20
@svix-lucho svix-lucho requested a review from a team as a code owner March 28, 2025 18:20
svix-james
svix-james previously approved these changes Mar 28, 2025
Comment on lines +91 to +94
Err(e) => {
eprintln!("Failed to get session ID: {}", e);
return Err(anyhow::anyhow!("Failed to get session ID"));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why print to stderr and return an error? Would the error not be printed otherwise?

Comment on lines +116 to +129
let response = match client
.post(&poll_url)
.json(&serde_json::json!({ "sessionId": session_id }))
.send()
.await
{
Ok(resp) => resp,
Err(e) => {
return Err(anyhow::anyhow!(
"Failed to connect to authentication server: {}",
e
));
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let response = match client
.post(&poll_url)
.json(&serde_json::json!({ "sessionId": session_id }))
.send()
.await
{
Ok(resp) => resp,
Err(e) => {
return Err(anyhow::anyhow!(
"Failed to connect to authentication server: {}",
e
));
}
};
let response = client
.post(&poll_url)
.json(&serde_json::json!({ "sessionId": session_id }))
.send()
.awai
.context("Failed to connect to authentication server")?;

(need to use anyhow::Context)

Comment on lines +132 to +138
match response.json::<AuthTokenOut>().await {
Ok(data) => {
println!("Authentication successful!\n");
return Ok(data.token);
}
Err(_) => return Err(anyhow::anyhow!("Failed to parse auth token")),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can also use .context() here (unless you think we should be hiding the deserialization error?)

Err(_) => "Unknown error".to_string(),
};

return Err(anyhow::anyhow!("Authentication failed: {}", error_message));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Err(anyhow::anyhow!("Authentication failed: {}", error_message));
anyhow::bail!("Authentication failed: {error_message}");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants