Get User
Retrieve the current authenticated user's profile information
Get User
USER
Retrieve the currently authenticated user's complete profile information including personal details, verification status, and security settings.
Query
GraphQL Schema
getUser: User
Parameters
This query requires no parameters. It automatically retrieves the profile of the currently authenticated user based on their authentication token.
Return Type
Returns a complete User
object containing:
Example Usage
query {
getUser {
id
email
name
country
role
tierLevel
lastLoginDate
avatar {
prefix
name
selected
}
verify {
emailVerified
phoneVerified
kycVerified
}
security {
tfaEnabled
authType
}
}
}
{
"data": {
"getUser": {
"id": 12345,
"email": "user@example.com",
"name": "John Doe",
"country": "USA",
"role": ["ROLE_USER"],
"tierLevel": 2,
"lastLoginDate": 1699564800000,
"avatar": {
"prefix": "Tesla",
"name": "12",
"selected": "{\"hair\":\"style1\",\"eyes\":\"blue\"}"
},
"verify": {
"emailVerified": true,
"phoneVerified": true,
"kycVerified": false
},
"security": {
"tfaEnabled": true,
"authType": "password"
}
}
}
}
import { GraphQLClient } from 'graphql-request';
const client = new GraphQLClient('https://api.nyyu.io/graphql', {
headers: {
authorization: `Bearer ${authToken}`,
},
});
const query = `
query {
getUser {
id
email
name
role
tierLevel
verify {
emailVerified
kycVerified
}
}
}
`;
async function getCurrentUser() {
try {
const data = await client.request(query);
console.log('Current user:', data.getUser);
return data.getUser;
} catch (error) {
console.error('Error fetching user:', error);
throw error;
}
}
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport
transport = RequestsHTTPTransport(
url='https://api.nyyu.io/graphql',
headers={'authorization': f'Bearer {auth_token}'},
)
client = Client(transport=transport)
query = gql('''
query {
getUser {
id
email
name
role
tierLevel
verify {
emailVerified
kycVerified
}
}
}
''')
def get_current_user():
try:
result = client.execute(query)
print(f"Current user: {result['getUser']}")
return result['getUser']
except Exception as error:
print(f"Error fetching user: {error}")
raise
Use Cases
Profile Dashboard
Display user profile information in a dashboard, showing account details, verification status, and tier level.
User Profile, Settings Page
Session Validation
Verify user session and retrieve current authentication status when users access protected resources.
Auth Middleware, Route Guards
Personalization
Load user preferences, avatar settings, and notification configurations to personalize the user experience.
UI Customization, Preferences
Verification Check
Check user verification status before allowing access to features that require KYC, email, or phone verification.
Feature Gating, Compliance
Security Considerations
Authentication Required
This query requires a valid authentication token. The user's identity is determined from the JWT token in the Authorization header.
Data Privacy
This query only returns data for the authenticated user. Users cannot access other users' profiles through this endpoint.
Token Validation
Ensure tokens are properly validated and not expired. Implement token refresh mechanisms for long-running sessions.
Best Practices
Implementation Guidelines
Error Handling
Unauthorized
Missing or invalid authentication token
Token Expired
JWT token has expired and needs to be refreshed
User Not Found
User account has been deleted or suspended
async function getUserWithErrorHandling() {
try {
const data = await client.request(query);
return data.getUser;
} catch (error) {
if (error.response?.status === 401) {
// Token expired or invalid - redirect to login
window.location.href = '/login';
} else if (error.response?.status === 404) {
// User not found - clear session
localStorage.removeItem('authToken');
window.location.href = '/login';
} else {
// Other errors - show error message
console.error('Failed to fetch user:', error);
throw error;
}
}
}