From 48cf0b93eea43833a47dee9fc7642ba26d355851 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Tue, 20 Apr 2021 17:21:05 +0700 Subject: [PATCH] fixed token checking --- src/redux/store.ts | 10 +++++----- src/redux/user/sagas.ts | 1 + src/utils/api/index.ts | 17 ++++++----------- src/utils/api/types.ts | 13 +++++++++++++ 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/redux/store.ts b/src/redux/store.ts index 48328a5..f3919fb 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -1,6 +1,6 @@ -import { createStore, applyMiddleware, combineReducers, compose, Store } from 'redux'; +import { applyMiddleware, combineReducers, compose, createStore, Store } from 'redux'; -import { persistStore, persistReducer } from 'redux-persist'; +import { persistReducer, persistStore } from 'redux-persist'; import storage from 'redux-persist/lib/storage'; import createSagaMiddleware from 'redux-saga'; @@ -8,15 +8,15 @@ import { createBrowserHistory } from 'history'; import { editorLocationChanged } from '~/redux/editor/actions'; import { PersistConfig, Persistor } from 'redux-persist/es/types'; -import { userReducer, IRootReducer } from '~/redux/user'; +import { IRootReducer, userReducer } from '~/redux/user'; import { userSaga } from '~/redux/user/sagas'; import { editor, IEditorState } from '~/redux/editor'; import { editorSaga } from '~/redux/editor/sagas'; -import { map, IMapReducer } from '~/redux/map'; +import { IMapReducer, map } from '~/redux/map'; import { mapSaga } from '~/redux/map/sagas'; -import { watchLocation, getLocation } from '~/utils/window'; +import { watchLocation } from '~/utils/window'; import { LatLngLiteral } from 'leaflet'; import { setUserLocation, userLogout } from './user/actions'; import { MainMap } from '~/constants/map'; diff --git a/src/redux/user/sagas.ts b/src/redux/user/sagas.ts index f9ee41a..a1c9faa 100644 --- a/src/redux/user/sagas.ts +++ b/src/redux/user/sagas.ts @@ -77,6 +77,7 @@ function* authCheckSaga({ key }: RehydrateAction) { data: { user, random_url }, }: Unwrap = yield call(checkUserToken, { id, + token, }); if (user) { diff --git a/src/utils/api/index.ts b/src/utils/api/index.ts index 38d0a38..d89e12d 100644 --- a/src/utils/api/index.ts +++ b/src/utils/api/index.ts @@ -1,5 +1,5 @@ import { API } from '~/constants/api'; -import { IRootState, IRouteListItem } from '~/redux/user'; +import { IRootState } from '~/redux/user'; import { IUser } from '~/constants/auth'; import { CLIENT } from '~/config/frontend'; import { LatLngLiteral } from 'leaflet'; @@ -7,7 +7,7 @@ import { IRoute } from '~/redux/map/types'; import { INominatimResult } from '~/redux/types'; import { api } from './instance'; import { postMapInterceptor } from '~/utils/api/interceptors'; -import { PostMapRequest, PostMapResponse } from '~/utils/api/types'; +import { CheckTokenRequest, CheckTokenResult, PostMapRequest, PostMapResponse } from '~/utils/api/types'; interface IGetRouteList { min: number; @@ -20,16 +20,11 @@ interface IGetRouteList { export const checkUserToken = ({ id, -}: { - id: IRootState['user']['id']; -}) => + token, +}: CheckTokenRequest) => api - .get<{ - user: IUser; - random_url: string; - routes: IRouteListItem[]; - }>(API.CHECK_TOKEN, { - params: { id }, + .get(API.CHECK_TOKEN, { + params: { id, token }, }); export const getGuestToken = () => diff --git a/src/utils/api/types.ts b/src/utils/api/types.ts index 2fdf3a1..b0ded9a 100644 --- a/src/utils/api/types.ts +++ b/src/utils/api/types.ts @@ -1,4 +1,6 @@ import { IRoute } from '~/redux/map/types'; +import { IUser } from '~/constants/auth'; +import { IRootState, IRouteListItem } from '~/redux/user'; export interface PostMapResponse { route: IRoute; @@ -9,3 +11,14 @@ export interface PostMapResponse { export type PostMapRequest = Partial & { force: boolean; } + +export interface CheckTokenResult { + user: IUser; + random_url: string; + routes: IRouteListItem[]; +} + +export interface CheckTokenRequest { + id: IRootState['user']['id']; + token: string, +}