auth: saga for logging through vk

This commit is contained in:
muerwre 2018-12-10 14:54:38 +07:00
parent a0c1f00be4
commit 2608b2687c
3 changed files with 16 additions and 1 deletions

View file

@ -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 });

View file

@ -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 });

View file

@ -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);
}