You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Future<GraphQLClient> _getClient({
required final String path,
final String? accessToken,
}) async {
// final Link link = HttpLink(path);
// Link link = HttpLink(path, httpClient: LoggerHttpClient(http.Client()));
// if (accessToken != null) {
// link = AuthLink(getToken: () async => 'Bearer $accessToken').concat(
// HttpLink(
// path,
// ),
// );
// }
final freshLink = FreshLink.oAuth2(
shouldRefresh: (final _) {
debugPrint(_.errors.toString());
debugPrint(_.data.toString());
return true;
},
tokenStorage: InMemoryTokenStorage(),
refreshToken: (final token, final client) {
// Perform refresh and return new token
debugPrint('--------->refreshToken $token');
return Future.value();
},
)..authenticationStatus.listen(
(final data) {
debugPrint('---------> authenticationStatus $data');
},
onError: (final err) {
debugPrint('--------->onError $err');
},
);
await freshLink.setToken(OAuth2Token(accessToken: 'Bearer $accessToken'));
return getClient = GraphQLClient(
link: Link.from([freshLink, HttpLink(path)]),
cache: GraphQLCache(store: InMemoryStore()),
);
}
Future<QueryResult> query({
required final String mainPath,
required final String query,
final Function(Map<String, dynamic>? result)? action,
final Function(String message)? error,
final bool requiredToken = true,
final bool showDialogResend = false,
final Map<String, dynamic>? params,
final FetchPolicy fetchPolicy = FetchPolicy.networkOnly,
}) async {
// try {
// Get token from local storage if required token is true
UserTokenModel? token;
if (requiredToken) {
token = UserStoreService.to.getToken();
}
final client = await _getClient(
path: mainPath,
accessToken: requiredToken ? token!.accessToken : null,
);
return client.query(
QueryOptions(
document: gql(query),
fetchPolicy: fetchPolicy,
variables: params ?? {},
),
);
}
But just this print is printed: ---------> authenticationStatus AuthenticationStatus.unauthenticated
and other callback not triggered?
I am using unit test to test that?
The text was updated successfully, but these errors were encountered:
I fix the problem by change await freshLink.setToken(OAuth2Token(accessToken: 'Bearer $accessToken'));
to this await freshLink.setToken(OAuth2Token(accessToken: '$accessToken'));
I am using this library like this:
But just this print is printed:
---------> authenticationStatus AuthenticationStatus.unauthenticated
and other callback not triggered?
I am using unit test to test that?
The text was updated successfully, but these errors were encountered: