Skip to content

Commit

Permalink
NOISSUE - Fix token refresh function (#3)
Browse files Browse the repository at this point in the history
Signed-off-by: ianmuchyri <[email protected]>
  • Loading branch information
ianmuchyri authored Nov 10, 2023
1 parent 471583c commit 8f811a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ui/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -2290,18 +2290,20 @@ func TokenMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
tokenString, err := tokenFromCookie(r, "token")
if err != nil {
http.Redirect(w, r, "/login", http.StatusSeeOther)
return
}

// Parse the token without validation to get the expiration time
token, _, err := new(jwt.Parser).ParseUnverified(tokenString, jwt.MapClaims{})
if err != nil {
http.Redirect(w, r, "/error?error="+url.QueryEscape(err.Error()), http.StatusSeeOther)
return
}
if claims, ok := token.Claims.(jwt.MapClaims); ok {
expirationTime := time.Unix(int64(claims["exp"].(float64)), 0)
if expirationTime.Before(time.Now()) {
http.Redirect(w, r, "/ui/token/refresh?referer_url="+url.QueryEscape(r.URL.String()), http.StatusSeeOther)
http.Redirect(w, r, "/token/refresh?referer_url="+url.QueryEscape(r.URL.String()), http.StatusSeeOther)
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/web/template/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ <h5 class="modal-title" id="forgotPasswordModalLabel">
showAlert(errorMessage);
} else {
form.reset();
window.location.href = "";
window.location.href = "/";
}
})
.catch((error) => {
Expand Down

0 comments on commit 8f811a2

Please sign in to comment.