From 6ba94881c904a9bc40e14eca787f6c9fb255dadb Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Wed, 9 Oct 2019 20:43:04 +0700 Subject: [PATCH] fixed authorization somehow --- src/containers/node/NodeLayout/index.tsx | 2 +- src/redux/auth/constants.ts | 3 ++- src/redux/auth/sagas.ts | 23 ++++++++++++++++------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/containers/node/NodeLayout/index.tsx b/src/containers/node/NodeLayout/index.tsx index abc69b4c..de6dd97c 100644 --- a/src/containers/node/NodeLayout/index.tsx +++ b/src/containers/node/NodeLayout/index.tsx @@ -64,7 +64,7 @@ const NodeLayoutUnconnected: FC = ({ - + {is_user && } {is_loading_comments || !comments.length ? ( diff --git a/src/redux/auth/constants.ts b/src/redux/auth/constants.ts index ad414940..2fbc9c27 100644 --- a/src/redux/auth/constants.ts +++ b/src/redux/auth/constants.ts @@ -8,8 +8,9 @@ export const AUTH_USER_ACTIONS = { }; export const USER_ERRORS = { + UNAUTHORIZED: 'Вы не авторизованы', INVALID_CREDENTIALS: 'Неверное имя пользователя или пароль. Очень жаль.', - EMPTY_CREDENTIALS: 'Давайте введем логин и пароль. Это обязательно.' + EMPTY_CREDENTIALS: 'Давайте введем логин и пароль. Это обязательно.', }; export const USER_STATUSES = { diff --git a/src/redux/auth/sagas.ts b/src/redux/auth/sagas.ts index 742dc018..752c55b5 100644 --- a/src/redux/auth/sagas.ts +++ b/src/redux/auth/sagas.ts @@ -1,6 +1,6 @@ import { call, put, takeLatest, select } from 'redux-saga/effects'; import { push } from 'connected-react-router'; -import { AUTH_USER_ACTIONS } from '~/redux/auth/constants'; +import { AUTH_USER_ACTIONS, EMPTY_USER, USER_ERRORS } from '~/redux/auth/constants'; import { authSetToken, userSetLoginError, @@ -10,8 +10,6 @@ import { import { apiUserLogin, apiAuthGetUser } from '~/redux/auth/api'; import { modalSetShown, modalShowDialog } from '~/redux/modal/actions'; import { selectToken } from './selectors'; -import { URLS } from '~/constants/urls'; -import { DIALOGS } from '../modal/constants'; import { IResultWithStatus } from '../types'; import { IUser } from './types'; import { REHYDRATE, RehydrateAction } from 'redux-persist'; @@ -22,10 +20,7 @@ export function* reqWrapper(requestAction, props = {}): ReturnType = yield call(reqWrapper, apiAuthGetUser); + console.log({ error, user }); + + if (error) { + yield put( + authSetUser({ + ...EMPTY_USER, + is_user: false, + }) + ); + + return; + } + yield put(authSetUser({ ...user, is_user: true })); }