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- NodeJS
- GoLang
- Python
- Other Frameworks
Important
For other backend frameworks, you can follow our guide on how to spin up a separate server configured with the SuperTokens backend SDK to authenticate requests and issue session tokens.
import { HttpRequest } from "supertokens-node/types";
import SuperTokens from "supertokens-node";
SuperTokens.init({
supertokens: {
connectionURI: "...",
apiKey: "...",
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;
},
},
appInfo: {
apiDomain: "...",
appName: "...",
websiteDomain: "...",
},
recipeList: [
// ...
],
});
import (
"log"
"net/http"
"github.com/supertokens/supertokens-golang/supertokens"
)
func main() {
supertokens.Init(supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "...",
APIKey: "...",
NetworkInterceptor: func(request *http.Request, context supertokens.UserContext) *http.Request {
log.Print("http request to core: %+v", request)
return request
},
},
AppInfo: supertokens.AppInfo{
AppName: "...",
APIDomain: "...",
WebsiteDomain: "...",
},
RecipeList: []supertokens.Recipe{/*...*/},
})
}
from typing import Dict, Any, Optional
from supertokens_python import init, InputAppInfo, SupertokensConfig
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
init(
app_info=InputAppInfo(
app_name="...",
api_domain="...",
website_domain="...",
),
supertokens_config=SupertokensConfig(
connection_uri="...",
api_key="...",
network_interceptor=intercept,
),
framework="django", # works with other frameworks as well
recipe_list=[
# ...
],
)