Skip to content

Commit

Permalink
Check access token and fail fast if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
cyx committed Jan 25, 2021
1 parent 3d2ada9 commit 33ac735
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -31,6 +32,8 @@ type tenant struct {
ExpiresAt time.Time `json:"expires_at"`
}

var errUnauthenticated = errors.New("Not yet configured. Try `auth0 login`.")

// cli provides all the foundational things for all the commands in the CLI,
// specifically:
//
Expand Down Expand Up @@ -84,7 +87,10 @@ func (c *cli) setup() error {
return err
}

if t.AccessToken != "" {
if t.AccessToken == "" {
return errUnauthenticated

} else if t.AccessToken != "" {
c.api, err = management.New(t.Domain,
management.WithStaticToken(t.AccessToken),
management.WithDebug(c.verbose))
Expand Down Expand Up @@ -177,7 +183,7 @@ func (c *cli) initContext() (err error) {
}

if _, err := os.Stat(c.path); os.IsNotExist(err) {
return fmt.Errorf("Not yet configured. Try `auth0 login`.")
return errUnauthenticated
}

var buf []byte
Expand All @@ -190,7 +196,7 @@ func (c *cli) initContext() (err error) {
}

if c.tenant == "" && c.config.DefaultTenant == "" {
return fmt.Errorf("Not yet configured. Try `auth0 login`.")
return errUnauthenticated
}

if c.tenant == "" {
Expand Down

0 comments on commit 33ac735

Please sign in to comment.