User Profiles
Access and update user profile information.
Accessing User Data
- Next.js SDK
- Django
- cURL / API
'use client';
import { useSyAuth } from '@syauth/nextjs';
export function UserProfile() {
const { user, isAuthenticated } = useSyAuth();
if (!isAuthenticated) {
return <p>Please log in</p>;
}
return (
<div>
<p><strong>Email:</strong> {user?.email}</p>
<p><strong>Name:</strong> {user?.first_name} {user?.last_name}</p>
</div>
);
}
In Django views, the authenticated user is available via request.user when using the SyAuth authentication backend:
from django.http import JsonResponse
from django.contrib.auth.decorators import login_required
@login_required
def user_profile(request):
user = request.user
return JsonResponse({
'email': user.email,
'first_name': user.first_name,
'last_name': user.last_name,
})
curl -X GET https://api.syauth.com/e/v1/user/profile/ \
-H "Authorization: Bearer <access-token>"
Response:
{
"id": "user-uuid",
"email": "[email protected]",
"first_name": "John",
"last_name": "Doe",
"email_verified": true
}
User Object Properties
| Property | Type | Description |
|---|---|---|
id | string | Unique user ID (UUID) |
email | string | Email address |
first_name | string | First name |
last_name | string | Last name |
email_verified | boolean | Email verification status |
registration_method | string | email or google |
created_at | string | ISO timestamp |
last_login | string | ISO timestamp |
Updating Profiles
- Next.js SDK
- Django / Python
- cURL / API
'use client';
import { useSyAuth } from '@syauth/nextjs';
import { useState } from 'react';
export function EditProfileForm() {
const { user, updateProfile, isLoading } = useSyAuth();
const [formData, setFormData] = useState({
first_name: user?.first_name || '',
last_name: user?.last_name || '',
});
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
await updateProfile(formData);
alert('Profile updated');
};
// ... form JSX
}
import requests
def update_user_profile(access_token, first_name, last_name):
url = "https://api.syauth.com/e/v1/user/profile/"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
payload = {
"first_name": first_name,
"last_name": last_name
}
response = requests.patch(url, json=payload, headers=headers)
return response.json()
curl -X PATCH https://api.syauth.com/e/v1/user/profile/ \
-H "Authorization: Bearer <access-token>" \
-H "Content-Type: application/json" \
-d '{
"first_name": "Jane",
"last_name": "Smith"
}'
Response:
{
"id": "user-uuid",
"email": "[email protected]",
"first_name": "Jane",
"last_name": "Smith",
"email_verified": true
}
Updatable Fields
| Field | Updatable | Notes |
|---|---|---|
first_name | ✅ | |
last_name | ✅ | |
email | ❌ | Requires separate flow |
password | ❌ | Use password update endpoint |
Get Profile via API
GET https://api.syauth.com/e/v1/user/profile/
Authorization: Bearer <access-token>
Response:
{
"id": "user-uuid",
"email": "[email protected]",
"first_name": "John",
"last_name": "Doe",
"email_verified": true,
"registration_method": "email",
"created_at": "2024-01-01T00:00:00Z",
"last_login": "2024-01-15T10:30:00Z"
}
👉 Manage user profiles as an administrator: Dashboard → Users
Next Steps
- Password Reset - Allow password changes
- User Groups - Assign users to groups