fix: handle signup token
This commit is contained in:
parent
78b5b33a3d
commit
d1973c1f8f
|
@ -8,7 +8,7 @@ ENV VERSION="${VERSION}"
|
|||
RUN apk add build-base &&\
|
||||
cd server && \
|
||||
go mod download && \
|
||||
go build && \
|
||||
make clean && make && \
|
||||
chmod 777 server
|
||||
|
||||
FROM alpine:latest
|
||||
|
|
|
@ -93,12 +93,6 @@ func InitEnv() {
|
|||
panic("Database type is required")
|
||||
}
|
||||
|
||||
if constants.AUTHORIZER_DOMAIN == "" {
|
||||
panic("Authroizer domain is required")
|
||||
}
|
||||
|
||||
log.Println("=> Authorizer domain=", constants.AUTHORIZER_DOMAIN)
|
||||
|
||||
if constants.JWT_TYPE == "" {
|
||||
constants.JWT_TYPE = "HS256"
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package handlers
|
|||
|
||||
import (
|
||||
"github.com/99designs/gqlgen/graphql/handler"
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
"github.com/authorizerdev/authorizer/server/graph"
|
||||
"github.com/authorizerdev/authorizer/server/graph/generated"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -14,6 +15,9 @@ func GraphqlHandler() gin.HandlerFunc {
|
|||
h := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
|
||||
|
||||
return func(c *gin.Context) {
|
||||
if constants.AUTHORIZER_DOMAIN == "" {
|
||||
constants.AUTHORIZER_DOMAIN = "https://" + c.Request.Host
|
||||
}
|
||||
h.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ func Signup(ctx context.Context, params model.SignUpInput) (*model.AuthResponse,
|
|||
if constants.DISABLE_EMAIL_VERICATION == "true" {
|
||||
user.EmailVerifiedAt = time.Now().Unix()
|
||||
}
|
||||
_, err = db.Mgr.SaveUser(user)
|
||||
user, err = db.Mgr.SaveUser(user)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user