Skip to main content
import { useState } from 'react';
import { View, Button, Text, Image } from 'react-native';
import { useStytchB2BClient } from '@stytch/react-native/b2b';

export const CreateTOTP = () => {
  const stytch = useStytchB2BClient();
  const [totpData, setTotpData] = useState(null);

  const createTOTP = async () => {
    const response = await stytch.totps.create({
      organization_id: 'organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931',
      member_id: 'member-test-32fc5024-9c09-4da3-bd2e-c9698807585d',
      expiration_minutes: 60,
    });
    setTotpData(response);
    console.log('TOTP created:', response);
  };

  return (
    <View>
      <Button title="Create TOTP" onPress={createTOTP} />
      {totpData && (
        <View>
          <Text>Secret: {totpData.secret}</Text>
          <Image source={{ uri: totpData.qr_code }} />
        </View>
      )}
    </View>
  );
};
totp.create wraps the Create TOTP endpoint. Call this method to create a TOTP registration on an existing .

Parameters

organization_id
string
required
Globally unique UUID that identifies a specific Organization. You may also use the organization_slug or organization_external_id here as a convenience.
member_id
string
required
Globally unique UUID that identifies a specific Member. You may use an external_id here if one is set for the member.
expiration_minutes
number
The expiration for the TOTP registration. If the newly created TOTP registration is not authenticated within this time frame the member will have to restart the registration flow. Defaults to 60 (1 hour) with a minimum of 5 and a maximum of 1440.

Response

secret
string
The TOTP secret key shared between the authenticator app and the server used to generate TOTP codes.
totp_registration_id
string
The unique ID for a TOTP instance.
qr_code
string
The QR code image encoded in base64.
recovery_codes
string[]
An array of recovery codes that can be used to recover a Member’s account.
member_id
string
Globally unique UUID that identifies a specific Member.
member
object
request_id
string
Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
status_code
number
The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.