summaryrefslogtreecommitdiffstats
path: root/web/handler
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.net>2026-01-16 18:45:03 +0000
committerLeonardo Bishop <me@leonardobishop.net>2026-01-16 18:45:03 +0000
commiteddd55bc5dcfe36d8a56645d4b7e2e49429a933c (patch)
tree3eaf75f72225004980e99bc4a848a0cf5f942090 /web/handler
parente6cbb8415490524034561102b6c9f03e92e4dae7 (diff)
Cache /userinfo for a bit
Diffstat (limited to 'web/handler')
-rw-r--r--web/handler/auth.go11
-rw-r--r--web/handler/index.go19
2 files changed, 19 insertions, 11 deletions
diff --git a/web/handler/auth.go b/web/handler/auth.go
index 29bd47c..fcaaadf 100644
--- a/web/handler/auth.go
+++ b/web/handler/auth.go
@@ -5,6 +5,7 @@ import (
"html/template"
"log/slog"
"net/http"
+ "net/url"
"time"
"git.leonardobishop.net/instancer/pkg/auth"
@@ -13,12 +14,17 @@ import (
func GetAuth(tmpl *template.Template, authProvider *auth.OIDCAuthProvider) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
- w.Header().Add("HX-Redirect", "/auth")
+ errMessage := r.URL.Query().Get("error")
+ if errMessage != "" {
+ w.Header().Add("HX-Redirect", "/auth?error="+url.QueryEscape(errMessage))
+ } else {
+ w.Header().Add("HX-Redirect", "/auth")
+ }
tmpl.ExecuteTemplate(w, "auth.html", struct {
Error string
OidcIdPName string
}{
- Error: "",
+ Error: errMessage,
OidcIdPName: authProvider.Name,
})
}
@@ -156,7 +162,6 @@ func GetAuthCallback(tmpl *template.Template, session *session.MemoryStore, auth
func GetLogout(session *session.MemoryStore) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
//TODO expire session here
-
http.SetCookie(w, &http.Cookie{
Name: "instancer-session",
Value: "",
diff --git a/web/handler/index.go b/web/handler/index.go
index 9279151..8b3d43c 100644
--- a/web/handler/index.go
+++ b/web/handler/index.go
@@ -2,7 +2,7 @@ package handler
import (
"html/template"
- "log"
+ "log/slog"
"net/http"
"git.leonardobishop.net/instancer/pkg/registry"
@@ -13,14 +13,20 @@ func GetIndex(tmpl *template.Template, registryClient *registry.RegistryClient)
return func(w http.ResponseWriter, r *http.Request) {
challenges, err := registryClient.ListRepositories()
if err != nil {
- log.Printf("Could not list repositories: %v", err)
- http.Error(w, "Internal server error", http.StatusInternalServerError)
+ slog.Error("could not list repositories", "cause", err)
+ tmpl.ExecuteTemplate(w, "problem.html", struct {
+ Error string
+ ShowLogout bool
+ }{
+ Error: "Error occured fetching available challenges. Please try again.",
+ ShowLogout: false,
+ })
return
}
session := r.Context().Value("session").(*session.UserSession)
- if err := tmpl.ExecuteTemplate(w, "index.html", struct {
+ tmpl.ExecuteTemplate(w, "index.html", struct {
Challenges []string
Name string
Team string
@@ -28,9 +34,6 @@ func GetIndex(tmpl *template.Template, registryClient *registry.RegistryClient)
Challenges: challenges,
Name: session.Name,
Team: session.TeamName,
- }); err != nil {
- http.Error(w, "Internal server error", http.StatusInternalServerError)
- return
- }
+ })
}
}