doghouse: clear invalid token when failed to get GitHub authenticated
user
@@ -271,8 +271,10 @@ func notfound(w http.ResponseWriter) {
func (g *GitHubHandler) getUserOrBadRequest(ctx context.Context, ghcli *github.Client, w http.ResponseWriter, r *http.Request) (bool, *github.User) {
u, _, err := ghcli.Users.Get(ctx, "")
if err != nil {
+ // Token seeims invalid. Clear it before returning BadRequest status.
+ g.tokenStore.Clear(w)
w.WriteHeader(http.StatusBadRequest)
- fmt.Fprintf(w, "cannot get GitHub authenticated user")
+ fmt.Fprintf(w, "Cannot get GitHub authenticated user. Please reload the page again.")
return false, nil
}
return true, u
