register method

Future<Map<String, dynamic>?> register(
  1. String username,
  2. String email,
  3. String name,
  4. String password,
)

Implementation

Future<Map<String, dynamic>?> register(
    String username, String email, String name, String password) async {
  final response = await http.post(
    Uri.parse('$webbaseUrl/api/ibl/v1/authentication/register-user/'),
    body: {
      'username': username,
      'email': email,
      'name': name,
      'password': password,
      'mobile': '1'
    },
  );

  var data = json.decode(response.body);

  // Extracting the token from the redirect_uri field in the response
  String? redirectUri = data['redirect_uri'];
  if (redirectUri != null) {
    String? token = Uri.parse(redirectUri).queryParameters['token'];
    if (token != null) {
      return {'token': token}; // Return the token as a JSON object
    }
  }
  return data; // Return null if redirectUri is not in the response or token is not found
}