Crossmint Auth provides a way to retrieve and update user profile data, such as email, social login metadata, and more.

This API requires the users.read scope.

  • Server side: Requires a server-side API key.
  • Client side: Requires a client-side API key, and a logged in user.

Server-side

For server-side operations, use the @crossmint/server-sdk-auth that provides a getUser function to fetch user information.

import { CrossmintAuthService } from '@crossmint/server-sdk-auth';

const crossmintAuthService = new CrossmintAuthService('YOUR_SERVER_API_KEY');

async function getUser(userId: string) {
  try {
    const user = await crossmintAuthService.getUser(userId);
    console.log('User data:', user);
  } catch (error) {
    console.error('Error fetching user data:', error);
  }
}

Response Format

{
    "userId": "123", 
    "email": "test@test.com", // Optional (if user was created with email)
    "phoneNumber": "123456789", // Optional (if user was created with phone number)
    "google": {
        "name": "John Doe",
        "picture": "https://example.com/picture.jpg"
    },
    "farcaster": {
        "fid": "123",
        "username": "johndoe",
        "bio": "Hello, I'm John Doe",
        "displayName": "John Doe",
        "pfpUrl": "https://example.com/pfp.jpg",
        "custody": "0x1234567890123456789012345678901234567890",
        "verifications": ["0x1234567890123456789012345678901234567890"]
    }
}

Client-side

Use the useAuth react hook from @crossmint/client-sdk-react-ui to access the user object.

If you would like to use a different framework, contact support
React
import { useAuth } from '@crossmint/client-sdk-react-ui';

function User() {
  const { user } = useAuth();

  if (!user) {
    return <div>Loading user...</div>;
  }

  return (
    <div>
      <h1>User</h1>
      <p>User ID: {user.userId}</p>
      <p>Email: {user.email}</p>
      <p>Phone Number: {user.phoneNumber}</p>
      <p>Google Name: {user.google?.name}</p>
      <p>Google Picture: {user.google?.picture}</p>
      <p>Farcaster FID: {user.farcaster?.fid}</p>
      <p>Farcaster Username: {user.farcaster?.username}</p>
      <p>Farcaster Bio: {user.farcaster?.bio}</p>
      <p>Farcaster Display Name: {user.farcaster?.displayName}</p>
      <p>Farcaster PFP URL: {user.farcaster?.pfpUrl}</p>
      <p>Farcaster Custody: {user.farcaster?.custody}</p>
      <p>Farcaster Verifications: {user.farcaster?.verifications}</p>
    </div>
  );
}