From c2cb4dff4c7f0c43d5640bdc8a921d60ee77cafd Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 11 Aug 2016 01:55:51 +0100 Subject: [PATCH] Support for refactored login token handling loginToken handling is now done by the session loader, so we need to pass in the queryparams to MatrixChat. Also, MatrixChat no longer automatically reloads the page to drop the querystring, so we have to do that ourselves (doing it in index.js allows tokenlogin to be tested). --- src/vector/index.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index a29502f83b..de436ba126 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -44,6 +44,7 @@ var VectorConferenceHandler = require('../VectorConferenceHandler'); var UpdateChecker = require("./updater"); var q = require('q'); var request = require('browser-request'); +import url from 'url'; import {parseQs, parseQsFromFragment} from './url_utils'; @@ -87,13 +88,6 @@ function routeUrl(location) { if (!window.matrixChat) return; console.log("Routing URL "+location); - var params = parseQs(location); - var loginToken = params.loginToken; - if (loginToken) { - window.matrixChat.showScreen('token_login', params); - return; - } - var fragparts = parseQsFromFragment(location); window.matrixChat.showScreen(fragparts.location.substring(1), fragparts.params); @@ -174,6 +168,21 @@ function getConfig() { return deferred.promise; } +function onLoadCompleted() { + // if we did a token login, we're now left with the token, hs and is + // url as query params in the url; a little nasty but let's redirect to + // clear them. + if (window.location.search) { + var parsedUrl = url.parse(window.location.href); + parsedUrl.search = ""; + var formatted = url.format(parsedUrl); + console.log("Redirecting to " + formatted + " to drop loginToken " + + "from queryparams"); + window.location.href = formatted; + } +} + + async function loadApp() { if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) { if (confirm("Vector is not supported on mobile web. Install the app?")) { @@ -209,15 +218,21 @@ async function loadApp() { , document.getElementById('matrixchat')); } else if (validBrowser) { var MatrixChat = sdk.getComponent('structures.MatrixChat'); - var fragParts = parseQsFromFragment(window.location); + + var fragparts = parseQsFromFragment(window.location); + var params = parseQs(window.location); + window.matrixChat = ReactDOM.render( , + realQueryParams={params} + startingFragmentQueryParams={fragparts.params} + enableGuest={true} + onLoadCompleted={onLoadCompleted} + />, document.getElementById('matrixchat') ); }