diff --git a/v2/emailpassword/advanced-customizations/backend-sdk-core-interceptor.mdx b/v2/emailpassword/advanced-customizations/backend-sdk-core-interceptor.mdx new file mode 100644 index 000000000..b8686379c --- /dev/null +++ b/v2/emailpassword/advanced-customizations/backend-sdk-core-interceptor.mdx @@ -0,0 +1,131 @@ +--- +id: backend-sdk-core-interceptor +title: Backend SDK Core Interceptor +hide_title: true +--- + +import BackendSDKTabs from "/src/components/tabs/BackendSDKTabs" +import TabItem from '@theme/TabItem'; + + + + +# Backend SDK Core Interceptor + +:::important +This feature is only available for SDKs versions: +- NodeJS >= `v16.5.0` +- Python >= `v0.16.8` +- GoLang >= `v0.6.6` +::: + +This hook can be used to intercept all outgoing requests from the backend SDK to the core. The request can be captured and modified before it is sent to the core. + +Users can modify the HTTP method, query params, headers and body of the request. + +## Example Use + + + + +```tsx +import { HttpRequest } from "supertokens-node/types"; +import SuperTokens from "supertokens-node"; + +SuperTokens.init({ + supertokens: { + connectionURI: "...", + apiKey: "...", + // highlight-start + networkInterceptor: (request: HttpRequest, userContext: any) => { + console.log("http request to core: ", request) + // this can also be used to return a modified request object. + return request; + }, + // highlight-end + }, + appInfo: { + apiDomain: "...", + appName: "...", + websiteDomain: "...", + }, + recipeList: [ + // ... + ], +}); +``` + + + + +```go +import ( + "log" + "net/http" + + "github.com/supertokens/supertokens-golang/supertokens" +) + +func main() { +supertokens.Init(supertokens.TypeInput{ + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "...", + APIKey: "...", + // highlight-start + NetworkInterceptor: func(request *http.Request, context supertokens.UserContext) *http.Request { + log.Print("http request to core: %+v", request) + return request + }, + // highlight-end + }, + AppInfo: supertokens.AppInfo{ + AppName: "...", + APIDomain: "...", + WebsiteDomain: "...", + }, + RecipeList: []supertokens.Recipe{/*...*/}, + }) +} +``` + + + + +```python +from typing import Dict, Any, Optional +from supertokens_python import init, InputAppInfo, SupertokensConfig + +# highlight-start +def intercept( + url: str, + method: str, + headers: Dict[str, Any], + params: Optional[Dict[str, Any]], + body: Optional[Dict[str, Any]], + user_context: Optional[Dict[str, Any]], +): + print("http request to core: ", url, method, headers, params, body) + return url, method, headers, params, body +# highlight-end + +init( + app_info=InputAppInfo( + app_name="...", + api_domain="...", + website_domain="...", + ), + supertokens_config=SupertokensConfig( + connection_uri="...", + api_key="...", + # highlight-next-line + network_interceptor=intercept, + ), + framework="django", # works with other frameworks as well + recipe_list=[ + # ... + ], +) +``` + + + \ No newline at end of file diff --git a/v2/emailpassword/sidebars.js b/v2/emailpassword/sidebars.js index 59f3d706c..ba790fb69 100644 --- a/v2/emailpassword/sidebars.js +++ b/v2/emailpassword/sidebars.js @@ -576,6 +576,7 @@ module.exports = { ], }, "advanced-customizations/user-context", + "advanced-customizations/backend-sdk-core-interceptor" ], }, { diff --git a/v2/passwordless/advanced-customizations/backend-sdk-core-interceptor.mdx b/v2/passwordless/advanced-customizations/backend-sdk-core-interceptor.mdx new file mode 100644 index 000000000..930142770 --- /dev/null +++ b/v2/passwordless/advanced-customizations/backend-sdk-core-interceptor.mdx @@ -0,0 +1,131 @@ +--- +id: backend-sdk-core-interceptor +title: Backend SDK Core Interceptor +hide_title: true +--- + +import BackendSDKTabs from "/src/components/tabs/BackendSDKTabs" +import TabItem from '@theme/TabItem'; + + + + +# Backend SDK Core Interceptor + +:::important +This feature is only available for SDKs versions: +- NodeJS >= `v16.5.0` +- Python >= `v0.16.8` +- GoLang >= `v0.6.6` +::: + +This hook can be used to intercept all outgoing requests from the backend SDK to the core. The request can be captured and modified before it is sent to the core. + +Users can modify the HTTP method, query params, headers and body of the request. + +## Example Use + + + + +```tsx +import { HttpRequest } from "supertokens-node/types"; +import SuperTokens from "supertokens-node"; + +SuperTokens.init({ + supertokens: { + connectionURI: "...", + apiKey: "...", + // highlight-start + networkInterceptor: (request: HttpRequest, userContext: any) => { + console.log("http request to core: ", request) + // this can also be used to return a modified request object. + return request; + }, + // highlight-end + }, + appInfo: { + apiDomain: "...", + appName: "...", + websiteDomain: "...", + }, + recipeList: [ + // ... + ], +}); +``` + + + + +```go +import ( + "log" + "net/http" + + "github.com/supertokens/supertokens-golang/supertokens" +) + +func main() { +supertokens.Init(supertokens.TypeInput{ + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "...", + APIKey: "...", + // highlight-start + NetworkInterceptor: func(request *http.Request, context supertokens.UserContext) *http.Request { + log.Print("http request to core: %+v", request) + return request + }, + // highlight-end + }, + AppInfo: supertokens.AppInfo{ + AppName: "...", + APIDomain: "...", + WebsiteDomain: "...", + }, + RecipeList: []supertokens.Recipe{/*...*/}, + }) +} +``` + + + + +```python +from typing import Dict, Any, Optional +from supertokens_python import init, InputAppInfo, SupertokensConfig + +# highlight-start +def intercept( + url: str, + method: str, + headers: Dict[str, Any], + params: Optional[Dict[str, Any]], + body: Optional[Dict[str, Any]], + user_context: Optional[Dict[str, Any]], +): + print("http request to core: ", url, method, headers, params, body) + return url, method, headers, params, body +# highlight-end + +init( + app_info=InputAppInfo( + app_name="...", + api_domain="...", + website_domain="...", + ), + supertokens_config=SupertokensConfig( + connection_uri="...", + api_key="...", + # highlight-next-line + network_interceptor=intercept, + ), + framework="django", # works with other frameworks as well + recipe_list=[ + # ... + ], +) +``` + + + diff --git a/v2/passwordless/sidebars.js b/v2/passwordless/sidebars.js index 18ee657e4..99f1b3b68 100644 --- a/v2/passwordless/sidebars.js +++ b/v2/passwordless/sidebars.js @@ -560,6 +560,7 @@ module.exports = { ], }, "advanced-customizations/user-context", + "advanced-customizations/backend-sdk-core-interceptor" ], }, { diff --git a/v2/session/advanced-customizations/backend-sdk-core-interceptor.mdx b/v2/session/advanced-customizations/backend-sdk-core-interceptor.mdx new file mode 100644 index 000000000..b8686379c --- /dev/null +++ b/v2/session/advanced-customizations/backend-sdk-core-interceptor.mdx @@ -0,0 +1,131 @@ +--- +id: backend-sdk-core-interceptor +title: Backend SDK Core Interceptor +hide_title: true +--- + +import BackendSDKTabs from "/src/components/tabs/BackendSDKTabs" +import TabItem from '@theme/TabItem'; + + + + +# Backend SDK Core Interceptor + +:::important +This feature is only available for SDKs versions: +- NodeJS >= `v16.5.0` +- Python >= `v0.16.8` +- GoLang >= `v0.6.6` +::: + +This hook can be used to intercept all outgoing requests from the backend SDK to the core. The request can be captured and modified before it is sent to the core. + +Users can modify the HTTP method, query params, headers and body of the request. + +## Example Use + + + + +```tsx +import { HttpRequest } from "supertokens-node/types"; +import SuperTokens from "supertokens-node"; + +SuperTokens.init({ + supertokens: { + connectionURI: "...", + apiKey: "...", + // highlight-start + networkInterceptor: (request: HttpRequest, userContext: any) => { + console.log("http request to core: ", request) + // this can also be used to return a modified request object. + return request; + }, + // highlight-end + }, + appInfo: { + apiDomain: "...", + appName: "...", + websiteDomain: "...", + }, + recipeList: [ + // ... + ], +}); +``` + + + + +```go +import ( + "log" + "net/http" + + "github.com/supertokens/supertokens-golang/supertokens" +) + +func main() { +supertokens.Init(supertokens.TypeInput{ + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "...", + APIKey: "...", + // highlight-start + NetworkInterceptor: func(request *http.Request, context supertokens.UserContext) *http.Request { + log.Print("http request to core: %+v", request) + return request + }, + // highlight-end + }, + AppInfo: supertokens.AppInfo{ + AppName: "...", + APIDomain: "...", + WebsiteDomain: "...", + }, + RecipeList: []supertokens.Recipe{/*...*/}, + }) +} +``` + + + + +```python +from typing import Dict, Any, Optional +from supertokens_python import init, InputAppInfo, SupertokensConfig + +# highlight-start +def intercept( + url: str, + method: str, + headers: Dict[str, Any], + params: Optional[Dict[str, Any]], + body: Optional[Dict[str, Any]], + user_context: Optional[Dict[str, Any]], +): + print("http request to core: ", url, method, headers, params, body) + return url, method, headers, params, body +# highlight-end + +init( + app_info=InputAppInfo( + app_name="...", + api_domain="...", + website_domain="...", + ), + supertokens_config=SupertokensConfig( + connection_uri="...", + api_key="...", + # highlight-next-line + network_interceptor=intercept, + ), + framework="django", # works with other frameworks as well + recipe_list=[ + # ... + ], +) +``` + + + \ No newline at end of file diff --git a/v2/session/sidebars.js b/v2/session/sidebars.js index 90aabb905..839fae587 100644 --- a/v2/session/sidebars.js +++ b/v2/session/sidebars.js @@ -267,7 +267,9 @@ module.exports = { "advanced-customizations/frontend-hooks/pre-api", "advanced-customizations/frontend-hooks/handle-event" ], - },], + }, + "advanced-customizations/backend-sdk-core-interceptor" + ], }, { type: "category", diff --git a/v2/src/plugins/codeTypeChecking/jsEnv/package.json b/v2/src/plugins/codeTypeChecking/jsEnv/package.json index bee304964..ca60f1d28 100644 --- a/v2/src/plugins/codeTypeChecking/jsEnv/package.json +++ b/v2/src/plugins/codeTypeChecking/jsEnv/package.json @@ -54,7 +54,7 @@ "socket.io": "^4.6.1", "socketio": "^1.0.0", "supertokens-auth-react": "^0.35.0", - "supertokens-node": "^16.4.0", + "supertokens-node": "^16.5.0", "supertokens-node7": "npm:supertokens-node@7.3", "supertokens-react-native": "^4.0.0", "supertokens-web-js": "^0.8.0", diff --git a/v2/thirdparty/advanced-customizations/backend-sdk-core-interceptor.mdx b/v2/thirdparty/advanced-customizations/backend-sdk-core-interceptor.mdx new file mode 100644 index 000000000..930142770 --- /dev/null +++ b/v2/thirdparty/advanced-customizations/backend-sdk-core-interceptor.mdx @@ -0,0 +1,131 @@ +--- +id: backend-sdk-core-interceptor +title: Backend SDK Core Interceptor +hide_title: true +--- + +import BackendSDKTabs from "/src/components/tabs/BackendSDKTabs" +import TabItem from '@theme/TabItem'; + + + + +# Backend SDK Core Interceptor + +:::important +This feature is only available for SDKs versions: +- NodeJS >= `v16.5.0` +- Python >= `v0.16.8` +- GoLang >= `v0.6.6` +::: + +This hook can be used to intercept all outgoing requests from the backend SDK to the core. The request can be captured and modified before it is sent to the core. + +Users can modify the HTTP method, query params, headers and body of the request. + +## Example Use + + + + +```tsx +import { HttpRequest } from "supertokens-node/types"; +import SuperTokens from "supertokens-node"; + +SuperTokens.init({ + supertokens: { + connectionURI: "...", + apiKey: "...", + // highlight-start + networkInterceptor: (request: HttpRequest, userContext: any) => { + console.log("http request to core: ", request) + // this can also be used to return a modified request object. + return request; + }, + // highlight-end + }, + appInfo: { + apiDomain: "...", + appName: "...", + websiteDomain: "...", + }, + recipeList: [ + // ... + ], +}); +``` + + + + +```go +import ( + "log" + "net/http" + + "github.com/supertokens/supertokens-golang/supertokens" +) + +func main() { +supertokens.Init(supertokens.TypeInput{ + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "...", + APIKey: "...", + // highlight-start + NetworkInterceptor: func(request *http.Request, context supertokens.UserContext) *http.Request { + log.Print("http request to core: %+v", request) + return request + }, + // highlight-end + }, + AppInfo: supertokens.AppInfo{ + AppName: "...", + APIDomain: "...", + WebsiteDomain: "...", + }, + RecipeList: []supertokens.Recipe{/*...*/}, + }) +} +``` + + + + +```python +from typing import Dict, Any, Optional +from supertokens_python import init, InputAppInfo, SupertokensConfig + +# highlight-start +def intercept( + url: str, + method: str, + headers: Dict[str, Any], + params: Optional[Dict[str, Any]], + body: Optional[Dict[str, Any]], + user_context: Optional[Dict[str, Any]], +): + print("http request to core: ", url, method, headers, params, body) + return url, method, headers, params, body +# highlight-end + +init( + app_info=InputAppInfo( + app_name="...", + api_domain="...", + website_domain="...", + ), + supertokens_config=SupertokensConfig( + connection_uri="...", + api_key="...", + # highlight-next-line + network_interceptor=intercept, + ), + framework="django", # works with other frameworks as well + recipe_list=[ + # ... + ], +) +``` + + + diff --git a/v2/thirdparty/sidebars.js b/v2/thirdparty/sidebars.js index b1a9e862a..c3642087d 100644 --- a/v2/thirdparty/sidebars.js +++ b/v2/thirdparty/sidebars.js @@ -571,6 +571,7 @@ module.exports = { ], }, "advanced-customizations/user-context", + "advanced-customizations/backend-sdk-core-interceptor" ], }, { diff --git a/v2/thirdpartyemailpassword/advanced-customizations/backend-sdk-core-interceptor.mdx b/v2/thirdpartyemailpassword/advanced-customizations/backend-sdk-core-interceptor.mdx new file mode 100644 index 000000000..930142770 --- /dev/null +++ b/v2/thirdpartyemailpassword/advanced-customizations/backend-sdk-core-interceptor.mdx @@ -0,0 +1,131 @@ +--- +id: backend-sdk-core-interceptor +title: Backend SDK Core Interceptor +hide_title: true +--- + +import BackendSDKTabs from "/src/components/tabs/BackendSDKTabs" +import TabItem from '@theme/TabItem'; + + + + +# Backend SDK Core Interceptor + +:::important +This feature is only available for SDKs versions: +- NodeJS >= `v16.5.0` +- Python >= `v0.16.8` +- GoLang >= `v0.6.6` +::: + +This hook can be used to intercept all outgoing requests from the backend SDK to the core. The request can be captured and modified before it is sent to the core. + +Users can modify the HTTP method, query params, headers and body of the request. + +## Example Use + + + + +```tsx +import { HttpRequest } from "supertokens-node/types"; +import SuperTokens from "supertokens-node"; + +SuperTokens.init({ + supertokens: { + connectionURI: "...", + apiKey: "...", + // highlight-start + networkInterceptor: (request: HttpRequest, userContext: any) => { + console.log("http request to core: ", request) + // this can also be used to return a modified request object. + return request; + }, + // highlight-end + }, + appInfo: { + apiDomain: "...", + appName: "...", + websiteDomain: "...", + }, + recipeList: [ + // ... + ], +}); +``` + + + + +```go +import ( + "log" + "net/http" + + "github.com/supertokens/supertokens-golang/supertokens" +) + +func main() { +supertokens.Init(supertokens.TypeInput{ + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "...", + APIKey: "...", + // highlight-start + NetworkInterceptor: func(request *http.Request, context supertokens.UserContext) *http.Request { + log.Print("http request to core: %+v", request) + return request + }, + // highlight-end + }, + AppInfo: supertokens.AppInfo{ + AppName: "...", + APIDomain: "...", + WebsiteDomain: "...", + }, + RecipeList: []supertokens.Recipe{/*...*/}, + }) +} +``` + + + + +```python +from typing import Dict, Any, Optional +from supertokens_python import init, InputAppInfo, SupertokensConfig + +# highlight-start +def intercept( + url: str, + method: str, + headers: Dict[str, Any], + params: Optional[Dict[str, Any]], + body: Optional[Dict[str, Any]], + user_context: Optional[Dict[str, Any]], +): + print("http request to core: ", url, method, headers, params, body) + return url, method, headers, params, body +# highlight-end + +init( + app_info=InputAppInfo( + app_name="...", + api_domain="...", + website_domain="...", + ), + supertokens_config=SupertokensConfig( + connection_uri="...", + api_key="...", + # highlight-next-line + network_interceptor=intercept, + ), + framework="django", # works with other frameworks as well + recipe_list=[ + # ... + ], +) +``` + + + diff --git a/v2/thirdpartyemailpassword/sidebars.js b/v2/thirdpartyemailpassword/sidebars.js index 120b20975..097aa483e 100644 --- a/v2/thirdpartyemailpassword/sidebars.js +++ b/v2/thirdpartyemailpassword/sidebars.js @@ -616,7 +616,9 @@ module.exports = { "advanced-customizations/frontend-hooks/redirection-callback" ], }, - "advanced-customizations/user-context",], + "advanced-customizations/user-context", + "advanced-customizations/backend-sdk-core-interceptor" + ], }, { type: "category", diff --git a/v2/thirdpartypasswordless/advanced-customizations/backend-sdk-core-interceptor.mdx b/v2/thirdpartypasswordless/advanced-customizations/backend-sdk-core-interceptor.mdx new file mode 100644 index 000000000..930142770 --- /dev/null +++ b/v2/thirdpartypasswordless/advanced-customizations/backend-sdk-core-interceptor.mdx @@ -0,0 +1,131 @@ +--- +id: backend-sdk-core-interceptor +title: Backend SDK Core Interceptor +hide_title: true +--- + +import BackendSDKTabs from "/src/components/tabs/BackendSDKTabs" +import TabItem from '@theme/TabItem'; + + + + +# Backend SDK Core Interceptor + +:::important +This feature is only available for SDKs versions: +- NodeJS >= `v16.5.0` +- Python >= `v0.16.8` +- GoLang >= `v0.6.6` +::: + +This hook can be used to intercept all outgoing requests from the backend SDK to the core. The request can be captured and modified before it is sent to the core. + +Users can modify the HTTP method, query params, headers and body of the request. + +## Example Use + + + + +```tsx +import { HttpRequest } from "supertokens-node/types"; +import SuperTokens from "supertokens-node"; + +SuperTokens.init({ + supertokens: { + connectionURI: "...", + apiKey: "...", + // highlight-start + networkInterceptor: (request: HttpRequest, userContext: any) => { + console.log("http request to core: ", request) + // this can also be used to return a modified request object. + return request; + }, + // highlight-end + }, + appInfo: { + apiDomain: "...", + appName: "...", + websiteDomain: "...", + }, + recipeList: [ + // ... + ], +}); +``` + + + + +```go +import ( + "log" + "net/http" + + "github.com/supertokens/supertokens-golang/supertokens" +) + +func main() { +supertokens.Init(supertokens.TypeInput{ + Supertokens: &supertokens.ConnectionInfo{ + ConnectionURI: "...", + APIKey: "...", + // highlight-start + NetworkInterceptor: func(request *http.Request, context supertokens.UserContext) *http.Request { + log.Print("http request to core: %+v", request) + return request + }, + // highlight-end + }, + AppInfo: supertokens.AppInfo{ + AppName: "...", + APIDomain: "...", + WebsiteDomain: "...", + }, + RecipeList: []supertokens.Recipe{/*...*/}, + }) +} +``` + + + + +```python +from typing import Dict, Any, Optional +from supertokens_python import init, InputAppInfo, SupertokensConfig + +# highlight-start +def intercept( + url: str, + method: str, + headers: Dict[str, Any], + params: Optional[Dict[str, Any]], + body: Optional[Dict[str, Any]], + user_context: Optional[Dict[str, Any]], +): + print("http request to core: ", url, method, headers, params, body) + return url, method, headers, params, body +# highlight-end + +init( + app_info=InputAppInfo( + app_name="...", + api_domain="...", + website_domain="...", + ), + supertokens_config=SupertokensConfig( + connection_uri="...", + api_key="...", + # highlight-next-line + network_interceptor=intercept, + ), + framework="django", # works with other frameworks as well + recipe_list=[ + # ... + ], +) +``` + + + diff --git a/v2/thirdpartypasswordless/sidebars.js b/v2/thirdpartypasswordless/sidebars.js index e21bab01c..2bd804b59 100644 --- a/v2/thirdpartypasswordless/sidebars.js +++ b/v2/thirdpartypasswordless/sidebars.js @@ -608,6 +608,7 @@ module.exports = { ], }, "advanced-customizations/user-context", + "advanced-customizations/backend-sdk-core-interceptor" ], }, {