rentease/internal/server/auth.go
Ruidy 973a15c55b
feat(deps): migrate from Echo to Chi, update Stripe/Sentry
Switch web framework from Echo to Chi, removing Echo-related
dependencies
and adding chi and cors. Update Stripe to v83.1.0 and Sentry to v0.36.2.
Remove unused and indirect dependencies for a cleaner go.mod/go.sum.
2025-11-02 16:17:18 +01:00

26 lines
567 B
Go

package server
import (
"net/http"
"github.com/rjNemo/rentease/internal/constant"
"github.com/rjNemo/rentease/internal/service/auth"
)
func MakeAuthMiddleware(as *auth.Service) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == constant.RouteLogin {
next.ServeHTTP(w, r)
return
}
if !as.Authenticated(r) {
http.Redirect(w, r, constant.RouteLogin, http.StatusSeeOther)
return
}
next.ServeHTTP(w, r)
})
}
}