Skip to content

feat: add feature to show warning to user if they are already logged in #14219

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: added requested changes
  • Loading branch information
BRAVO68WEB committed Aug 9, 2024
commit f9270a9b8c0da09098a9ab11f47151ef9fbae01b
2 changes: 1 addition & 1 deletion cli/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func TestLogin(t *testing.T) {
err := root.Run()
assert.NoError(t, err)
}()
pty.ExpectMatch(fmt.Sprintf(" Already Logged In to '%s'!", client.URL.String()))
pty.ExpectMatch(fmt.Sprintf("You are already logged in to '%s'!", client.URL.String()))
pty.ExpectMatch(fmt.Sprintf("Attempting to authenticate with argument URL: '%s'", client.URL.String()))
pty.ExpectMatch("Paste your token here:")
pty.WriteLine(client.SessionToken())
Expand Down
4 changes: 2 additions & 2 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,9 @@ func (r *RootCmd) CheckExistingUserSession() serpent.MiddlewareFunc {
}
}

// IF r.token and r.clientUR, exists then print warning "ALready loggedIn"
// IF r.token and r.clientUR, exists then print warning "You are already logged in to $"
if r.token != "" && r.clientURL.String() != "" {
_, _ = fmt.Fprintf(inv.Stdout, Caret+"%s!\n", pretty.Sprint(cliui.DefaultStyles.Warn, "Already Logged In to "+r.clientURL.String()))
_, _ = fmt.Fprintf(inv.Stdout, Caret+"%s!\n", pretty.Sprint(cliui.DefaultStyles.Warn, "You are already logged in to "+r.clientURL.String()))
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking about what we want to achieve with this warning. As it stands I imagine it will be slightly annoying to see the warning but not be able to do an action based on it.

Also, the token could be expired so then we're kind of lying to the user as they're not really logged in.

Should we move this from middleware and prompt the user for what to do instead (+ verify token is valid)? WDYT @matifali?

Copy link
Member

Choose a reason for hiding this comment

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

Yes I agree 💯. Checking token for validity should be a must and if expired should instruct the user to relogin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Guys, give me a final rundown about what should I implement?

Copy link
Member

Choose a reason for hiding this comment

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

I think for merge this should call the coder API to see what the current user is and print the username as well. If the request fails, any message should be suppressed.

This should also print to stderr rather than stdout.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted

}

// We remove the token and clientURL from the RootCmd, so the user can still go ahead and login
Expand Down
Loading