auth: added login through vk iframe

This commit is contained in:
muerwre 2018-12-10 13:00:44 +07:00
parent 678f2b17a4
commit 9427866e60
5 changed files with 75 additions and 3 deletions

View file

@ -5,4 +5,5 @@ export const API = {
CHECK_TOKEN: `${CLIENT.API_ADDR}/auth`,
GET_MAP: `${CLIENT.API_ADDR}/route`,
POST_MAP: `${CLIENT.API_ADDR}/route`,
VK_IFRAME_AUTH: `${CLIENT.API_ADDR}/auth/social/vk_iframe`,
};

View file

@ -1,7 +1,7 @@
import { REHYDRATE } from 'redux-persist';
import { delay } from 'redux-saga';
import { takeLatest, select, call, put, takeEvery, race, take } from 'redux-saga/effects';
import { checkUserToken, getGuestToken, getStoredMap, postMap } from '$utils/api';
import { checkUserToken, getGuestToken, getStoredMap, getVkIframeUser, postMap } from '$utils/api';
import {
hideRenderer,
setActiveSticker, setAddress,
@ -102,11 +102,19 @@ function* loadMapSaga(path) {
return map;
}
function* vkIframeAuth({ viewer_id, access_token }) {
const user = yield call(getVkIframeUser, { viewer_id, access_token });
if (user) return yield put(setUser(user));
}
function* mapInitSaga() {
const { hash } = getUrlData();
const { viewer_id, access_token } = yield parseQuery(window.location.search);
// const viewer_id = '360004';
// const access_token = '35baba3da5ac109775bc818f9f04d031ffeeb5a0f36afb42c3ab9a45035b04a12e7c70478c19dde07752b';
if (viewer_id && access_token) console.log('GOT THEM!', { viewer_id, access_token });
if (viewer_id && access_token) yield call(vkIframeAuth, { viewer_id, access_token });
if (hash && /^#map/.test(hash)) {
const [, newUrl] = hash.match(/^#map[:/?!](.*)$/);

View file

@ -31,4 +31,8 @@ export const postMap = ({
force,
logo,
distance,
}).then(result => (result && result.data && result.data));
}).then(result => (result && result.data && result.data)).catch(() => null);
export const getVkIframeUser = ({ viewer_id: user_id, access_token }) => (axios.get(API.VK_IFRAME_AUTH, {
params: { user_id, access_token }
}).then(result => (result && result.data))).catch(() => null);