Consumer Authentication

/

Mobile SDKs

/

React Native SDK reference

/

Session Management

/

Get Tokens

Get tokens

Returns the session_token and session_jwt for the active session. Otherwise retuns null.

import { useState } from 'react';
import { SessionTokens, useStytch } from '@stytch/react-native';
import { Text, TouchableOpacity, View } from 'react-native';

export const GetSessionTokens = () => {
  const stytch = useStytch();
  const [sessionTokens, setSessionTokens] = useState<SessionTokens | null>(null);

  // Callback to retrieve session tokens on demand
  const handleGetTokens = () => {
    const tokens = stytch.session.getTokens();
    setSessionTokens(tokens);
  };

  return (
    <View>
      <TouchableOpacity onPress={handleGetTokens}>Get Session Tokens</TouchableOpacity>
      {sessionTokens && (
        <View>
          <Text>Session Token: {sessionTokens.session_token}</Text>
          <Text>Session JWT: {sessionTokens.session_jwt}</Text>
        </View>
      )}
    </View>
  );
};