login method Null safety
Login a user.
Implementation
void login(String username, String password, Function loginCallback) async {
// Link to server.
final HttpLink httpLink = HttpLink(statementDatabaseUrl, defaultHeaders: {
'X-Parse-Application-Id': statementDatabaseApplicationID,
'X-Parse-Client-Key': statementDatabaseClientKey,
//'X-Parse-REST-API-Key' : kParseRestApiKey,
});
// Provides data from server and facilitates requests.
GraphQLClient client = GraphQLClient(
cache: GraphQLCache(),
link: httpLink,
);
// The result returned from the query.
var loginResult = await client.mutate(
MutationOptions(
document: gql(Queries.login(username, password)),
),
);
// If login result has any exceptions.
if (loginResult.hasException) {
loginCallback(false, "Login fehlgeschlagen.");
return;
}
// Safe the new token.
safeStorage.write(
key: "token",
value: loginResult.data?["logIn"]["viewer"]["sessionToken"]);
loginCallback(true, null);
}