createLoginChallenge method

Future<LoginChallengepost> createLoginChallenge(
  1. String loginChallengeId,
  2. String redirectTo
)

Implementation

Future<LoginChallengepost> createLoginChallenge(
    String loginChallengeId, String redirectTo) async {
  var response = await http
      .post(Uri.parse('${APIMode.BASE_URL}api/v1/login-challenge'), body: {
    "loginChallengeId":
        '${DateTime.now().millisecondsSinceEpoch.toString()}${Uuid().v4().toString()}',
    "redirectTo": redirectTo
  });

  if (response.statusCode == 201) {
    dataMain = jsonDecode(response.body);
    var responseString = response.body;
    String loginChallengeId =
        loginChallengepostFromJson(responseString).loginChallengeId;

    CoreDb.instance().setLoginId(loginChallengeId);

    return loginChallengepostFromJson(responseString);
  } else {
    ConscentMethods().onPluginError(response.body);
    throw Exception('Failed to create album.');
  }
}