feat(web): allow Redis session URL separate from app DB

Wire session_url through app.auth/listen so sites can store sessions in
Redis while keeping Postgres/SQLite for application data.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-18 14:59:50 +08:00
1 parent 410f36f719
commit 981d754133
5 files changed
+24 -5

No files matched your search

+4
View File
@@ -213,6 +213,10 @@ func Auth(appBag map[string]any, users any, opts map[string]any) (map[string]any
if v := firstStr(opts, "default_role", "默认角色"); v != "" {
authBag["default_role"] = v
}
if v := firstStr(opts, "session_url", "会话地址", "redis_url", "Redis"); v != "" {
out["session_url"] = v
authBag["session_url"] = v
}
out["auth"] = authBag
gates := gatesOf(out)
if !hasAdminGate(gates, prefix) {
+13
View File
@@ -45,6 +45,7 @@ func NewHandler(appBag map[string]any, entryDir string) (http.Handler, error) {
}
session.Configure(session.Config{
DBURL: dbURL,
RedisURL: sessionURLOf(appBag),
TTLSec: authCfg.sessionTTL,
CookieSecure: authCfg.cookieSecure,
})
@@ -846,6 +847,18 @@ func dbURLOf(appBag map[string]any) string {
return ""
}
func sessionURLOf(appBag map[string]any) string {
if s, ok := appBag["session_url"].(string); ok && s != "" {
return s
}
if auth, ok := appBag["auth"].(map[string]any); ok {
if s, ok := auth["session_url"].(string); ok && s != "" {
return s
}
}
return ""
}
func resolvePath(p, entryDir string) string {
if filepath.IsAbs(p) {
return p