The Authenticate Discovery Email OTP method wraps the authenticate discovery email OTP API endpoint, which validates the discovery code passed in. If this method succeeds, the intermediate session token will be stored in the browser as a cookie.
Authenticate discovery magic link
Method parameters
code* string
email_address* string
import React, { useCallback, useState } from 'react';
import { useStytchB2BClient } from '@stytch/react/b2b';
export const DiscoveryAuthenticate = () => {
const stytch = useStytchB2BClient();
const [code, setCode] = useState('');
// email used during discovery loginOrCreate
const email = 'sandbox@stytch.com';
const authenticate = async () => {
const { intermediate_session_token, email_address, discovered_organizations } =
await stytch.otps.email.discovery.authenticate({ email_address: email, code });
console.log({ intermediate_session_token, email_address, discovered_organizations });
};
const handleChange = useCallback((e) => {
setCode(e.target.value);
}, []);
return (
<form>
<label htmlFor="otp-input">Enter code</label>
<input id="otp-input" autoComplete="one-time-code" inputMode="numeric" pattern="[0-9]*" onChange={handleChange} />
<button onClick={authenticate} type="submit">
Submit
</button>
</form>
);
};
RESPONSE
200
{
"request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
"status_code": 200,
"intermediate_session_token": "SeiGwdj5lKkrEVgcEY3QNJXt6srxS3IK2Nwkar6mXD4=",
"email_address": "sandbox@stytch.com",
"discovered_organizations": [{...}, {...}]
}