2021-07-14 18:43:19 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2021-07-21 15:57:12 +00:00
|
|
|
"log"
|
|
|
|
|
2021-07-14 18:43:19 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/yauthdev/yauth/server/constants"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SetCookie(gc *gin.Context, token string) {
|
|
|
|
secure := true
|
|
|
|
httpOnly := true
|
|
|
|
|
|
|
|
if !constants.IS_PROD {
|
|
|
|
secure = false
|
|
|
|
}
|
|
|
|
|
2021-07-21 15:57:12 +00:00
|
|
|
log.Println("-> is cookie secure", secure)
|
|
|
|
|
2021-07-14 18:43:19 +00:00
|
|
|
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", GetFrontendHost(), secure, httpOnly)
|
|
|
|
}
|
2021-07-15 09:43:00 +00:00
|
|
|
|
|
|
|
func DeleteCookie(gc *gin.Context) {
|
|
|
|
secure := true
|
|
|
|
httpOnly := true
|
|
|
|
|
|
|
|
if !constants.IS_PROD {
|
|
|
|
secure = false
|
|
|
|
}
|
|
|
|
|
|
|
|
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", GetFrontendHost(), secure, httpOnly)
|
|
|
|
}
|