Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - fix token refresh function #3

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading