add: cookie defaults and nuxt init check route

This commit is contained in:
Mohamed Sohail 2022-06-01 12:59:02 +03:00
parent 8e2625a094
commit 723c8bc71c
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
2 changed files with 20 additions and 9 deletions

View File

@ -31,6 +31,7 @@ func InitAdminApi(e *echo.Echo, db *pgxpool.Pool, queries goyesql.Queries, metaC
g.Use(api.dwCoreMiddleware)
g.Use(api.verifyAuthMiddleware)
g.GET("/check", isLoggedIn)
g.GET("/meta-proxy/:address", handleMetaProxy)
}

View File

@ -20,6 +20,10 @@ type jwtClaims struct {
jwt.StandardClaims
}
func isLoggedIn(c echo.Context) error {
return c.String(http.StatusOK, "ok")
}
func sendLoginJwtCookie(c echo.Context) error {
var (
api = c.Get("api").(*api)
@ -55,11 +59,8 @@ func sendLoginJwtCookie(c echo.Context) error {
return err
}
cookie := new(http.Cookie)
cookie.Name = "_ge_auth"
cookie := cookieDefaults()
cookie.Value = tokenString
cookie.Path = "/"
cookie.Expires = expiration
c.SetCookie(cookie)
@ -67,12 +68,21 @@ func sendLoginJwtCookie(c echo.Context) error {
}
func sendLogoutCookie(c echo.Context) error {
cookie := new(http.Cookie)
cookie.Name = "_ge_auth"
cookie.Value = ""
cookie.Expires = time.Now()
cookie := cookieDefaults()
cookie.MaxAge = -1
c.SetCookie(cookie)
return c.String(http.StatusOK, "logout successful")
}
func cookieDefaults() *http.Cookie {
cookie := new(http.Cookie)
cookie.Name = "_ge_auth"
cookie.Path = "/"
cookie.SameSite = 3
cookie.HttpOnly = true
cookie.Secure = false
return cookie
}