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:
parent
119e3b7a6d
commit
ac04d7f346
6 changed files with 39 additions and 20 deletions
|
|
@ -57,14 +57,25 @@ services:
|
|||
|
||||
vite:
|
||||
image: node:20-alpine
|
||||
working_dir: /app/studio
|
||||
working_dir: /app/frontends
|
||||
environment:
|
||||
- CHOKIDAR_USEPOLLING=true
|
||||
- CHOKIDAR_INTERVAL=100
|
||||
command: sh -c "npm install && npm run dev -- --host"
|
||||
command: sh -c "npm install && npm run dev:studio -- --host"
|
||||
volumes:
|
||||
- ./studio:/app/studio
|
||||
- vite_node_modules:/app/studio/node_modules
|
||||
- ./frontends:/app/frontends
|
||||
- frontends_node_modules:/app/frontends/node_modules
|
||||
|
||||
owner-tools:
|
||||
image: node:20-alpine
|
||||
working_dir: /app/frontends
|
||||
environment:
|
||||
- CHOKIDAR_USEPOLLING=true
|
||||
- CHOKIDAR_INTERVAL=100
|
||||
command: sh -c "while [ ! -f /app/frontends/node_modules/.bin/vite ]; do sleep 5; done && npm run dev:owner-tools -- --host"
|
||||
volumes:
|
||||
- ./frontends:/app/frontends
|
||||
- frontends_node_modules:/app/frontends/node_modules
|
||||
|
||||
app:
|
||||
image: cosmtrek/air
|
||||
|
|
@ -76,6 +87,7 @@ services:
|
|||
air_wd: /app
|
||||
ENV: local
|
||||
VITE_URL: http://vite:5173
|
||||
OWNER_TOOLS_URL: http://owner-tools:5174
|
||||
DATABASE_URL: postgres://writekit:writekit@postgres:5432/writekit?sslmode=disable
|
||||
DOMAIN: writekit.lvh.me
|
||||
BASE_URL: http://writekit.lvh.me
|
||||
|
|
@ -116,4 +128,4 @@ volumes:
|
|||
minio_data:
|
||||
app_data:
|
||||
go_mod:
|
||||
vite_node_modules:
|
||||
frontends_node_modules:
|
||||
|
|
|
|||
3
go.mod
3
go.mod
|
|
@ -1,4 +1,4 @@
|
|||
module github.com/writekitapp/writekit
|
||||
module writekit
|
||||
|
||||
go 1.24.0
|
||||
|
||||
|
|
@ -18,7 +18,6 @@ require (
|
|||
github.com/jackc/pgx/v5 v5.7.1
|
||||
github.com/yuin/goldmark v1.7.13
|
||||
github.com/yuin/goldmark-emoji v1.0.6
|
||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
|
||||
golang.org/x/image v0.34.0
|
||||
modernc.org/sqlite v1.34.0
|
||||
)
|
||||
|
|
|
|||
7
go.sum
7
go.sum
|
|
@ -1,9 +1,7 @@
|
|||
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
|
||||
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
|
||||
github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
|
||||
github.com/alecthomas/chroma/v2 v2.21.1 h1:FaSDrp6N+3pphkNKU6HPCiYLgm8dbe5UXIXcoBhZSWA=
|
||||
github.com/alecthomas/chroma/v2 v2.21.1/go.mod h1:NqVhfBR0lte5Ouh3DcthuUCTUpDC9cxBOfyMbMQPs3o=
|
||||
github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
|
||||
github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs=
|
||||
github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
|
||||
github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI=
|
||||
|
|
@ -45,8 +43,6 @@ github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxY
|
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
||||
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
|
||||
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
|
|
@ -100,13 +96,10 @@ github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834 h1:ZF+QBjOI+tILZ
|
|||
github.com/tetratelabs/wabin v0.0.0-20230304001439-f6f874872834/go.mod h1:m9ymHTgNSEjuxvw8E7WWe4Pl4hZQHXONY8wE6dMLaRk=
|
||||
github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I=
|
||||
github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM=
|
||||
github.com/yuin/goldmark v1.4.15/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA=
|
||||
github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
|
||||
github.com/yuin/goldmark-emoji v1.0.6 h1:QWfF2FYaXwL74tfGOW5izeiZepUDroDJfWubQI9HTHs=
|
||||
github.com/yuin/goldmark-emoji v1.0.6/go.mod h1:ukxJDKFpdFb5x0a5HqbdlcKtebh086iJpI31LTKmWuA=
|
||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc h1:+IAOyRda+RLrxa1WC7umKOZRsGq4QrFFMYApOeHzQwQ=
|
||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc/go.mod h1:ovIvrum6DQJA4QsJSovrkC4saKHQVs7TvcaeO8AIl5I=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
|
||||
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
|
||||
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/writekitapp/writekit/internal/db"
|
||||
"writekit/internal/db"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
|
|
|
|||
8
main.go
8
main.go
|
|
@ -5,10 +5,10 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/writekitapp/writekit/internal/db"
|
||||
"github.com/writekitapp/writekit/internal/server"
|
||||
"github.com/writekitapp/writekit/internal/storage"
|
||||
"github.com/writekitapp/writekit/internal/tenant"
|
||||
"writekit/internal/db"
|
||||
"writekit/internal/server"
|
||||
"writekit/internal/storage"
|
||||
"writekit/internal/tenant"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue