From a43bac4c261ff8317217fa3190c079c5bc790c21 Mon Sep 17 00:00:00 2001 From: muerwre Date: Mon, 10 Dec 2018 14:59:09 +0700 Subject: [PATCH] auth: api call? --- src/constants/api.js | 1 + src/redux/user/sagas.js | 19 +++++++++++++++++-- src/utils/api.js | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/constants/api.js b/src/constants/api.js index 9767b3f..b299d96 100644 --- a/src/constants/api.js +++ b/src/constants/api.js @@ -3,6 +3,7 @@ import { CLIENT } from '$config/frontend'; export const API = { GET_GUEST: `${CLIENT.API_ADDR}/auth`, CHECK_TOKEN: `${CLIENT.API_ADDR}/auth`, + IFRAME_LOGIN_VK: `${CLIENT.API_ADDR}/auth/iframe/vk`, GET_MAP: `${CLIENT.API_ADDR}/route`, POST_MAP: `${CLIENT.API_ADDR}/route`, }; diff --git a/src/redux/user/sagas.js b/src/redux/user/sagas.js index 9befdd6..4b52f42 100644 --- a/src/redux/user/sagas.js +++ b/src/redux/user/sagas.js @@ -1,7 +1,15 @@ 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, getVkIframeUser, getVkUserInfo, postMap } from '$utils/api'; +import { + checkIframeToken, + checkUserToken, + getGuestToken, + getStoredMap, + getVkIframeUser, + getVkUserInfo, + postMap +} from '$utils/api'; import { hideRenderer, iframeLoginVk, setActiveSticker, setAddress, @@ -146,7 +154,14 @@ function* authCheckSaga() { 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 (viewer_id && access_token && auth_key) { + const user = yield call(checkIframeToken, { viewer_id, access_token, auth_key }); + + if (user) { + yield put(setUser(user)); + return yield call(mapInitSaga); + } + } } if (id && token) { diff --git a/src/utils/api.js b/src/utils/api.js index c9f30bc..96a8004 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -33,3 +33,6 @@ export const postMap = ({ distance, }).then(result => (result && result.data && result.data)); +export const checkIframeToken = ({ id, token }) => axios.get(API.IFRAME_LOGIN_VK, { + params: { viewer_id, access_token, auth_key } +}).then(result => (result && result.data));