feat: add Redis support for distributed passkey sessions
- Implement SessionStore interface for pluggable storage backends - Add redisStore for distributed environment - Add memoryStore as fallback for single instance - Update router to initialize Redis client when configured - Update .env.example with Redis documentation
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -64,10 +65,19 @@ func SetRouter(cfg *config.Config, db *gorm.DB, web *embed.FS) {
|
||||
gateway.SetUsageRecorder(usageRecorder)
|
||||
|
||||
// Initialize passkey service
|
||||
var rdb *redis.Client
|
||||
if cfg.RedisHost != "" {
|
||||
rdb = redis.NewClient(&redis.Options{
|
||||
Addr: fmt.Sprintf("%s:%d", cfg.RedisHost, cfg.RedisPort),
|
||||
Password: cfg.RedisPassword,
|
||||
DB: cfg.RedisDB,
|
||||
})
|
||||
}
|
||||
passkeySvc, err := passkey.New(db, passkey.Config{
|
||||
RPID: cfg.RPID,
|
||||
Origins: cfg.RPOrigins,
|
||||
Name: cfg.AppName,
|
||||
Redis: rdb,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize passkey service: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user