Skip to content

Commit

Permalink
fix: Add authentication to room deeplink (#2751)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanfbrito authored Oct 13, 2023
1 parent 18174e2 commit 0e71f31
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/deepLinks/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type AuthenticationParams = {
type OpenRoomParams = {
host: string;
path?: string;
token?: string;
userId?: string;
};

type InviteParams = {
Expand Down Expand Up @@ -138,16 +140,27 @@ const performAuthentication = async ({
});

// https://developer.rocket.chat/rocket.chat/deeplink#channel-group-dm
const performOpenRoom = async ({ host, path }: OpenRoomParams): Promise<void> =>
const performOpenRoom = async ({
host,
path,
token,
userId,
}: OpenRoomParams): Promise<void> =>
performOnServer(host, async (serverUrl) => {
if (!path) {
return;
}
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<void> =>
Expand Down Expand Up @@ -191,8 +204,10 @@ const processDeepLink = async (deepLink: string): Promise<void> => {
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;
}
Expand Down

0 comments on commit 0e71f31

Please sign in to comment.