diff --git a/src/redux/user/actions.js b/src/redux/user/actions.js index d788c39..2a9e102 100644 --- a/src/redux/user/actions.js +++ b/src/redux/user/actions.js @@ -48,3 +48,5 @@ export const setReady = ready => ({ type: ACTIONS.SET_READY, ready }); export const gotVkUser = user => ({ type: ACTIONS.GOT_VK_USER, user }); export const keyPressed = ({ key }) => ({ type: ACTIONS.KEY_PRESSED, key }); + +export const iframeLoginVk = payload => ({ type: ACTIONS.IFRAME_LOGIN_VK, ...payload }); diff --git a/src/redux/user/constants.js b/src/redux/user/constants.js index a25340d..4a60ebf 100644 --- a/src/redux/user/constants.js +++ b/src/redux/user/constants.js @@ -48,4 +48,6 @@ export const ACTIONS = ({ GOT_VK_USER: 'GOT_VK_USER', KEY_PRESSED: 'KEY_PRESSED', + + IFRAME_LOGIN_VK: 'IFRAME_LOGIN_VK', }: { [key: String]: String }); diff --git a/src/redux/user/sagas.js b/src/redux/user/sagas.js index 101191f..ad953ad 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'; @@ -101,9 +101,18 @@ function* loadMapSaga(path) { return map; } +function* iframeLoginVkSaga({ viewer_id, access_token, auth_key }) { + return yield console.log('GOT', { viewer_id, access_token, auth_key }); +} + function* mapInitSaga() { const { hash } = getUrlData(); + if (window.location.search) { + const { viewer_id, access_token, auth_key } = yield parseQuery(window.location.search); + if (viewer_id && access_token && auth_key) yield put(iframeLoginVk({ viewer_id, access_token, auth_key })); + } + if (hash && /^#map/.test(hash)) { const [, newUrl] = hash.match(/^#map[:/?!](.*)$/); @@ -421,4 +430,6 @@ export function* userSaga() { yield takeLatest(ACTIONS.GOT_VK_USER, gotVkUserSaga); yield takeLatest(ACTIONS.KEY_PRESSED, keyPressedSaga); + + yield takeLatest(ACTIONS.IFRAME_LOGIN_VK, iframeLoginVkSaga); }