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,
	},
)

var IsAlreadyLogin = echojwt.WithConfig(
	echojwt.Config{
		SigningKey:   []byte("--one_api-secret-2019-04-01"),
		ErrorHandler: JWTErrorChecker,
	},
)

func JWTErrorChecker(c echo.Context, err error) error {
	return c.Redirect(http.StatusTemporaryRedirect, "/login")
}
