Добавить сессии в Valkey и вход через Basic с Bearer-токеном
This commit is contained in:
+9
-1
@@ -5,11 +5,14 @@ package app
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
||||
"messenger/internal/auth"
|
||||
authstore "messenger/internal/auth/store"
|
||||
"messenger/internal/chat"
|
||||
chatstore "messenger/internal/chat/store"
|
||||
"messenger/internal/health"
|
||||
@@ -28,6 +31,8 @@ type App struct {
|
||||
type Deps struct {
|
||||
Log *slog.Logger
|
||||
DB *pgxpool.Pool
|
||||
Sessions *redis.Client
|
||||
SessionTTL time.Duration
|
||||
MaxBodyBytes int64
|
||||
}
|
||||
|
||||
@@ -39,8 +44,11 @@ func New(d Deps) *App {
|
||||
probes := health.New()
|
||||
probes.Register(engine)
|
||||
|
||||
sessions := auth.NewService(users, authstore.NewSessions(d.Sessions), d.SessionTTL)
|
||||
|
||||
public := engine.Group("/api/v1")
|
||||
protected := public.Group("", auth.RequireUser(users))
|
||||
protected := public.Group("", auth.RequireSession(sessions))
|
||||
auth.NewHandler(sessions).Register(public, protected)
|
||||
user.NewHandler(users).Register(public, protected)
|
||||
chat.NewHandler(chats).Register(protected)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user