Users
User profile endpoints for AsaHome Cloud.
Endpoints Overview
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /users/me | Get current user profile | Yes |
Base URL: https://cloud.asahome.io/api/v1
GET Get Current User
Retrieve the profile of the currently authenticated user.
Request
GET /api/v1/users/me
Headers
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Bearer <accessToken> |
Example
curl -X GET "https://cloud.asahome.io/api/v1/users/me" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Response
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"email": "user@example.com",
"firstName": "John",
"lastName": "Doe",
"role": "user",
"isActive": true,
"isEmailVerified": true,
"profile": {
"avatar": null,
"timezone": "Europe/Amsterdam",
"language": "en"
},
"devices": [
{
"id": "device-uuid-1",
"name": "Home Hub",
"role": "owner",
"isOnline": true
}
],
"createdAt": "2024-01-15T10:30:00.000Z",
"updatedAt": "2024-01-15T10:30:00.000Z"
}
Response Fields
| Field | Type | Description |
|---|---|---|
id | string | User UUID |
email | string | Email address |
firstName | string | First name |
lastName | string | Last name |
role | string | User role (user or admin) |
isActive | boolean | Account active status |
isEmailVerified | boolean | Email verification status |
profile | object | User profile settings |
devices | array | Linked devices summary |
createdAt | string | Account creation timestamp |
updatedAt | string | Last update timestamp |
Profile Object
| Field | Type | Description |
|---|---|---|
avatar | string | Avatar URL or null |
timezone | string | User timezone |
language | string | Preferred language |
Device Summary
| Field | Type | Description |
|---|---|---|
id | string | Device ID |
name | string | Device display name |
role | string | User's role for this device |
isOnline | boolean | Device online status |
Error Responses
Unauthorized (401)
{
"statusCode": 401,
"message": "Unauthorized",
"error": "Unauthorized"
}
Token Expired (401)
{
"statusCode": 401,
"message": "Token has expired",
"error": "Unauthorized"
}
Usage in Flutter
Get User Profile
import 'package:http/http.dart' as http;
import 'dart:convert';
class UserService {
final String baseUrl = 'https://cloud.asahome.io/api/v1';
final String accessToken;
UserService(this.accessToken);
Future<Map<String, dynamic>> getCurrentUser() async {
final response = await http.get(
Uri.parse('$baseUrl/users/me'),
headers: {
'Authorization': 'Bearer $accessToken',
'Content-Type': 'application/json',
},
);
if (response.statusCode == 200) {
return jsonDecode(response.body);
} else if (response.statusCode == 401) {
throw UnauthorizedException('Token expired');
} else {
throw Exception('Failed to fetch user');
}
}
}
Usage Example
void loadUserProfile() async {
try {
final token = await AuthStorage().getAccessToken();
final userService = UserService(token!);
final user = await userService.getCurrentUser();
setState(() {
userName = '${user['firstName']} ${user['lastName']}';
userDevices = user['devices'];
});
} on UnauthorizedException {
// Refresh token and retry
await refreshTokens();
loadUserProfile();
} catch (e) {
showError('Failed to load profile');
}
}
Notes
User Management
User accounts are managed through the Laravel integration. New users are created via the /auth/sync-customer endpoint when customers are added in the Laravel application.
Password Reset
Users who are synced from Laravel receive a randomly generated password and must use the password reset flow to set their own password.