From 0e71f31a4e917f5f94bc9df29befc86b2321293d Mon Sep 17 00:00:00 2001 From: Jean Brito Date: Fri, 13 Oct 2023 09:21:58 -0300 Subject: [PATCH] fix: Add authentication to room deeplink (#2751) --- src/deepLinks/main.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/deepLinks/main.ts b/src/deepLinks/main.ts index 37446fcc9..aee0cb413 100644 --- a/src/deepLinks/main.ts +++ b/src/deepLinks/main.ts @@ -67,6 +67,8 @@ type AuthenticationParams = { type OpenRoomParams = { host: string; path?: string; + token?: string; + userId?: string; }; type InviteParams = { @@ -138,7 +140,12 @@ const performAuthentication = async ({ }); // https://developer.rocket.chat/rocket.chat/deeplink#channel-group-dm -const performOpenRoom = async ({ host, path }: OpenRoomParams): Promise => +const performOpenRoom = async ({ + host, + path, + token, + userId, +}: OpenRoomParams): Promise => performOnServer(host, async (serverUrl) => { if (!path) { return; @@ -146,8 +153,14 @@ const performOpenRoom = async ({ host, path }: OpenRoomParams): Promise => if (!/^\/?(direct|group|channel|livechat)\/[0-9a-zA-Z-_.]+/.test(path)) { return; } + const url = new URL(path, serverUrl); + if (token && userId) { + url.searchParams.append('resumeToken', token); + url.searchParams.append('userId', userId); + } + const webContents = await getWebContents(serverUrl); - webContents.loadURL(new URL(path, serverUrl).href); + webContents.loadURL(url.href); }); const performInvite = async ({ host, path }: InviteParams): Promise => @@ -191,8 +204,10 @@ const processDeepLink = async (deepLink: string): Promise => { case 'room': { const host = args.get('host') ?? undefined; const path = args.get('path') ?? undefined; + const token = args.get('token') ?? undefined; + const userId = args.get('userId') ?? undefined; if (host && path) { - await performOpenRoom({ host, path }); + await performOpenRoom({ host, path, token, userId }); } break; }