Page MenuHomePhabricator

D9672.id32605.diff
No OneTemporary

D9672.id32605.diff

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

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)

Event Timeline