Crossmint Auth provides a way to retrieve and update user profile data, such as email, social login metadata, and more.
Reading User Data
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
that provides a getUser
function to fetch user information.
import { createCrossmint, CrossmintAuth } from '@crossmint/server-sdk';
const crossmint = createCrossmint({ apiKey: SERVER_API_KEY });
const crossmintAuth = CrossmintAuth.from(crossmint);
async function getUser(userId: string) {
try {
const user = await crossmintAuth.getUser(userId);
console.log('User data:', user);
} catch (error) {
console.error('Error fetching user data:', error);
}
}
{
"userId": "123",
"email": "test@test.com",
"phoneNumber": "123456789",
"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.
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>
);
}