Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 67bbaed

Browse files
jakozaurmieciu
andauthored
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 <[email protected]>
1 parent ee91bfa commit 67bbaed

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

quesma/quesma/ui/console_routes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
uiTcpPort = "9999"
2424
managementInternalPath = "/_quesma"
2525
healthPath = managementInternalPath + "/health"
26+
loginWithElasticSearch = "/login-with-elasticsearch"
2627
)
2728

2829
//go:embed asset/*
@@ -70,7 +71,7 @@ func (qmc *QuesmaManagementConsole) createRouting() *mux.Router {
7071
router.HandleFunc("/auth/{provider}/callback", authCallbackHandler)
7172

7273
// our logic for login
73-
router.HandleFunc("/login-with-elasticsearch", qmc.HandleElasticsearchLogin)
74+
router.HandleFunc(loginWithElasticSearch, qmc.HandleElasticsearchLogin)
7475

7576
authenticatedRoutes := router.PathPrefix("/").Subrouter()
7677
if qmc.cfg.Elasticsearch.User == "" && qmc.cfg.Elasticsearch.Password == "" {

quesma/quesma/ui/es_auth_provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func NewElasticsearchAuthProvider() *ElasticsearchAuthProvider {
2525
type ElasticsearchSession struct{}
2626

2727
func (e ElasticsearchSession) GetAuthURL() (string, error) {
28-
return "http://localhost:9999/login-with-elasticsearch", nil
28+
return loginWithElasticSearch, nil
2929
}
3030

3131
func (e ElasticsearchSession) Marshal() string {

quesma/quesma/ui/html_utils.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ func (qmc *QuesmaManagementConsole) generateTopNavigation(target string) []byte
8585
buffer.Html(abTestingPath)
8686
buffer.Html(`">A/B</a></li>`)
8787

88-
buffer.Html(`<li><a href="/logout">Logout</a></li>`)
89-
9088
if qmc.isAuthEnabled {
9189
buffer.Html(`<li><a href="/logout">Logout</a></li>`)
9290
}

quesma/quesma/ui/login.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (qmc *QuesmaManagementConsole) generateLoginForm() []byte {
2020
buffer.Html(`<div class="login-form">`)
2121
buffer.Html(`<h2>Login</h2>`)
2222
buffer.Html(`<p style="color: #ccc;">Log in to Quesma admin console using your Elasticsearch credentials</p>`)
23-
buffer.Html(`<form action="/login-with-elasticsearch" method="post">`)
23+
buffer.Html(`<form action="`).Text(loginWithElasticSearch).Html(`" method="post">`)
2424
buffer.Html(`<label for="username">Username:</label>`)
2525
buffer.Html(`<input type="text" id="username" name="username" placeholder="Enter your Elasticsearch username" autofocus>`)
2626
buffer.Html(`<label for="password">Password:</label>`)
@@ -41,6 +41,7 @@ func (qmc *QuesmaManagementConsole) HandleElasticsearchLogin(writer http.Respons
4141
return
4242
}
4343
writer.Header().Set("Content-Type", "text/html")
44+
writer.Header().Set("HX-Redirect", loginWithElasticSearch)
4445
writer.Write(qmc.generateLoginForm())
4546
} else if req.Method == http.MethodPost {
4647
username := req.FormValue("username")

0 commit comments

Comments
 (0)