-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #753 from supertokens/feat/network-interceptor-hook
feat: adds docs for `networkInterceptor`
- Loading branch information
Showing
13 changed files
with
797 additions
and
3 deletions.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
v2/emailpassword/advanced-customizations/backend-sdk-core-interceptor.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
|
||
<!-- COPY DOCS --> | ||
<!-- ./emailpassword/advanced-customizations/backend-sdk-core-interceptor.mdx --> | ||
|
||
# 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 | ||
|
||
<BackendSDKTabs> | ||
<TabItem value="nodejs"> | ||
|
||
```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: [ | ||
// ... | ||
], | ||
}); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="go"> | ||
|
||
```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{/*...*/}, | ||
}) | ||
} | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="python"> | ||
|
||
```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=[ | ||
# ... | ||
], | ||
) | ||
``` | ||
|
||
</TabItem> | ||
</BackendSDKTabs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
v2/passwordless/advanced-customizations/backend-sdk-core-interceptor.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
|
||
<!-- COPY DOCS --> | ||
<!-- ./emailpassword/advanced-customizations/backend-sdk-core-interceptor.mdx --> | ||
|
||
# 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 | ||
|
||
<BackendSDKTabs> | ||
<TabItem value="nodejs"> | ||
|
||
```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: [ | ||
// ... | ||
], | ||
}); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="go"> | ||
|
||
```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{/*...*/}, | ||
}) | ||
} | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="python"> | ||
|
||
```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=[ | ||
# ... | ||
], | ||
) | ||
``` | ||
|
||
</TabItem> | ||
</BackendSDKTabs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.