Skip to main content

refreshAccessToken method

Future<bool> refreshAccessToken (String refreshToken)

This function is used to refresh the Authenication token to access the application.

params:

  • refreshToken: Needed for authentication

returns:

  • Future<bool>: it returns Future of dynamic

Implementation

Future<bool> refreshAccessToken(String refreshToken) async {
// run the graphQL mutation
final QueryResult result = await clientNonAuth.mutate(
MutationOptions(
document: gql(
_query.refreshToken(refreshToken),
),
),
);
// if there is an error or exception in [result]
if (result.hasException) {
final exception = encounteredExceptionOrError(result.exception!);
if (exception!) {
refreshAccessToken(refreshToken);
} else {
navigationService.pop();
}
} else if (result.data != null && result.isConcrete) {
userConfig.updateAccessToken(
refreshToken: (result.data!['refreshToken']
as Map<String, dynamic>)['refreshToken']
.toString(),
accessToken: (result.data!['refreshToken']
as Map<String, dynamic>)['accessToken']
.toString(),
);
databaseFunctions.init();
return true;
}
return false;
}