Consumer Authentication

/

Mobile SDKs

/

React Native SDK reference

/

Session Management

/

Update Session

Update session

Update a user's session tokens to hydrate a front-end session from the backend. For example, if you log your users in with one of our backend SDKs, you can pass the resulting session_token and session_jwt to this method to prime the frontend SDK with a valid set of tokens. You must then make an authenticate call to authenticate the session tokens and retrieve the user's current session.

import React, { useCallback, useEffect } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import { useStytch, useStytchUser } from '@stytch/react-native';

export const App = () => {
  const stytch = useStytch();
  const { user } = useStytchUser();

  useEffect(() => {
    if (user) {
      // redirect to logged in experience
    }
  }, [user]);

  const authenticate = useCallback(() => {
    stytch.session.updateSession({
      session_token: 'a session token from your backend',
      session_jwt: 'a session JWT from your backend',
    });

    stytch.session.authenticate({ session_duration_minutes: 60 });
  }, [stytch]);

  return (
    <View>
      <TouchableOpacity onPress={authenticate}>
        <Text>Hydrate session</Text>
      </TouchableOpacity>
    </View>
  );
};