Consumer Authentication

/

Mobile SDKs

/

React Native SDK reference

/

OAuth

/

Authenticate

Authenticate

The authenticate method wraps the authenticate OAuth API endpoint which validates the OAuth token passed in.

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


token*string

Configuration*object

Additional configuration.

session_duration_minutes*int

Response fields


request_idstring

status_codeint

user_idstring

session_tokenstring

session_jwtstring

sessionobject

provider_subjectstring

provider_typestring
import { useStytch } from '@stytch/react-native';
import { useEffect, useState } from 'react';
import { Text } from 'react-native';

export const OAuthAuthenticate = ({ token }) => {
  const stytch = useStytch();
  const [sessionData, setSessionData] = useState();

  useEffect(() => {
    if (token && !sessionData) {
      stytch.oauth
        .authenticate(token, { session_duration_minutes: 60 })
        .then((resp) => setSessionData(resp));
    }
  }, [sessionData, stytch, token]);

  return sessionData && <Text>Hello, {sessionData?.user.name.first_name}</Text>;
};