Skip to content

Commit

Permalink
adds docs for mutiple frontend for golang
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Nov 25, 2023
1 parent fede7a9 commit 2505daf
Show file tree
Hide file tree
Showing 7 changed files with 248 additions and 23 deletions.
53 changes: 49 additions & 4 deletions v2/emailpassword/common-customizations/multiple-clients.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,54 @@ supertokens.init({

<TabItem value="go">

:::note
Coming Soon
:::
```go
import (
"net/http"

"github.com/supertokens/supertokens-golang/supertokens"
)

func main() {
err := supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "...",
APIKey: "...",
},
AppInfo: supertokens.AppInfo{
AppName: "...",
APIDomain: "...",
// highlight-start
GetOrigin: func(request *http.Request, userContext supertokens.UserContext) (string, error) {
if request != nil {
origin := request.Header.Get("origin")
if origin == "" {
// this means the client is in an iframe, it's a mobile app, or
// there is a privacy setting on the frontend which doesn't send
// the origin
} else {
if origin == "https://test.example.com" {
// query from the test site
return "https://test.example.com", nil
} else if origin == "http://localhost:3000" {
// query from local development
return "http://localhost:3000", nil
}
}
}
// in case the origin is unknown or not set, we return a default
// value which will be used for this request.
return "https://test.example.com", nil
},
// highlight-end
},
RecipeList: []supertokens.Recipe{ /*...*/ },
})

if err != nil {
panic(err.Error())
}
}
```

</TabItem>
<TabItem value="python">
Expand All @@ -81,7 +126,7 @@ Coming Soon
</TabItem>
</BackendSDKTabs>

- We remove the `websiteDomain` config in the `appInfo` config, and replace it with the `origin` config as shown above.
- We remove the `websiteDomain` config in the `appInfo` config, and replace it with the `origin` config (`GetOrigin` for Golang) as shown above.
- The `origin` config is a function that takes an optional request object, and returns a string representing the domain of the request. We first check for if the `request` is not provided, and if not, then we fallback on a default value. If it is provided, then we attempt to read the `origin` header from the request and return a domain based on that.
- There may be cases where the `origin` header is not set, in which case we fallback on the default value once again. This can happen for:
- Mobile app frontends.
Expand Down
53 changes: 49 additions & 4 deletions v2/passwordless/common-customizations/multiple-clients.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,54 @@ supertokens.init({

<TabItem value="go">

:::note
Coming Soon
:::
```go
import (
"net/http"

"github.com/supertokens/supertokens-golang/supertokens"
)

func main() {
err := supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "...",
APIKey: "...",
},
AppInfo: supertokens.AppInfo{
AppName: "...",
APIDomain: "...",
// highlight-start
GetOrigin: func(request *http.Request, userContext supertokens.UserContext) (string, error) {
if request != nil {
origin := request.Header.Get("origin")
if origin == "" {
// this means the client is in an iframe, it's a mobile app, or
// there is a privacy setting on the frontend which doesn't send
// the origin
} else {
if origin == "https://test.example.com" {
// query from the test site
return "https://test.example.com", nil
} else if origin == "http://localhost:3000" {
// query from local development
return "http://localhost:3000", nil
}
}
}
// in case the origin is unknown or not set, we return a default
// value which will be used for this request.
return "https://test.example.com", nil
},
// highlight-end
},
RecipeList: []supertokens.Recipe{ /*...*/ },
})

if err != nil {
panic(err.Error())
}
}
```

</TabItem>
<TabItem value="python">
Expand All @@ -81,7 +126,7 @@ Coming Soon
</TabItem>
</BackendSDKTabs>

- We remove the `websiteDomain` config in the `appInfo` config, and replace it with the `origin` config as shown above.
- We remove the `websiteDomain` config in the `appInfo` config, and replace it with the `origin` config (`GetOrigin` for Golang) as shown above.
- The `origin` config is a function that takes an optional request object, and returns a string representing the domain of the request. We first check for if the `request` is not provided, and if not, then we fallback on a default value. If it is provided, then we attempt to read the `origin` header from the request and return a domain based on that.
- There may be cases where the `origin` header is not set, in which case we fallback on the default value once again. This can happen for:
- Mobile app frontends.
Expand Down
2 changes: 1 addition & 1 deletion v2/src/plugins/codeTypeChecking/goEnv/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-chi/cors v1.2.1
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/supertokens/supertokens-golang v0.16.5
github.com/supertokens/supertokens-golang v0.17.1-0.20231125104805-1f08095a133e
)

require (
Expand Down
4 changes: 2 additions & 2 deletions v2/src/plugins/codeTypeChecking/goEnv/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/supertokens/supertokens-golang v0.16.5 h1:05I6qfDjkuLAKvTEIdTIZvhKG5+NmTI+JVl2e61odKo=
github.com/supertokens/supertokens-golang v0.16.5/go.mod h1:/n6zQ9461RscnnWB4Y4bWwzhPivnj8w79j/doqkLOs8=
github.com/supertokens/supertokens-golang v0.17.1-0.20231125104805-1f08095a133e h1:esMJPRbqTHFZwCvW4hrOcaA/IXU/5psgRluk1mtak6k=
github.com/supertokens/supertokens-golang v0.17.1-0.20231125104805-1f08095a133e/go.mod h1:/n6zQ9461RscnnWB4Y4bWwzhPivnj8w79j/doqkLOs8=
github.com/twilio/twilio-go v0.26.0 h1:wFW4oTe3/LKt6bvByP7eio8JsjtaLHjMQKOUEzQry7U=
github.com/twilio/twilio-go v0.26.0/go.mod h1:lz62Hopu4vicpQ056H5TJ0JE4AP0rS3sQ35/ejmgOwE=
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
Expand Down
53 changes: 49 additions & 4 deletions v2/thirdparty/common-customizations/multiple-clients.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,54 @@ supertokens.init({

<TabItem value="go">

:::note
Coming Soon
:::
```go
import (
"net/http"

"github.com/supertokens/supertokens-golang/supertokens"
)

func main() {
err := supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "...",
APIKey: "...",
},
AppInfo: supertokens.AppInfo{
AppName: "...",
APIDomain: "...",
// highlight-start
GetOrigin: func(request *http.Request, userContext supertokens.UserContext) (string, error) {
if request != nil {
origin := request.Header.Get("origin")
if origin == "" {
// this means the client is in an iframe, it's a mobile app, or
// there is a privacy setting on the frontend which doesn't send
// the origin
} else {
if origin == "https://test.example.com" {
// query from the test site
return "https://test.example.com", nil
} else if origin == "http://localhost:3000" {
// query from local development
return "http://localhost:3000", nil
}
}
}
// in case the origin is unknown or not set, we return a default
// value which will be used for this request.
return "https://test.example.com", nil
},
// highlight-end
},
RecipeList: []supertokens.Recipe{ /*...*/ },
})

if err != nil {
panic(err.Error())
}
}
```

</TabItem>
<TabItem value="python">
Expand All @@ -81,7 +126,7 @@ Coming Soon
</TabItem>
</BackendSDKTabs>

- We remove the `websiteDomain` config in the `appInfo` config, and replace it with the `origin` config as shown above.
- We remove the `websiteDomain` config in the `appInfo` config, and replace it with the `origin` config (`GetOrigin` for Golang) as shown above.
- The `origin` config is a function that takes an optional request object, and returns a string representing the domain of the request. We first check for if the `request` is not provided, and if not, then we fallback on a default value. If it is provided, then we attempt to read the `origin` header from the request and return a domain based on that.
- There may be cases where the `origin` header is not set, in which case we fallback on the default value once again. This can happen for:
- Mobile app frontends.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,54 @@ supertokens.init({

<TabItem value="go">

:::note
Coming Soon
:::
```go
import (
"net/http"

"github.com/supertokens/supertokens-golang/supertokens"
)

func main() {
err := supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "...",
APIKey: "...",
},
AppInfo: supertokens.AppInfo{
AppName: "...",
APIDomain: "...",
// highlight-start
GetOrigin: func(request *http.Request, userContext supertokens.UserContext) (string, error) {
if request != nil {
origin := request.Header.Get("origin")
if origin == "" {
// this means the client is in an iframe, it's a mobile app, or
// there is a privacy setting on the frontend which doesn't send
// the origin
} else {
if origin == "https://test.example.com" {
// query from the test site
return "https://test.example.com", nil
} else if origin == "http://localhost:3000" {
// query from local development
return "http://localhost:3000", nil
}
}
}
// in case the origin is unknown or not set, we return a default
// value which will be used for this request.
return "https://test.example.com", nil
},
// highlight-end
},
RecipeList: []supertokens.Recipe{ /*...*/ },
})

if err != nil {
panic(err.Error())
}
}
```

</TabItem>
<TabItem value="python">
Expand All @@ -81,7 +126,7 @@ Coming Soon
</TabItem>
</BackendSDKTabs>

- We remove the `websiteDomain` config in the `appInfo` config, and replace it with the `origin` config as shown above.
- We remove the `websiteDomain` config in the `appInfo` config, and replace it with the `origin` config (`GetOrigin` for Golang) as shown above.
- The `origin` config is a function that takes an optional request object, and returns a string representing the domain of the request. We first check for if the `request` is not provided, and if not, then we fallback on a default value. If it is provided, then we attempt to read the `origin` header from the request and return a domain based on that.
- There may be cases where the `origin` header is not set, in which case we fallback on the default value once again. This can happen for:
- Mobile app frontends.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,54 @@ supertokens.init({

<TabItem value="go">

:::note
Coming Soon
:::
```go
import (
"net/http"

"github.com/supertokens/supertokens-golang/supertokens"
)

func main() {
err := supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "...",
APIKey: "...",
},
AppInfo: supertokens.AppInfo{
AppName: "...",
APIDomain: "...",
// highlight-start
GetOrigin: func(request *http.Request, userContext supertokens.UserContext) (string, error) {
if request != nil {
origin := request.Header.Get("origin")
if origin == "" {
// this means the client is in an iframe, it's a mobile app, or
// there is a privacy setting on the frontend which doesn't send
// the origin
} else {
if origin == "https://test.example.com" {
// query from the test site
return "https://test.example.com", nil
} else if origin == "http://localhost:3000" {
// query from local development
return "http://localhost:3000", nil
}
}
}
// in case the origin is unknown or not set, we return a default
// value which will be used for this request.
return "https://test.example.com", nil
},
// highlight-end
},
RecipeList: []supertokens.Recipe{ /*...*/ },
})

if err != nil {
panic(err.Error())
}
}
```

</TabItem>
<TabItem value="python">
Expand All @@ -81,7 +126,7 @@ Coming Soon
</TabItem>
</BackendSDKTabs>

- We remove the `websiteDomain` config in the `appInfo` config, and replace it with the `origin` config as shown above.
- We remove the `websiteDomain` config in the `appInfo` config, and replace it with the `origin` config (`GetOrigin` for Golang) as shown above.
- The `origin` config is a function that takes an optional request object, and returns a string representing the domain of the request. We first check for if the `request` is not provided, and if not, then we fallback on a default value. If it is provided, then we attempt to read the `origin` header from the request and return a domain based on that.
- There may be cases where the `origin` header is not set, in which case we fallback on the default value once again. This can happen for:
- Mobile app frontends.
Expand Down

0 comments on commit 2505daf

Please sign in to comment.