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 authentication flow.
onEvent
A function that is called when the Stytch client makes a request. The function expects an argument of an event object, and the event object has type and data objects.
{
"type": "B2B_MAGIC_LINK_EMAIL_LOGIN_OR_SIGNUP",
"data": {
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
{
"type": "B2B_MAGIC_LINK_AUTHENTICATE",
"data": {
"method_id": "member-email-test-1dd089b3-8904-47ef-b943-987968e549d4",
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
"session_jwt": "example_jwt",
"member_session": { ...Stytch member session... },
"member_authenticated": true,
"intermediate_session_token": "",
"mfa_required": {
"member_options": {
"mfa_phone_number": "+12025550162"
},
"secondary_auth_initiated": null
},
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
{
"type": "B2B_MAGIC_LINK_EMAIL_DISCOVERY_SEND",
"data": {
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
{
"type": "B2B_MAGIC_LINK_DISCOVERY_AUTHENTICATE",
"data": {
"email_address": "sandbox@stytch.com",
"intermediate_session_token": "SeiGwdj5lKkrEVgcEY3QNJXt6srxS3IK2Nwkar6mXD4=",
"discovered_organizations": [{ ...Stytch organization... }, { ...Stytch organization... }],
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
{
"type": "B2B_SSO_START",
"data": {}
},
{
"type": "B2B_SSO_AUTHENTICATE",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
"session_jwt": "example_jwt",
"member_session": { ...Stytch member session... },
"member_authenticated": true,
"intermediate_session_token": "",
"mfa_required": {
"member_options": {
"mfa_phone_number": "+12025550162"
},
"secondary_auth_initiated": null
},
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
{
"type": "B2B_DISCOVERY_ORGANIZATIONS_CREATE",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
"session_jwt": "example_jwt",
"member_session": { ...Stytch member session... },
"member_authenticated": true,
"intermediate_session_token": "",
"mfa_required": {
"member_options": {
"mfa_phone_number": "+12025550162"
},
"secondary_auth_initiated": null
},
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
{
"type": "B2B_DISCOVERY_INTERMEDIATE_SESSION_EXCHANGE",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
"session_jwt": "example_jwt",
"member_session": { ...Stytch member session... },
"member_authenticated": true,
"intermediate_session_token": "",
"mfa_required": {
"member_options": {
"mfa_phone_number": "+12025550162"
},
"secondary_auth_initiated": null
},
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
{
"type": "B2B_PASSWORD_AUTHENTICATE",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
"session_jwt": "example_jwt",
"member_session": { ...Stytch member session... },
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
{
"type": "B2B_PASSWORD_RESET_BY_EMAIL_START",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
{
"type": "B2B_PASSWORD_RESET_BY_EMAIL",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
"session_jwt": "example_jwt",
"member_session": { ...Stytch member session... },
"member_authenticated": true,
"intermediate_session_token": "",
"mfa_required": {
"member_options": {
"mfa_phone_number": "+12025550162"
},
"secondary_auth_initiated": null
},
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
{
"type": "B2B_PASSWORD_RESET_BY_SESSION",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
"session_jwt": "example_jwt",
"member_session": { ...Stytch member session... },
"member_authenticated": true,
"intermediate_session_token": "",
"mfa_required": {
"member_options": {
"mfa_phone_number": "+12025550162"
},
"secondary_auth_initiated": null
},
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
},
},
{
{
"type": "B2B_SMS_OTP_SEND",
"data": {
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
},
{
{
"type": "B2B_SMS_OTP_AUTHENTICATE",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
"session_jwt": "example_jwt",
"member_session": { ...Stytch member session... },
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
},
{
{
"type": "B2B_TOTP_CREATE",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"qr_code": "data:image/png;base64,...",
"recovery_codes": ["abcd-efgh-1234", "ijkl-mnop-5678", "qrst-uvwx-9012"],
"secret": "X4YCZUQATXPVO46J2EDTZY55NLTQZDQA",
"totp_registration_id": "member-totp-test-9ed17883-fdfa-4795-9459-cd64a2bf351f",
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
},
{
{
"type": "B2B_TOTP_AUTHENTICATE",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
"session_jwt": "example_jwt",
"member_session": { ...Stytch member session... },
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
},
},
{
{
"type": "B2B_RECOVERY_CODES_RECOVER",
"data": {
"member_id": "member-test-32fc5024-9c09-4da3-bd2e-c9ce4da9375f",
"member": { ...Stytch member... },
"organization": { ...Stytch organization... },
"session_token": "mZAYn5aLEqKUlZ_Ad9U_fWr38GaAQ1oFAhT8ds245v7Q",
"session_jwt": "example_jwt",
"member_session": { ...Stytch member session... },
"recovery_codes_remaining": 9,
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200
}
}
}
onError
A function that is called when an error occurs. The function expects an argument of an StytchError object, and 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>"