Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app info refactor #389

Merged
merged 29 commits into from
Nov 25, 2023
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4bd69ba
changes type input - not compiling
rishabhpoddar Nov 22, 2023
c59e122
fixes noramlisation bug
rishabhpoddar Nov 22, 2023
8f4e4bd
changes to how debug mode appinfo is logged
rishabhpoddar Nov 22, 2023
97f6981
fixes analytics api
rishabhpoddar Nov 22, 2023
1bd3128
fixes ep recipe
rishabhpoddar Nov 22, 2023
b649c69
fixes tpep recipe
rishabhpoddar Nov 22, 2023
5044a1a
fixes ev recipe
rishabhpoddar Nov 22, 2023
d0e5f9d
fixes pless recipe
rishabhpoddar Nov 22, 2023
a844883
changes types and normalisation logic in session recipe
rishabhpoddar Nov 23, 2023
1520b15
fixes issues in sessionrequestfunction
rishabhpoddar Nov 23, 2023
de3e046
small refactor
rishabhpoddar Nov 23, 2023
3bf99af
fixes sessionfunctions file
rishabhpoddar Nov 23, 2023
85f3f3f
small bug fix
rishabhpoddar Nov 23, 2023
98b60f9
fixes more files
rishabhpoddar Nov 23, 2023
e907412
small bug fix
rishabhpoddar Nov 23, 2023
1a672b9
modifies setting cookie and header
rishabhpoddar Nov 23, 2023
43e8f7c
more type fixes
rishabhpoddar Nov 23, 2023
ace4b09
fixes sessionrequest functions file
rishabhpoddar Nov 23, 2023
fc0aeb7
completes all lib code changes
rishabhpoddar Nov 23, 2023
b957b7b
fixes bug
rishabhpoddar Nov 23, 2023
a291f5d
fixes a bug
rishabhpoddar Nov 24, 2023
0a9068e
fixes a few tests
rishabhpoddar Nov 24, 2023
2accb6f
fixes a test
rishabhpoddar Nov 24, 2023
ffa0cbc
fixes more tests
rishabhpoddar Nov 24, 2023
ac54734
updates changelog
rishabhpoddar Nov 24, 2023
e5b6b24
adds a few tests
rishabhpoddar Nov 24, 2023
d4fc64c
more test
rishabhpoddar Nov 24, 2023
5b6dd83
adds more tests
rishabhpoddar Nov 25, 2023
b6d37a3
adds more tests
rishabhpoddar Nov 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
changes type input - not compiling
rishabhpoddar committed Nov 22, 2023
commit 4bd69baf6704c7458f4ec532ab08ccb85658dff0
18 changes: 10 additions & 8 deletions supertokens/models.go
Original file line number Diff line number Diff line change
@@ -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
55 changes: 38 additions & 17 deletions supertokens/utils.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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"
@@ -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
}