Files
Agent-System/internal/auth/store_factory.go
T
weichen d8c445bfd5 feat(auth): persist sessions and accounts via PostgresAuthStore
Add PgStore with hashed token sessions, IAM bootstrap, and store factory wiring; remove in-memory token map and allow_dev_switch from login payload.
2026-09-13 02:50:22 +00:00

31 lines
753 B
Go

package auth
import (
"context"
"github.com/jackc/pgx/v5/pgxpool"
"chat-agent-system/internal/config"
)
// Stores 认证账户存储与会话存储组合。
type Stores struct {
Auth AuthStore
Sessions SessionStore
}
// NewStores 根据数据库与 IAM 迁移状态选择 PG 或内存实现。
func NewStores(ctx context.Context, pool *pgxpool.Pool, cfg *config.Config) (*Stores, error) {
if pool != nil && IAMTablesReady(ctx, pool) {
pg, err := NewPgStore(pool, cfg)
if err != nil {
return nil, err
}
if err := BootstrapIAM(ctx, pool, pg, cfg); err != nil {
return nil, err
}
return &Stores{Auth: pg, Sessions: pg}, nil
}
mem := NewMemoryStore(cfg)
return &Stores{Auth: mem, Sessions: NewMemorySessionStore()}, nil
}