-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Begging for support] Can the url be transformed? #419
Comments
Hi!
If you come to discord (see readme), there was a discussion around something very
similar.
You might be able to copy code from that discussion
danielRi ***@***.***> schrieb am Di., 19. Sep. 2023, 11:33:
… Hi,
I use want to use a WebSocketLink, but for authentication I need to append
the current auth token to the url (required by server).
I was thinking about something llike this, but I dont know how to update
the url of the request. Can TransformLink achieve this? Im stuck, so any
suggestions/help is much appreciated. Thank you!
class WebSocketAuthLink extends Link {
final Future<String?> Function() getToken;
final String graphQLEndpoint;
String? _token;
late Link _link;
WebSocketAuthLink({
required this.getToken,
required this.graphQLEndpoint,
}) {
_link = Link.from([
WebSocketLink(graphQLEndpoint),
TransformLink(requestTransformer: transformRequest),
]);
}
Future<void> updateToken() async {
_token = await getToken();
debugPrint('token: ${_token.toString()}');
}
Request transformRequest(Request request) {
// How to update url?
// final url = oldUrl + _token?
}
@OverRide
Stream<Response> request(Request request, [forward]) async* {
if (_token == null) {
await updateToken();
}
yield* _link.request(request, forward);
}
}
—
Reply to this email directly, view it on GitHub
<#419>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKASNZK3JA5VNMBRKPTJE3X3FRGFANCNFSM6AAAAAA46ACCIY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Cool Ill drop by. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I use want to use a WebSocketLink, but for authentication I need to append the current auth token to the url (required by server).
I was thinking about something llike this, but I dont know how to update the url of the request. Can TransformLink achieve this? Im stuck, so any suggestions/help is much appreciated. Thank you!
The text was updated successfully, but these errors were encountered: