checkToken method Null safety
Checks if token is valid.
Implementation
Future<bool> checkToken() async {
// The session token.
String? token = await safeStorage.read(key: "token");
// If token is not null, check if it is valid.
if (token != null) {
// Link to the database.
final HttpLink httpLink = HttpLink(statementDatabaseUrl, defaultHeaders: {
'X-Parse-Application-Id': statementDatabaseApplicationID,
'X-Parse-Client-Key': statementDatabaseClientKey,
'X-Parse-Session-Token': token,
});
// The client that provides the connection.
GraphQLClient client = GraphQLClient(
cache: GraphQLCache(),
link: httpLink,
);
// The query result.
var queryResult = await client.mutate(
MutationOptions(
document: gql(Queries.getCurrentUser()),
),
);
if (queryResult.hasException) {
return false;
} else {
return true;
}
}
// no token, return false
return false;
}