Skip to content

Commit 4934920

Browse files
[MM-66711] Verify push notifications on magic link login (#9322)
* [MM-66711] Verify push notifications on magic link login * Address copilot suggestion * Add missing await --------- Co-authored-by: Mattermost Build <build@mattermost.com>
1 parent c42ebca commit 4934920

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

app/actions/remote/session.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {defineMessages, type IntlShape} from 'react-intl';
55
import {Alert, DeviceEventEmitter, type AlertButton} from 'react-native';
66

77
import {cancelSessionNotification, findSession} from '@actions/local/session';
8+
import {doPing} from '@actions/remote/general';
89
import {Database, Events} from '@constants';
910
import {SYSTEM_IDENTIFIERS} from '@constants/database';
1011
import DatabaseManager from '@database/manager';
@@ -18,8 +19,10 @@ import {getCurrentUser} from '@queries/servers/user';
1819
import {resetToHome} from '@screens/navigation';
1920
import EphemeralStore from '@store/ephemeral_store';
2021
import {getFullErrorMessage, isErrorWithStatusCode, isErrorWithUrl} from '@utils/errors';
22+
import {getIntlShape} from '@utils/general';
2123
import {logWarning, logError, logDebug} from '@utils/log';
2224
import {scheduleExpiredNotification} from '@utils/notification';
25+
import {canReceiveNotifications} from '@utils/push_proxy';
2326
import {type SAMLChallenge} from '@utils/saml_challenge';
2427
import {getCSRFFromCookie} from '@utils/security';
2528
import {getServerUrlAfterRedirect} from '@utils/url';
@@ -468,6 +471,19 @@ export const magicLinkLogin = async (serverUrl: string, token: string): Promise<
468471
});
469472
const csrfToken = await getCSRFFromCookie(serverUrlToUse);
470473
client.setCSRFToken(csrfToken);
474+
475+
// Check push notification capability (similar to normal login flow)
476+
const pingResult = await doPing(
477+
serverUrlToUse,
478+
true, // verifyPushProxy
479+
undefined, // timeoutInterval
480+
undefined, // preauthSecret
481+
client, // client
482+
);
483+
if (!pingResult.error && pingResult.canReceiveNotifications) {
484+
const intl = getIntlShape(user.locale);
485+
await canReceiveNotifications(serverUrlToUse, pingResult.canReceiveNotifications as string, intl);
486+
}
471487
} catch (error) {
472488
return {error, failed: true};
473489
}

app/screens/edit_server/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ const EditServer = ({closeButtonId, componentId, server, theme}: ServerProps) =>
110110
}
111111

112112
// Then try ping request - use doPing without client to avoid client pollution
113-
const result = await doPing(headRequest.url, true, undefined, secretForValidation);
113+
const result = await doPing(
114+
headRequest.url, // serverUrl
115+
true, // verifyPushProxy
116+
undefined, // timeoutInterval
117+
secretForValidation, // preauthSecret
118+
);
114119
if (result.error) {
115120
if (result.isPreauthError) {
116121
setPreauthSecretError(formatMessage({

app/screens/server/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ const Server = ({
146146
handleConnect(managedConfig?.serverUrl || LocalConfig.DefaultServerUrl);
147147
}
148148

149-
// functions do not need memoization
150-
// eslint-disable-next-line react-hooks/exhaustive-deps
149+
// We only want to handle connect when a smaller set of variables change
150+
// eslint-disable-next-line react-hooks/exhaustive-deps
151151
}, [managedConfig?.allowOtherServers, managedConfig?.serverUrl, managedConfig?.serverName, defaultServerUrl]);
152152

153153
useEffect(() => {
@@ -189,8 +189,8 @@ const Server = ({
189189

190190
return () => backHandler.remove();
191191

192-
// only needed on mount
193-
// eslint-disable-next-line react-hooks/exhaustive-deps
192+
// We register the back handler and the push notifications only on mount
193+
// eslint-disable-next-line react-hooks/exhaustive-deps
194194
}, []);
195195

196196
useNavButtonPressed(closeButtonId || '', componentId, dismiss, []);
@@ -329,7 +329,12 @@ const Server = ({
329329
}
330330
return;
331331
}
332-
const result = await doPing(headRequest.url, true, managedConfig?.timeout ? parseInt(managedConfig?.timeout, 10) : undefined, preauthSecret.trim() || undefined);
332+
const result = await doPing(
333+
headRequest.url,
334+
true, // verifyPushProxy
335+
managedConfig?.timeout ? parseInt(managedConfig?.timeout, 10) : undefined, // timeoutInterval
336+
preauthSecret.trim() || undefined, // preauthSecret
337+
);
333338

334339
if (canceled) {
335340
return;

0 commit comments

Comments
 (0)