establishSession method
Implementation
Future<void> establishSession({
required String apiKey,
required String kycLevel,
String? firstName,
String? lastName,
String? uniqueId,
String? phoneNumber,
String? email,
String? i18n,
WidgetRef? ref,
}) async {
state = state.copyWith(isInitializing: true, error: null);
try {
// Initialize the API client with credentials
ApiClient.shared.apiKey = apiKey;
// Establish a session with the server
final branding = await ApiClient.shared.establishSession(
apiKey: apiKey,
kycLevel: kycLevel,
firstName: firstName,
lastName: lastName,
uniqueId: uniqueId,
phoneNumber: phoneNumber,
emailAddress: email,
i18n: i18n,
);
// Update state with the branding information
state = state.copyWith(
isInitializing: false,
branding: branding,
isInitialized: true,
);
// Setup WebSocket connection if ref is provided
if (ref != null) {
ref.read(webSocketManagerProvider.notifier).setupConnection(
baseURL: ApiClient.shared.websocketURL ?? "",
sessionToken: ApiClient.shared.sessionToken,
);
}
} catch (e) {
state = state.copyWith(
isInitializing: false,
error: e.toString(),
);
}
}