Initial commit
This commit is contained in:
25
mw/token_from_cookies.go
Normal file
25
mw/token_from_cookies.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user