Initial commit

This commit is contained in:
kandrusyak
2023-06-23 02:18:00 +03:00
commit 688ae61bc6
12 changed files with 297 additions and 0 deletions

25
mw/token_from_cookies.go Normal file
View File

@@ -0,0 +1,25 @@
package mw
import (
"github.com/labstack/echo/v4"
"net/http"
)
func TokenFromCookies(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
var token, err = c.Request().Cookie("accessToken")
var authToken = c.Request().Header.Get("Authorization")
if err != nil {
return next(c)
}
if authToken != "" {
return c.NoContent(http.StatusBadRequest)
}
c.Request().Header.Set("Authorization", "Bearer "+token.Value)
return next(c)
}
}