Returns the session_token and session_jwt for the active session. Otherwise retuns null.
Get tokens
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>
);
};