[FIX] App hanging on splash screen when deep link params are wrong (#2359)

* Add rule when there's no host on the deep link params

* Add fallbackNavigation()

* Fix insecure hosts
This commit is contained in:
Diego Mello 2020-07-30 16:41:23 -03:00 committed by GitHub
parent cb5c914570
commit 097304b5fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 2 deletions

View File

@ -10,7 +10,9 @@ import { inviteLinksSetToken, inviteLinksRequest } from '../actions/inviteLinks'
import database from '../lib/database'; import database from '../lib/database';
import RocketChat from '../lib/rocketchat'; import RocketChat from '../lib/rocketchat';
import EventEmitter from '../utils/events'; import EventEmitter from '../utils/events';
import { appStart, ROOT_INSIDE, ROOT_NEW_SERVER } from '../actions/app'; import {
appStart, ROOT_INSIDE, ROOT_NEW_SERVER, appInit
} from '../actions/app';
import { localAuthenticate } from '../utils/localAuthentication'; import { localAuthenticate } from '../utils/localAuthentication';
import { goRoom } from '../utils/goRoom'; import { goRoom } from '../utils/goRoom';
import callJitsi from '../lib/methods/callJitsi'; import callJitsi from '../lib/methods/callJitsi';
@ -61,6 +63,14 @@ const navigate = function* navigate({ params }) {
} }
}; };
const fallbackNavigation = function* fallbackNavigation() {
const currentRoot = yield select(state => state.app.root);
if (currentRoot) {
return;
}
yield put(appInit());
};
const handleOpen = function* handleOpen({ params }) { const handleOpen = function* handleOpen({ params }) {
const serversDB = database.servers; const serversDB = database.servers;
const serversCollection = serversDB.collections.get('servers'); const serversCollection = serversDB.collections.get('servers');
@ -76,11 +86,18 @@ const handleOpen = function* handleOpen({ params }) {
}); });
} }
// If there's no host on the deep link params and the app is opened, just call appInit()
if (!host) { if (!host) {
yield fallbackNavigation();
return; return;
} }
// If there's host, continue
if (!/^(http|https)/.test(host)) { if (!/^(http|https)/.test(host)) {
host = `https://${ params.host }`; host = `https://${ host }`;
} else {
// Notification should always come from https
host = host.replace('http://', 'https://');
} }
// remove last "/" from host // remove last "/" from host
if (host.slice(-1) === '/') { if (host.slice(-1) === '/') {
@ -119,6 +136,8 @@ const handleOpen = function* handleOpen({ params }) {
// if deep link is from a different server // if deep link is from a different server
const result = yield RocketChat.getServerInfo(host); const result = yield RocketChat.getServerInfo(host);
if (!result.success) { if (!result.success) {
// Fallback to prevent the app from being stuck on splash screen
yield fallbackNavigation();
return; return;
} }
yield put(appStart({ root: ROOT_NEW_SERVER })); yield put(appStart({ root: ROOT_NEW_SERVER }));