Add comprehensive debug logging for password flow and org creation diagnostics
This commit is contained in:
@@ -97,8 +97,10 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
||||
CreateOrganization event,
|
||||
Emitter<OrganizationState> emit,
|
||||
) async {
|
||||
print('[DEBUG-ORG-CREATION] CreateOrganization event received with name: "${event.name}"');
|
||||
final name = event.name.trim();
|
||||
if (name.isEmpty) {
|
||||
print('[DEBUG-ORG-CREATION] Name is empty after trim');
|
||||
// Try to preserve current state if possible
|
||||
if (state is OrganizationLoaded) {
|
||||
emit(
|
||||
@@ -144,8 +146,10 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
||||
),
|
||||
);
|
||||
|
||||
print('[DEBUG-ORG-CREATION] About to call orgApi.createOrganization with name: "$name"');
|
||||
try {
|
||||
final newOrg = await orgApi.createOrganization(name);
|
||||
print('[DEBUG-ORG-CREATION] API returned successfully: ${newOrg.id} - ${newOrg.name}');
|
||||
final updatedOrgs = [...existingOrgs, newOrg];
|
||||
emit(OrganizationLoaded(organizations: updatedOrgs, selectedOrg: newOrg));
|
||||
// Reset blocs and load permissions for new org
|
||||
@@ -154,6 +158,7 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
||||
uploadBloc.add(ResetUploads());
|
||||
permissionBloc.add(LoadPermissions(newOrg.id));
|
||||
} catch (e) {
|
||||
print('[DEBUG-ORG-CREATION] Error caught: $e');
|
||||
emit(
|
||||
OrganizationLoaded(
|
||||
organizations: existingOrgs,
|
||||
|
||||
@@ -72,10 +72,13 @@ class ApiClient {
|
||||
dynamic data,
|
||||
required T Function(dynamic data) fromJson,
|
||||
}) async {
|
||||
print('[DEBUG-API-CLIENT] POST request starting - path: $path, data: $data');
|
||||
try {
|
||||
final response = await _dio.post(path, data: data);
|
||||
print('[DEBUG-API-CLIENT] POST response received - status: ${response.statusCode}, data: ${response.data}');
|
||||
return fromJson(response.data);
|
||||
} on DioException catch (e) {
|
||||
print('[DEBUG-API-CLIENT] POST request failed - type: ${e.type}, message: ${e.message}, status: ${e.response?.statusCode}');
|
||||
throw _handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import '../blocs/organization/organization_state.dart';
|
||||
import 'api_client.dart';
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
class OrgApi {
|
||||
final ApiClient _apiClient;
|
||||
@@ -14,10 +15,20 @@ class OrgApi {
|
||||
}
|
||||
|
||||
Future<Organization> createOrganization(String name) async {
|
||||
return await _apiClient.post(
|
||||
'/orgs',
|
||||
data: {'name': name},
|
||||
fromJson: (data) => Organization.fromJson(data),
|
||||
);
|
||||
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization called with name: "$name"');
|
||||
developer.log('POST /orgs with payload: {"name": "$name"}', name: 'OrgApi');
|
||||
|
||||
try {
|
||||
final result = await _apiClient.post(
|
||||
'/orgs',
|
||||
data: {'name': name},
|
||||
fromJson: (data) => Organization.fromJson(data),
|
||||
);
|
||||
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization returned: ${result.id}');
|
||||
return result;
|
||||
} catch (e) {
|
||||
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization error: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user