mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
25 lines
534 B
Go
25 lines
534 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"github.com/rjNemo/rentease/internal/constant"
|
|
"github.com/rjNemo/rentease/internal/service/auth"
|
|
)
|
|
|
|
func MakeAuthMiddleware(as *auth.Service) echo.MiddlewareFunc {
|
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
|
return func(c echo.Context) error {
|
|
if c.Request().RequestURI == constant.RouteLogin {
|
|
return next(c)
|
|
}
|
|
|
|
if !as.Authenticated(c) {
|
|
return c.Redirect(http.StatusSeeOther, constant.RouteLogin)
|
|
}
|
|
return next(c)
|
|
}
|
|
}
|
|
}
|