Skip to content

Commit 1d9ce3c

Browse files
committed
Always send our auth token on Node, and always send an appcheck token if we have one.
1 parent 74ed43d commit 1d9ce3c

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

packages/database/src/realtime/WebSocketConnection.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,15 @@ export class WebSocketConnection implements Transport {
167167
};
168168

169169
// If using Node with admin creds, AppCheck-related checks are unnecessary.
170-
// It will send the authorization token.
171-
if (this.nodeAdmin) {
172-
options.headers['Authorization'] = this.authToken || '';
173-
} else {
174-
// If using Node without admin creds (which includes all uses of the
175-
// client-side Node SDK), it will send an AppCheck token if available.
176-
// Any other auth credentials will eventually be sent after the connection
177-
// is established, but aren't needed here as they don't effect the initial
178-
// request to establish a connection.
179-
options.headers['X-Firebase-AppCheck'] = this.appCheckToken || '';
170+
// Note that we send the credentials here even if they aren't admin credentials, which is
171+
// not a problem.
172+
// Note that this header is just used to bypass appcheck, and the token should still be sent
173+
// through the websocket connection once it is established.
174+
if (this.authToken) {
175+
options.headers['Authorization'] = this.authToken;
176+
}
177+
if (this.appCheckToken) {
178+
options.headers['X-Firebase-AppCheck'] = this.appCheckToken;
180179
}
181180

182181
// Plumb appropriate http_proxy environment variable into faye-websocket if it exists.
@@ -239,7 +238,7 @@ export class WebSocketConnection implements Transport {
239238
/**
240239
* No-op for websockets, we don't need to do anything once the connection is confirmed as open
241240
*/
242-
start() {}
241+
start() { }
243242

244243
static forceDisallow_: boolean;
245244

0 commit comments

Comments
 (0)