login method Null safety
Gets the JWT and refresh token through the API
Will throw an Exception if the password and user do not match OR API returns a 400
var client = MDClient()
client.login('myuser','mypassword')
Implementation
void login(String username, String password) {
http.post(Uri.parse('https://api.mangadex.org/auth/login'),
body: '{"username":"$username","password":"$password"}',
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
HttpHeaders.userAgentHeader: 'mangadex_dart_api/1.0'
}).then((res) {
if (res.statusCode == 401) {
throw 'User and Password does not match';
} else if (res.statusCode == 400) {
throw 'Bad request';
}
var data = jsonDecode(res.body);
token = data['token']['session'];
refresh = data['token']['refresh'];
});
}