Add stuff
This commit is contained in:
@ -2,6 +2,7 @@ package routes
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
@ -27,10 +28,12 @@ func OnlyAuthenticatedMiddleware(next http.Handler) http.Handler {
|
||||
func AuthMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
session, err := getSession(r)
|
||||
if err != nil {
|
||||
slog.Error("error getting token", "err", err)
|
||||
}
|
||||
username := ""
|
||||
if err != nil {
|
||||
if !errors.Is(err, http.ErrNoCookie) {
|
||||
slog.Error("error getting token", "err", err)
|
||||
}
|
||||
}
|
||||
if session != nil {
|
||||
username = session.Username
|
||||
}
|
||||
|
||||
15
routes/log_middleware.go
Normal file
15
routes/log_middleware.go
Normal file
@ -0,0 +1,15 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func LogMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
slog.Info("request", "method", r.Method, "path", r.URL.Path, "origin", r.RemoteAddr)
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user