add authgurad

This commit is contained in:
2024-06-21 18:54:06 +07:00
parent 5826d72988
commit c771187889
15 changed files with 127 additions and 94 deletions

20
auth/jwt.go Normal file
View File

@@ -0,0 +1,20 @@
package auth
import (
"net/http"
echojwt "github.com/labstack/echo-jwt/v4"
"github.com/labstack/echo/v4"
)
var IsLoggedIn = echojwt.WithConfig(
echojwt.Config{
SigningKey: []byte("--one_api-secret-2019-04-01"),
TokenLookup: "cookie:token",
ErrorHandler: JWTErrorChecker,
},
)
func JWTErrorChecker(c echo.Context, err error) error {
return c.Redirect(http.StatusTemporaryRedirect, "/login")
}

View File

@@ -1,7 +0,0 @@
package auth
import "github.com/labstack/echo/v4/middleware"
var IsLoggedIn = middleware.JWTWithConfig(middleware.JWTConfig{
SigningKey: []byte("secret"),
})