Add stuff

This commit is contained in:
Henri Burau
2024-06-06 21:30:29 +02:00
parent 72dce76e2b
commit ddbfc32fb1
13 changed files with 77 additions and 20 deletions

View File

@ -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
View 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)
})
}