diff --git a/v2/emailpassword/common-customizations/multiple-clients.mdx b/v2/emailpassword/common-customizations/multiple-clients.mdx index 26b83f924..043d8f5d2 100644 --- a/v2/emailpassword/common-customizations/multiple-clients.mdx +++ b/v2/emailpassword/common-customizations/multiple-clients.mdx @@ -67,9 +67,54 @@ supertokens.init({ -:::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()) + } +} +``` @@ -81,7 +126,7 @@ Coming Soon -- 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. diff --git a/v2/passwordless/common-customizations/multiple-clients.mdx b/v2/passwordless/common-customizations/multiple-clients.mdx index 26b83f924..043d8f5d2 100644 --- a/v2/passwordless/common-customizations/multiple-clients.mdx +++ b/v2/passwordless/common-customizations/multiple-clients.mdx @@ -67,9 +67,54 @@ supertokens.init({ -:::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()) + } +} +``` @@ -81,7 +126,7 @@ Coming Soon -- 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. diff --git a/v2/src/plugins/codeTypeChecking/goEnv/go.mod b/v2/src/plugins/codeTypeChecking/goEnv/go.mod index 66cb6f900..9647b330d 100644 --- a/v2/src/plugins/codeTypeChecking/goEnv/go.mod +++ b/v2/src/plugins/codeTypeChecking/goEnv/go.mod @@ -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 ( diff --git a/v2/src/plugins/codeTypeChecking/goEnv/go.sum b/v2/src/plugins/codeTypeChecking/goEnv/go.sum index ee0b00bf6..e16ba0d01 100644 --- a/v2/src/plugins/codeTypeChecking/goEnv/go.sum +++ b/v2/src/plugins/codeTypeChecking/goEnv/go.sum @@ -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= diff --git a/v2/thirdparty/common-customizations/multiple-clients.mdx b/v2/thirdparty/common-customizations/multiple-clients.mdx index 26b83f924..043d8f5d2 100644 --- a/v2/thirdparty/common-customizations/multiple-clients.mdx +++ b/v2/thirdparty/common-customizations/multiple-clients.mdx @@ -67,9 +67,54 @@ supertokens.init({ -:::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()) + } +} +``` @@ -81,7 +126,7 @@ Coming Soon -- 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. diff --git a/v2/thirdpartyemailpassword/common-customizations/multiple-clients.mdx b/v2/thirdpartyemailpassword/common-customizations/multiple-clients.mdx index 01c23f872..b8243085c 100644 --- a/v2/thirdpartyemailpassword/common-customizations/multiple-clients.mdx +++ b/v2/thirdpartyemailpassword/common-customizations/multiple-clients.mdx @@ -67,9 +67,54 @@ supertokens.init({ -:::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()) + } +} +``` @@ -81,7 +126,7 @@ Coming Soon -- 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. diff --git a/v2/thirdpartypasswordless/common-customizations/multiple-clients.mdx b/v2/thirdpartypasswordless/common-customizations/multiple-clients.mdx index 26b83f924..043d8f5d2 100644 --- a/v2/thirdpartypasswordless/common-customizations/multiple-clients.mdx +++ b/v2/thirdpartypasswordless/common-customizations/multiple-clients.mdx @@ -67,9 +67,54 @@ supertokens.init({ -:::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()) + } +} +``` @@ -81,7 +126,7 @@ Coming Soon -- 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.