B2B Saas 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 { useStytchB2BClient } from '@stytch/react-native/b2b';
import { SessionTokens } from '@stytch/react-native';
import { Text, TouchableOpacity, View } from 'react-native';

export const GetSessionTokens = () => {
  const stytch = useStytchB2BClient();
  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>
  );
};