fix cookie generation
This commit is contained in:
parent
d4b295320e
commit
efce3337ec
|
@ -1,6 +1,10 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/yauthdev/yauth/server/constants"
|
"github.com/yauthdev/yauth/server/constants"
|
||||||
)
|
)
|
||||||
|
@ -12,9 +16,12 @@ func SetCookie(gc *gin.Context, token string) {
|
||||||
if !constants.IS_PROD {
|
if !constants.IS_PROD {
|
||||||
secure = false
|
secure = false
|
||||||
}
|
}
|
||||||
host := GetFrontendHost()
|
u, err := url.Parse(constants.SERVER_URL)
|
||||||
|
if err != nil {
|
||||||
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", host, secure, httpOnly)
|
log.Println("error getting server host")
|
||||||
|
}
|
||||||
|
gc.SetSameSite(http.SameSiteNoneMode)
|
||||||
|
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", u.Hostname(), secure, httpOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteCookie(gc *gin.Context) {
|
func DeleteCookie(gc *gin.Context) {
|
||||||
|
@ -25,5 +32,11 @@ func DeleteCookie(gc *gin.Context) {
|
||||||
secure = false
|
secure = false
|
||||||
}
|
}
|
||||||
|
|
||||||
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", GetFrontendHost(), secure, httpOnly)
|
u, err := url.Parse(constants.SERVER_URL)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("error getting server host")
|
||||||
|
}
|
||||||
|
gc.SetSameSite(http.SameSiteNoneMode)
|
||||||
|
|
||||||
|
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", u.Hostname(), secure, httpOnly)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/yauthdev/yauth/server/constants"
|
"github.com/yauthdev/yauth/server/constants"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFrontendHost() string {
|
func GetDomainName() string {
|
||||||
u, err := url.Parse(constants.FRONTEND_URL)
|
u, err := url.Parse(constants.FRONTEND_URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return `localhost`
|
return `localhost`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user