Skip to content

Commit

Permalink
changes type input - not compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Nov 22, 2023
1 parent ac39010 commit 4bd69ba
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 25 deletions.
18 changes: 10 additions & 8 deletions supertokens/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ import (
)

type NormalisedAppinfo struct {
AppName string
WebsiteDomain NormalisedURLDomain
APIDomain NormalisedURLDomain
TopLevelAPIDomain string
TopLevelWebsiteDomain string
APIBasePath NormalisedURLPath
APIGatewayPath NormalisedURLPath
WebsiteBasePath NormalisedURLPath
AppName string
GetOrigin func(request *http.Request, userContext UserContext) (NormalisedURLDomain, error)
APIDomain NormalisedURLDomain
TopLevelAPIDomain string
GetTopLevelWebsiteDomain func(request *http.Request, userContext UserContext) (string, error)
APIBasePath NormalisedURLPath
APIGatewayPath NormalisedURLPath
WebsiteBasePath NormalisedURLPath
}

type AppInfo struct {
AppName string
WebsiteDomain string
Origin string
GetOrigin func(request *http.Request, userContext UserContext) (string, error)
APIDomain string
WebsiteBasePath *string
APIBasePath *string
Expand Down
55 changes: 38 additions & 17 deletions supertokens/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ func NormaliseInputAppInfoOrThrowError(appInfo AppInfo) (NormalisedAppinfo, erro
if appInfo.AppName == "" {
return NormalisedAppinfo{}, errors.New("Please provide your appName inside the appInfo object when calling supertokens.init")
}
if appInfo.WebsiteDomain == "" {
return NormalisedAppinfo{}, errors.New("Please provide your websiteDomain inside the appInfo object when calling supertokens.init")
}
apiGatewayPath, err := NewNormalisedURLPath("")
if err != nil {
return NormalisedAppinfo{}, err
Expand All @@ -60,10 +57,30 @@ func NormaliseInputAppInfoOrThrowError(appInfo AppInfo) (NormalisedAppinfo, erro
return NormalisedAppinfo{}, err
}
}
websiteDomain, err := NewNormalisedURLDomain(appInfo.WebsiteDomain)
if err != nil {
return NormalisedAppinfo{}, err

if appInfo.Origin == "" && appInfo.WebsiteDomain == "" && appInfo.GetOrigin == nil {
return NormalisedAppinfo{}, errors.New("Please provide either Origin, GetOrigin or WebsiteDomain inside the appInfo object when calling supertokens.init")
}

websiteDomainFunction := func(request *http.Request, userContext UserContext) (NormalisedURLDomain, error) {
origin := appInfo.Origin
if origin == "" {
origin = appInfo.WebsiteDomain
}

if appInfo.GetOrigin != nil {
originResult, err := appInfo.GetOrigin(request, userContext)
if err != nil {
return NormalisedURLDomain{}, err
}
origin = originResult
}

return NormalisedURLDomain{
value: origin,
}, nil
}

apiDomain, err := NewNormalisedURLDomain(appInfo.APIDomain)
if err != nil {
return NormalisedAppinfo{}, err
Expand All @@ -73,9 +90,13 @@ func NormaliseInputAppInfoOrThrowError(appInfo AppInfo) (NormalisedAppinfo, erro
if err != nil {
return NormalisedAppinfo{}, err
}
topLevelWebsiteDomain, err := GetTopLevelDomainForSameSiteResolution(websiteDomain.GetAsStringDangerous())
if err != nil {
return NormalisedAppinfo{}, err

getTopLevelWebsiteDomain := func(request *http.Request, userContext UserContext) (string, error) {
origin, err := websiteDomainFunction(request, userContext)
if err != nil {
return "", err
}
return GetTopLevelDomainForSameSiteResolution(origin.GetAsStringDangerous())
}

APIBasePathStr := "/auth"
Expand All @@ -97,14 +118,14 @@ func NormaliseInputAppInfoOrThrowError(appInfo AppInfo) (NormalisedAppinfo, erro
return NormalisedAppinfo{}, err
}
return NormalisedAppinfo{
AppName: appInfo.AppName,
APIGatewayPath: apiGatewayPath,
WebsiteDomain: websiteDomain,
APIDomain: apiDomain,
APIBasePath: apiBasePath,
TopLevelAPIDomain: topLevelAPIDomain,
TopLevelWebsiteDomain: topLevelWebsiteDomain,
WebsiteBasePath: websiteBasePath,
AppName: appInfo.AppName,
APIGatewayPath: apiGatewayPath,
GetOrigin: websiteDomainFunction,
APIDomain: apiDomain,
APIBasePath: apiBasePath,
TopLevelAPIDomain: topLevelAPIDomain,
GetTopLevelWebsiteDomain: getTopLevelWebsiteDomain,
WebsiteBasePath: websiteBasePath,
}, nil
}

Expand Down

0 comments on commit 4bd69ba

Please sign in to comment.