User API
⚡ 5 min readThe transcodes.user object provides methods to retrieve user information.
Methods
get()
Retrieves user information from the server.
transcodes.user.get(params: {
projectId?: string;
userId?: string;
email?: string;
fields?: string;
}): Promise<ApiResponse<User[]>>Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
projectId | string | No | Project ID |
userId | string | No | User ID to fetch |
email | string | No | Email address to search |
fields | string | No | Comma-separated fields to return |
Returns: Promise<ApiResponse<User[]>>
Example - Get user by ID:
const result = await transcodes.user.get({
projectId: 'proj_xxx',
userId: 'user_xxx',
});
if (result.success) {
const user = result.payload[0];
console.log('User:', user.name, user.email);
} else {
console.error('Failed to get user:', result.error);
}Example - Get user by email:
const result = await transcodes.user.get({
projectId: 'proj_xxx',
email: 'user@example.com',
});
if (result.success && result.payload.length > 0) {
const user = result.payload[0];
console.log('Found user:', user.id);
}Example - Get specific fields:
const result = await transcodes.user.get({
projectId: 'proj_xxx',
userId: 'user_xxx',
fields: 'id,email,name',
});Type Definitions
User
interface User {
id?: string;
projectId?: string;
name?: string;
email?: string;
roles?: string;
metadata?: Record<string, string | number | boolean | null | undefined>;
createdAt?: Date | string;
updatedAt?: Date | string;
}ApiResponse<T>
interface ApiResponse<T> {
success: boolean;
payload: T;
error?: string;
message?: string;
}Usage Examples
Fetch User After Login
async function handleLogin() {
const result = await transcodes.openAuthLoginModal({
projectId: 'proj_xxx',
});
if (result.success) {
const userId = result.payload[0].user.id;
// Fetch full user details
const userResult = await transcodes.user.get({
projectId: 'proj_xxx',
userId: userId,
});
if (userResult.success) {
const user = userResult.payload[0];
console.log('Welcome,', user.name || user.email);
}
}
}Related
- Token API - Authentication tokens
- Modal API - Authentication modals
- Events API - Auth state change events
Last updated on