diff --git a/src/redux/user/sagas.js b/src/redux/user/sagas.js index db6a06a..b69e8bb 100644 --- a/src/redux/user/sagas.js +++ b/src/redux/user/sagas.js @@ -12,7 +12,7 @@ import { setSaveOverwrite, setSaveSuccess, setTitle, setUser } from '$redux/user/actions'; -import { getUrlData, pushPath } from '$utils/history'; +import { getUrlData, parseQuery, pushPath } from '$utils/history'; import { editor } from '$modules/Editor'; import { ACTIONS } from '$redux/user/constants'; import { MODES } from '$constants/modes'; @@ -104,7 +104,9 @@ function* loadMapSaga(path) { function* mapInitSaga() { const { hash } = getUrlData(); - console.log('got credentials', window.location); + const { viewer_id, access_token } = yield parseQuery(window.location.search); + + if (viewer_id && access_token) console.log('GOT THEM!', { viewer_id, access_token }); if (hash && /^#map/.test(hash)) { const [, newUrl] = hash.match(/^#map[:/?!](.*)$/); diff --git a/src/utils/format.js b/src/utils/format.js index 4956f2d..e12db6d 100644 --- a/src/utils/format.js +++ b/src/utils/format.js @@ -8,5 +8,4 @@ export const toHours = (info) => { return `${hrs}:${lmin}`; }; - export const toTranslit = string => ru.reduce((text, el, i) => (text.replace(new RegExp(ru[i], 'g'), en[i])), (String(string) || '')); diff --git a/src/utils/history.js b/src/utils/history.js index 67d4fa2..601efb5 100644 --- a/src/utils/history.js +++ b/src/utils/history.js @@ -13,3 +13,16 @@ export const getUrlData = (url = getPath()) => { path, mode, host, hash }; }; + +// Parses query string +export const parseQuery = (queryString: string) => { + let params = {}; + const queries = decodeURIComponent(queryString) + .substring(queryString.substr(0, 1) === '?' ? 1 : 0) + .split('&'); + for (let i = 0, l = queries.length; i < l; i += 1) { + const temp = queries[i].split('='); + params = { ...params, [temp[0]]: temp[1] }; + } + return params; +};