Add PgStore with hashed token sessions, IAM bootstrap, and store factory wiring; remove in-memory token map and allow_dev_switch from login payload.
31 lines
753 B
Go
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
|
|
}
|