From 67bbaedf5f46d140fc5a8ac7500cecedcf9c9cc7 Mon Sep 17 00:00:00 2001 From: Jacek Migdal Date: Thu, 7 Nov 2024 00:58:07 -0800 Subject: [PATCH] Improve login redirect (#959) @mieciu please test it before merging. I could not do that locally. It fixes two issues: - right redirect if you host it on different domain than localhost - do also redirect if HTMX hit it in some fragment (auto-refreshed panel) --------- Co-authored-by: przemyslaw --- quesma/quesma/ui/console_routes.go | 3 ++- quesma/quesma/ui/es_auth_provider.go | 2 +- quesma/quesma/ui/html_utils.go | 2 -- quesma/quesma/ui/login.go | 3 ++- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/quesma/quesma/ui/console_routes.go b/quesma/quesma/ui/console_routes.go index 8b730ea8f..18b30ff23 100644 --- a/quesma/quesma/ui/console_routes.go +++ b/quesma/quesma/ui/console_routes.go @@ -23,6 +23,7 @@ const ( uiTcpPort = "9999" managementInternalPath = "/_quesma" healthPath = managementInternalPath + "/health" + loginWithElasticSearch = "/login-with-elasticsearch" ) //go:embed asset/* @@ -70,7 +71,7 @@ func (qmc *QuesmaManagementConsole) createRouting() *mux.Router { router.HandleFunc("/auth/{provider}/callback", authCallbackHandler) // our logic for login - router.HandleFunc("/login-with-elasticsearch", qmc.HandleElasticsearchLogin) + router.HandleFunc(loginWithElasticSearch, qmc.HandleElasticsearchLogin) authenticatedRoutes := router.PathPrefix("/").Subrouter() if qmc.cfg.Elasticsearch.User == "" && qmc.cfg.Elasticsearch.Password == "" { diff --git a/quesma/quesma/ui/es_auth_provider.go b/quesma/quesma/ui/es_auth_provider.go index 966f6375d..12b2afb59 100644 --- a/quesma/quesma/ui/es_auth_provider.go +++ b/quesma/quesma/ui/es_auth_provider.go @@ -25,7 +25,7 @@ func NewElasticsearchAuthProvider() *ElasticsearchAuthProvider { type ElasticsearchSession struct{} func (e ElasticsearchSession) GetAuthURL() (string, error) { - return "http://localhost:9999/login-with-elasticsearch", nil + return loginWithElasticSearch, nil } func (e ElasticsearchSession) Marshal() string { diff --git a/quesma/quesma/ui/html_utils.go b/quesma/quesma/ui/html_utils.go index 56a21f496..28dab3790 100644 --- a/quesma/quesma/ui/html_utils.go +++ b/quesma/quesma/ui/html_utils.go @@ -85,8 +85,6 @@ func (qmc *QuesmaManagementConsole) generateTopNavigation(target string) []byte buffer.Html(abTestingPath) buffer.Html(`">A/B`) - buffer.Html(`
  • Logout
  • `) - if qmc.isAuthEnabled { buffer.Html(`
  • Logout
  • `) } diff --git a/quesma/quesma/ui/login.go b/quesma/quesma/ui/login.go index af67fc71c..b173d2b51 100644 --- a/quesma/quesma/ui/login.go +++ b/quesma/quesma/ui/login.go @@ -20,7 +20,7 @@ func (qmc *QuesmaManagementConsole) generateLoginForm() []byte { buffer.Html(`