auth: api call?

This commit is contained in:
muerwre 2018-12-10 14:59:09 +07:00
parent 088236c94e
commit a43bac4c26
3 changed files with 21 additions and 2 deletions

View file

@ -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`,
};

View file

@ -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) {

View file

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