Consumer Authentication

/

Mobile SDKs

/

React Native SDK reference

/

Time-Based One-Time Passcodes (TOTP)

/

Recover

Recover

Wraps Stytch's recover endpoint. Call this method to authenticate a recovery code for a TOTP instance.

If this method succeeds, the user will be logged in, granted an active session, and the session data will be persisted on device.

You can listen for successful login events anywhere in the codebase with the stytch.session.onChange() method or useStytchSession hook.


Method parameters


recovery_code*string

session_duration_minutes*int
import React, { useCallback, useState } from 'react';
import { Text, TouchableOpacity, View, TextInput } from 'react-native';
import { useStytch } from '@stytch/react-native';

export const UseTOTPRecoveryCode = () => {
  const stytch = useStytch();
  const [recoveryCode, setRecoveryCode] = useState('');
  const useTOTPRecoveryCode = useCallback(() => {
    stytch.totp.recover({
      recovery_code: recoveryCode,
      session_duration_minutes: 5,
    });
  }, [stytch, recoveryCode]);

  return (
    <View>
      <TextInput placeholder="123456" onChangeText={setRecoveryCode} />
      <TouchableOpacity onPress={useTOTPRecoveryCode}>
        <Text>Use TOTP Recovery Code</Text>
      </TouchableOpacity>
    </View>
  );
};

RESPONSE

200
{
    "status_code": 200,
    "request_id": "request-id-test-b05c992f-ebdc-489d-a754-c7e70ba13141",
    "totp_id": "totp-test-41920359-8bbb-4fe8-8fa3-aaa83f35f02c",
    "session": null,
    "session_jwt": "",
    "session_token": "",
    "user": {...},
    "user_id": "user-test-16d9ba61-97a1-4ba4-9720-b03761dc50c6"
  }