fix: handle signup token
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
@@ -11,8 +12,10 @@ func SetCookie(gc *gin.Context, token string) {
|
||||
secure := true
|
||||
httpOnly := true
|
||||
|
||||
host := GetDomainName(gc.Request.Host)
|
||||
log.Println("=> host", host)
|
||||
gc.SetSameSite(http.SameSiteNoneMode)
|
||||
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", gc.Request.Host, secure, httpOnly)
|
||||
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", host, secure, httpOnly)
|
||||
}
|
||||
|
||||
func GetCookie(gc *gin.Context) (string, error) {
|
||||
@@ -32,7 +35,7 @@ func DeleteCookie(gc *gin.Context) {
|
||||
secure = false
|
||||
}
|
||||
|
||||
host := GetDomainName(gc.Request.Host)
|
||||
gc.SetSameSite(http.SameSiteNoneMode)
|
||||
|
||||
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", gc.Request.Host, secure, httpOnly)
|
||||
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", host, secure, httpOnly)
|
||||
}
|
||||
|
@@ -2,36 +2,36 @@ package utils
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
)
|
||||
|
||||
func GetDomainName() string {
|
||||
u, err := url.Parse(constants.FRONTEND_URL)
|
||||
// function to get hostname
|
||||
func GetDomainName(auth_url string) string {
|
||||
u, err := url.Parse("//" + auth_url)
|
||||
if err != nil {
|
||||
return `localhost`
|
||||
}
|
||||
|
||||
host := u.Hostname()
|
||||
hostParts := strings.Split(host, ".")
|
||||
hostPartsLen := len(hostParts)
|
||||
|
||||
if hostPartsLen == 1 {
|
||||
return host
|
||||
}
|
||||
// code to get root domain in case of sub-domains
|
||||
// hostParts := strings.Split(host, ".")
|
||||
// hostPartsLen := len(hostParts)
|
||||
|
||||
if hostPartsLen == 2 {
|
||||
if hostParts[0] == "www" {
|
||||
return hostParts[1]
|
||||
} else {
|
||||
return host
|
||||
}
|
||||
}
|
||||
// if hostPartsLen == 1 {
|
||||
// return host
|
||||
// }
|
||||
|
||||
if hostPartsLen > 2 {
|
||||
return strings.Join(hostParts[hostPartsLen-2:], ".")
|
||||
}
|
||||
// if hostPartsLen == 2 {
|
||||
// if hostParts[0] == "www" {
|
||||
// return hostParts[1]
|
||||
// } else {
|
||||
// return host
|
||||
// }
|
||||
// }
|
||||
|
||||
// if hostPartsLen > 2 {
|
||||
// return strings.Join(hostParts[hostPartsLen-2:], ".")
|
||||
// }
|
||||
|
||||
return host
|
||||
}
|
||||
|
Reference in New Issue
Block a user