File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,11 @@ func (t Auth) GetFreshAccessTokenOrNil() (string, error) {
151151 if ! isAccessTokenValid && tokens .RefreshToken != "" {
152152 tokens , err = t .getNewTokensWithRefreshOrNil (tokens .RefreshToken )
153153 if err != nil {
154+ if strings .Contains (err .Error (), "UNAUTHORIZED" ) {
155+ // Clear the expired tokens
156+ _ = t .authStore .DeleteAuthTokens ()
157+ return "" , & breverrors.SessionExpiredError {HasPreviousSession : true }
158+ }
154159 return "" , breverrors .WrapAndTrace (err )
155160 }
156161 if tokens == nil {
@@ -182,7 +187,7 @@ func (t Auth) PromptForLogin() (*LoginTokens, error) {
182187
183188func shouldLogin () (bool , error ) {
184189 reader := bufio .NewReader (os .Stdin ) // TODO 9 inject?
185- fmt .Print (`You are currently logged out, would you like to log in? [y/n]: ` )
190+ fmt .Print (color . YellowString ( "Would you like to log in to Brev ? [y/n]: " ) )
186191 text , err := reader .ReadString ('\n' )
187192 if err != nil {
188193 return false , breverrors .WrapAndTrace (err )
Original file line number Diff line number Diff line change @@ -130,6 +130,24 @@ func (d *DeclineToLoginError) Directive() string { return "log in to run this co
130130
131131var NetworkErrorMessage = "possible internet connection problem"
132132
133+ type SessionExpiredError struct {
134+ HasPreviousSession bool
135+ }
136+
137+ func (e * SessionExpiredError ) Error () string {
138+ if e .HasPreviousSession {
139+ return "Your session has expired due to inactivity"
140+ }
141+ return "You are not logged in"
142+ }
143+
144+ func (e * SessionExpiredError ) Directive () string {
145+ if e .HasPreviousSession {
146+ return "Please log in again to continue using the CLI"
147+ }
148+ return "Please log in to use the CLI"
149+ }
150+
133151type CredentialsFileNotFound struct {}
134152
135153func (e * CredentialsFileNotFound ) Directive () string {
You can’t perform that action at this time.
0 commit comments