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

export const Home = () => {
const stytch = useStytch();
const [user, setUser] = useState(null);

useEffect(() => {
  const fetchUser = async () => {
    const currentUser = await stytch.user.get();
    setUser(currentUser);
  };
  fetchUser();
}, [stytch]);

return user ? <p>Welcome, {user.name.first_name}</p> : <p>Log in to continue!</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"
}
user.get is an asynchronous method that wraps the get user endpoint. Use it to fetch the currently logged-in User. If no User is logged in, this method returns null. The Stytch SDK caches this data — calling this method will refresh the cached data. The Stytch SDK will invoke this method automatically in the background, so you likely won’t need to call this method directly. Instead, use the user.getSync method to fetch the cached data.

Response

user
object
See the User object for complete response field details.
request_id
string
Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
status_code
number
The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.