Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Fix coder login on Windows #310

Merged
merged 3 commits into from
Apr 5, 2021
Merged
Changes from all commits
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
18 changes: 9 additions & 9 deletions internal/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"context"
"fmt"
"io"
"net/url"
"strings"

Expand Down Expand Up @@ -73,7 +72,15 @@ func login(cmd *cobra.Command, envURL *url.URL) error {
fmt.Printf("Your browser has been opened to visit:\n\n\t%s\n\n", authURL.String())
}

token := readLine("Paste token here: ", cmd.InOrStdin())
fmt.Print("Paste token here: ")
var token string
scanner := bufio.NewScanner(cmd.InOrStdin())
_ = scanner.Scan()
token = scanner.Text()
if err := scanner.Err(); err != nil {
return xerrors.Errorf("reading standard input: %w", err)
}

if err := pingAPI(cmd.Context(), envURL, token); err != nil {
return xerrors.Errorf("ping API with credentials: %w", err)
}
Expand All @@ -84,13 +91,6 @@ func login(cmd *cobra.Command, envURL *url.URL) error {
return nil
}

func readLine(prompt string, r io.Reader) string {
reader := bufio.NewReader(r)
fmt.Print(prompt)
text, _ := reader.ReadString('\n')
return strings.TrimSuffix(text, "\n")
}

// pingAPI creates a client from the given url/token and try to exec an api call.
// Not using the SDK as we want to verify the url/token pair before storing the config files.
func pingAPI(ctx context.Context, envURL *url.URL, token string) error {
Expand Down