mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-24 18:46:40 +07:00
fixed token checking
This commit is contained in:
parent
9c436d348c
commit
48cf0b93ee
4 changed files with 25 additions and 16 deletions
|
@ -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 storage from 'redux-persist/lib/storage';
|
||||||
import createSagaMiddleware from 'redux-saga';
|
import createSagaMiddleware from 'redux-saga';
|
||||||
|
|
||||||
|
@ -8,15 +8,15 @@ import { createBrowserHistory } from 'history';
|
||||||
import { editorLocationChanged } from '~/redux/editor/actions';
|
import { editorLocationChanged } from '~/redux/editor/actions';
|
||||||
import { PersistConfig, Persistor } from 'redux-persist/es/types';
|
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 { userSaga } from '~/redux/user/sagas';
|
||||||
|
|
||||||
import { editor, IEditorState } from '~/redux/editor';
|
import { editor, IEditorState } from '~/redux/editor';
|
||||||
import { editorSaga } from '~/redux/editor/sagas';
|
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 { mapSaga } from '~/redux/map/sagas';
|
||||||
import { watchLocation, getLocation } from '~/utils/window';
|
import { watchLocation } from '~/utils/window';
|
||||||
import { LatLngLiteral } from 'leaflet';
|
import { LatLngLiteral } from 'leaflet';
|
||||||
import { setUserLocation, userLogout } from './user/actions';
|
import { setUserLocation, userLogout } from './user/actions';
|
||||||
import { MainMap } from '~/constants/map';
|
import { MainMap } from '~/constants/map';
|
||||||
|
|
|
@ -77,6 +77,7 @@ function* authCheckSaga({ key }: RehydrateAction) {
|
||||||
data: { user, random_url },
|
data: { user, random_url },
|
||||||
}: Unwrap<typeof checkUserToken> = yield call(checkUserToken, {
|
}: Unwrap<typeof checkUserToken> = yield call(checkUserToken, {
|
||||||
id,
|
id,
|
||||||
|
token,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { API } from '~/constants/api';
|
import { API } from '~/constants/api';
|
||||||
import { IRootState, IRouteListItem } from '~/redux/user';
|
import { IRootState } from '~/redux/user';
|
||||||
import { IUser } from '~/constants/auth';
|
import { IUser } from '~/constants/auth';
|
||||||
import { CLIENT } from '~/config/frontend';
|
import { CLIENT } from '~/config/frontend';
|
||||||
import { LatLngLiteral } from 'leaflet';
|
import { LatLngLiteral } from 'leaflet';
|
||||||
|
@ -7,7 +7,7 @@ import { IRoute } from '~/redux/map/types';
|
||||||
import { INominatimResult } from '~/redux/types';
|
import { INominatimResult } from '~/redux/types';
|
||||||
import { api } from './instance';
|
import { api } from './instance';
|
||||||
import { postMapInterceptor } from '~/utils/api/interceptors';
|
import { postMapInterceptor } from '~/utils/api/interceptors';
|
||||||
import { PostMapRequest, PostMapResponse } from '~/utils/api/types';
|
import { CheckTokenRequest, CheckTokenResult, PostMapRequest, PostMapResponse } from '~/utils/api/types';
|
||||||
|
|
||||||
interface IGetRouteList {
|
interface IGetRouteList {
|
||||||
min: number;
|
min: number;
|
||||||
|
@ -20,16 +20,11 @@ interface IGetRouteList {
|
||||||
|
|
||||||
export const checkUserToken = ({
|
export const checkUserToken = ({
|
||||||
id,
|
id,
|
||||||
}: {
|
token,
|
||||||
id: IRootState['user']['id'];
|
}: CheckTokenRequest) =>
|
||||||
}) =>
|
|
||||||
api
|
api
|
||||||
.get<{
|
.get<CheckTokenResult>(API.CHECK_TOKEN, {
|
||||||
user: IUser;
|
params: { id, token },
|
||||||
random_url: string;
|
|
||||||
routes: IRouteListItem[];
|
|
||||||
}>(API.CHECK_TOKEN, {
|
|
||||||
params: { id },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getGuestToken = () =>
|
export const getGuestToken = () =>
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import { IRoute } from '~/redux/map/types';
|
import { IRoute } from '~/redux/map/types';
|
||||||
|
import { IUser } from '~/constants/auth';
|
||||||
|
import { IRootState, IRouteListItem } from '~/redux/user';
|
||||||
|
|
||||||
export interface PostMapResponse {
|
export interface PostMapResponse {
|
||||||
route: IRoute;
|
route: IRoute;
|
||||||
|
@ -9,3 +11,14 @@ export interface PostMapResponse {
|
||||||
export type PostMapRequest = Partial<IRoute> & {
|
export type PostMapRequest = Partial<IRoute> & {
|
||||||
force: boolean;
|
force: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CheckTokenResult {
|
||||||
|
user: IUser;
|
||||||
|
random_url: string;
|
||||||
|
routes: IRouteListItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CheckTokenRequest {
|
||||||
|
id: IRootState['user']['id'];
|
||||||
|
token: string,
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue