chore(deps): update auth middleware and dependencies

- Add OptionalSessionMiddleware for non-required auth checks
- Add GetUserID helper function
- Update import paths in auth and main
- Update docker-compose with frontend build configuration
- Clean up go.mod and go.sum

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Josh 2026-01-12 02:02:30 +02:00
parent 119e3b7a6d
commit ac04d7f346
6 changed files with 39 additions and 20 deletions

View file

@ -5,7 +5,7 @@ import (
"net/http"
"strings"
"github.com/writekitapp/writekit/internal/db"
"writekit/internal/db"
)
type ctxKey string
@ -40,6 +40,21 @@ func GetUserID(r *http.Request) string {
return ""
}
func OptionalSessionMiddleware(database *db.DB) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token := extractToken(r)
if token != "" {
if session, err := database.ValidateSession(r.Context(), token); err == nil && session != nil {
ctx := context.WithValue(r.Context(), userIDKey, session.UserID)
r = r.WithContext(ctx)
}
}
next.ServeHTTP(w, r)
})
}
}
func extractToken(r *http.Request) string {
if cookie, err := r.Cookie("writekit_session"); err == nil && cookie.Value != "" {
return cookie.Value