Gate the dashboard on the site's admin login and add a setup page
Like job-tracker, the tracker forwards the visitor's cookies to the site backend's /auth/validate-admin instead of asking for an API key. Signed in, the dashboard shows every device's data. The new /setup page has instructions for each collector and creates and revokes API keys. The userscript is served publicly at /tracker.user.js. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+8
-1
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"ccp/internal/api"
|
||||
"ccp/internal/auth"
|
||||
"ccp/internal/config"
|
||||
"ccp/internal/migrations"
|
||||
"ccp/internal/store"
|
||||
@@ -96,9 +97,15 @@ func serve(ctx context.Context, cfg config.Config, pool *pgxpool.Pool, st *store
|
||||
log.Info("migrations applied")
|
||||
}
|
||||
|
||||
var checker auth.Checker = auth.NewForward(cfg.AuthValidateURL, log)
|
||||
if cfg.AuthMode == "dev" {
|
||||
log.Warn("AUTH_MODE=dev: every visitor is treated as the admin")
|
||||
checker = auth.AllowAll{}
|
||||
}
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: cfg.ListenAddr,
|
||||
Handler: api.New(st, cfg.Location, log),
|
||||
Handler: api.New(st, checker, cfg.Location, log),
|
||||
ReadHeaderTimeout: 10 * time.Second,
|
||||
ReadTimeout: 60 * time.Second,
|
||||
WriteTimeout: 60 * time.Second,
|
||||
|
||||
Reference in New Issue
Block a user