Skip to main content

Users

User profile endpoints for AsaHome Cloud.

Endpoints Overview

MethodEndpointDescriptionAuth
GET/users/meGet current user profileYes

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

HeaderRequiredDescription
AuthorizationYesBearer <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

FieldTypeDescription
idstringUser UUID
emailstringEmail address
firstNamestringFirst name
lastNamestringLast name
rolestringUser role (user or admin)
isActivebooleanAccount active status
isEmailVerifiedbooleanEmail verification status
profileobjectUser profile settings
devicesarrayLinked devices summary
createdAtstringAccount creation timestamp
updatedAtstringLast update timestamp

Profile Object

FieldTypeDescription
avatarstringAvatar URL or null
timezonestringUser timezone
languagestringPreferred language

Device Summary

FieldTypeDescription
idstringDevice ID
namestringDevice display name
rolestringUser's role for this device
isOnlinebooleanDevice 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.