Skip to main content
import { useStytch } from '@stytch/react';

export const UserDisplay = () => {
  const stytch = useStytch();
  const user = stytch.user.getSync();

  return user ? <p>User: {user.name.first_name}</p> : <p>No user found</p>;
};
{
  "user_id": "user-test-16d9ba61-97a1-4ba4-9720-b03761dc50c6",
  "emails": [
    {
      "email_id": "email-test-81bf03a8-86e1-4d95-bd44-bb3495224953",
      "email": "sandbox@stytch.com",
      "verified": true
    }
  ],
  "phone_numbers": [],
  "crypto_wallets": [],
  "name": {
    "first_name": "Jane",
    "last_name": "Doe"
  },
  "trusted_metadata": {},
  "untrusted_metadata": {},
  "created_at": "2023-01-01T00:00:00Z",
  "status": "active"
}
The Stytch SDK caches the currently logged-in user. user.getSync is a synchronous method that fetches the currently logged-in User from the cache. If there is no cached data, this method returns null. The user.getInfo method is similar to user.getSync, but returns an object containing the user object and a fromCache boolean. If fromCache is true, the user object is from the cache and a state refresh is in progress. You can listen for changes with the user.onChange method, which invokes your callback whenever the user object changes. If you need to asynchronously fetch guaranteed-fresh data from the API, use the user.get method.

Response

user
object
See the User object for complete response field details.
fromCache
boolean
Whether the User data is from persistent storage.