mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2025-02-08 04:57:31 +01:00
add: cookie defaults and nuxt init check route
This commit is contained in:
parent
8e2625a094
commit
723c8bc71c
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user