Callbacks
Callbacks are optional functions for the JavaScript SDK that allow you to do things like take actions in your app or send logs to your backend based on where your user is in the flow.
onEvent
A function that is called when the Stytch client makes a request. The function expects an argument of an event object, the event object has type and data objects.
/**
* An OAuth Authorization flow has been initiated by a Connected Application.
* The end-user may be prompted for consent to continue depending on the application
* that is requesting access.
*/
{
"type": "OAUTH_AUTHORIZE_FLOW_START",
"data": {
"client_id": "connected-app-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"redirect_uri": "http://localhost:3004/oauth/callback",
"scope": "openid profile email"
}
}
/**
* The end-user has completed the Authorization flow and is about to be redirected
* back to the Connected Application
*/
{
"type": "OAUTH_AUTHORIZE_FLOW_COMPLETE",
"data": {}
}
/**
* The end-user has denied the Authorization flow and is about to be redirected
* back to the Connected Application with an error message
*/
{
"type": "OAUTH_AUTHORIZE_FLOW_CONSENT_DENIED",
"data": {}
}
onError
A function that is called when an error occurs. The function expects an argument of an StytchError object, the StytchError object has a message property.
// Example of an API related error.
"message": "StytchSDKAPIError: [401] unauthorized_credentials Unauthorized credentials. See https://stytch.com/docs/api/errors/401 for more information. request_id: request-id-test-8e2a9758-713e-49a2-8b62-f9169bbabded",
// Example of a network related error.
"message": "SDKAPIUnreachableError: Failed to send magic link Unable to contact the Stytch servers. Are you online?"
// Example of a schema related error.
"message": "StytchSDKSchemaError: [400] Request does not match expected schema. email: should be string"
// Example of an error with using our SDK.
"message": "StytchSDKUsageError: Invalid call to <METHOD_NAME>"