Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3398205
D9672.id32605.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D9672.id32605.diff
View Options
diff --git a/web/grpc/interceptor.js b/web/grpc/interceptor.js
new file mode 100644
--- /dev/null
+++ b/web/grpc/interceptor.js
@@ -0,0 +1,53 @@
+// @flow
+
+import * as grpcWeb from 'grpc-web';
+
+import { getConfig } from 'lib/utils/config.js';
+
+class VersionInterceptor<Request, Response> {
+ intercept(
+ request: grpcWeb.Request<Request, Response>,
+ invoker: (
+ request: grpcWeb.Request<Request, Response>,
+ ) => Promise<grpcWeb.UnaryResponse<Request, Response>>,
+ ): Promise<grpcWeb.UnaryResponse<Request, Response>> {
+ const metadata = request.getMetadata();
+ const config = getConfig();
+ const codeVersion = config.platformDetails.codeVersion;
+ const deviceType = config.platformDetails.platform;
+ if (codeVersion) {
+ metadata['code_version'] = codeVersion.toString();
+ }
+ metadata['device_type'] = deviceType;
+
+ return invoker(request);
+ }
+}
+
+class AuthInterceptor<Request, Response> {
+ userID: string;
+ deviceID: string;
+ accessToken: string;
+
+ constructor(userID: string, deviceID: string, accessToken: string) {
+ this.userID = userID;
+ this.deviceID = deviceID;
+ this.accessToken = accessToken;
+ }
+
+ intercept(
+ request: grpcWeb.Request<Request, Response>,
+ invoker: (
+ request: grpcWeb.Request<Request, Response>,
+ ) => Promise<grpcWeb.UnaryResponse<Request, Response>>,
+ ): Promise<grpcWeb.UnaryResponse<Request, Response>> {
+ const metadata = request.getMetadata();
+ metadata['user_id'] = this.userID;
+ metadata['device_id'] = this.deviceID;
+ metadata['access_token'] = this.accessToken;
+
+ return invoker(request);
+ }
+}
+
+export { VersionInterceptor, AuthInterceptor };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 2, 9:45 PM (21 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2608629
Default Alt Text
D9672.id32605.diff (1 KB)
Attached To
Mode
D9672: [web] add client interceptors for grpc-web
Attached
Detach File
Event Timeline
Log In to Comment