/
Contact usSee pricingStart building
    Overview
    iOS SDK reference
    Android SDK reference

    React Native SDK reference

    Installation
    Changelog
    Configuration
    Pre-built UI
      UI Configuration
    Users
      Get user
      Update user
      Delete authentication factors
    Email Magic Links
      Send
      Login or create
      Authenticate
    OAuth
      Start
      Authenticate
    Passwords
      Create
      Authenticate
      Reset by Email Start
      Reset by Email
      Strength Check
    One-time Passcodes (OTP)
      Login or create via SMS
      Send via SMS
      Login or create via Email
      Send via Email
      Login or create via WhatsApp
      Send via WhatsApp
      Authenticate
    Time-Based One-Time Passcodes (TOTP)
      Create
      Authenticate
      Get Recovery Codes
      Recover
    Session Management
      Get Session
      Authenticate Session
      Revoke Session
      Update Session
      Get Tokens
    Passkeys & WebAuthn
      Register
      Authenticate
      Update
    Biometrics
      Introduction
      Register
      Authenticate
      Keystore available
      Registration available
      Remove registration
      Get sensor
      Errors
    Device Fingerprinting
      Get telemetry ID
    More Resources
      SWR & caching
      Deep linking
      Android KeyStore considerations
Get support on SlackVisit our developer forum

Contact us

Consumer Authentication

/

Mobile SDKs

/

React Native SDK reference

/

Time-Based One-Time Passcodes (TOTP)

/

Authenticate

Authenticate

Wraps Stytch's Authenticate endpoint. Call this method to authenticate a TOTP code entered by a user.

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


totp_code* string

session_duration_minutes* int

Response fields


request_id string

status_code int

totp_id string

user_id string

session object

session_jwt string

session_token string

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

export const AuthenticateTOTP = () => {
  const stytch = useStytch();
  const [totpCode, setTOTPCode] = useState('');
  const authenticateTotpCode = useCallback(() => {
    stytch.totp.authenticate({
      totp_code: totpCode,
      session_duration_minutes: 5,
    });
  }, [stytch, totpCode]);

  return (
    <View>
      <TextInput placeholder="123456" onChangeText={setTOTPCode} />
      <TouchableOpacity onPress={authenticateTotpCode}>
        <Text>Authenticate TOTP</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"
}