ReauthenticateIfExpired checks if err is a session-expired error from the API. If so, it clears the invalid token and triggers the login flow.
( io *iostreams.IOStreams, client *dashboard.Client, err error, )
| 31 | // ReauthenticateIfExpired checks if err is a session-expired error from the API. |
| 32 | // If so, it clears the invalid token and triggers the login flow. |
| 33 | func ReauthenticateIfExpired( |
| 34 | io *iostreams.IOStreams, |
| 35 | client *dashboard.Client, |
| 36 | err error, |
| 37 | ) (string, error) { |
| 38 | if !errors.Is(err, dashboard.ErrSessionExpired) { |
| 39 | return "", err |
| 40 | } |
| 41 | |
| 42 | cs := io.ColorScheme() |
| 43 | ClearToken() |
| 44 | fmt.Fprintf(io.Out, "%s Session expired.\n", cs.WarningIcon()) |
| 45 | |
| 46 | // No flow tracker: this re-authentication belongs to the calling flow, |
| 47 | // not to an `auth login` funnel. |
| 48 | return RunOAuth(io, client, false, true, nil) |
| 49 | } |
no test coverage detected