Skip to content

Commit 2eb9b58

Browse files
authored
feat(web): use session from setSession() for realtime
At the moment, if a cookie isn't set, only the local storage cookie fallback is used for realtime authentication. This means sessions using client.setSession() will be unauthenticated when using realtime. This PR makes realtime use this.config.session (which is set with client.setSession()) if it exists.
1 parent d1f9097 commit 2eb9b58

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

templates/web/src/client.ts.twig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,13 @@ class Client {
478478
this.realtime.lastMessage = message;
479479
switch (message.type) {
480480
case 'connected':
481-
const cookie = JSON.parse(window.localStorage.getItem('cookieFallback') ?? '{}');
482-
const session = cookie?.[`a_session_${this.config.project}`];
483-
const messageData = <RealtimeResponseConnected>message.data;
481+
let session = this.config.session;
482+
if (!session) {
483+
const cookie = JSON.parse(window.localStorage.getItem('cookieFallback') ?? '{}');
484+
session = cookie?.[`a_session_${this.config.project}`];
485+
}
484486

487+
const messageData = <RealtimeResponseConnected>message.data;
485488
if (session && !messageData.user) {
486489
this.realtime.socket?.send(JSON.stringify(<RealtimeRequest>{
487490
type: 'authentication',

0 commit comments

Comments
 (0)