1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

fixed authorization somehow

This commit is contained in:
Fedor Katurov 2019-10-09 20:43:04 +07:00
parent 2f11bb80aa
commit 6ba94881c9
3 changed files with 19 additions and 9 deletions

View file

@ -64,7 +64,7 @@ const NodeLayoutUnconnected: FC<IProps> = ({
<Padder> <Padder>
<Group horizontal className={styles.content}> <Group horizontal className={styles.content}>
<Group className={styles.comments}> <Group className={styles.comments}>
<CommentForm id={0} /> {is_user && <CommentForm id={0} />}
{is_loading_comments || !comments.length ? ( {is_loading_comments || !comments.length ? (
<NodeNoComments is_loading={is_loading_comments} /> <NodeNoComments is_loading={is_loading_comments} />

View file

@ -8,8 +8,9 @@ export const AUTH_USER_ACTIONS = {
}; };
export const USER_ERRORS = { export const USER_ERRORS = {
UNAUTHORIZED: 'Вы не авторизованы',
INVALID_CREDENTIALS: 'Неверное имя пользователя или пароль. Очень жаль.', INVALID_CREDENTIALS: 'Неверное имя пользователя или пароль. Очень жаль.',
EMPTY_CREDENTIALS: 'Давайте введем логин и пароль. Это обязательно.' EMPTY_CREDENTIALS: 'Давайте введем логин и пароль. Это обязательно.',
}; };
export const USER_STATUSES = { export const USER_STATUSES = {

View file

@ -1,6 +1,6 @@
import { call, put, takeLatest, select } from 'redux-saga/effects'; import { call, put, takeLatest, select } from 'redux-saga/effects';
import { push } from 'connected-react-router'; 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 { import {
authSetToken, authSetToken,
userSetLoginError, userSetLoginError,
@ -10,8 +10,6 @@ import {
import { apiUserLogin, apiAuthGetUser } from '~/redux/auth/api'; import { apiUserLogin, apiAuthGetUser } from '~/redux/auth/api';
import { modalSetShown, modalShowDialog } from '~/redux/modal/actions'; import { modalSetShown, modalShowDialog } from '~/redux/modal/actions';
import { selectToken } from './selectors'; import { selectToken } from './selectors';
import { URLS } from '~/constants/urls';
import { DIALOGS } from '../modal/constants';
import { IResultWithStatus } from '../types'; import { IResultWithStatus } from '../types';
import { IUser } from './types'; import { IUser } from './types';
import { REHYDRATE, RehydrateAction } from 'redux-persist'; import { REHYDRATE, RehydrateAction } from 'redux-persist';
@ -22,10 +20,7 @@ export function* reqWrapper(requestAction, props = {}): ReturnType<typeof reques
const result = yield call(requestAction, { access, ...props }); const result = yield call(requestAction, { access, ...props });
if (result && result.status === 401) { if (result && result.status === 401) {
yield put(push(URLS.BASE)); return { error: USER_ERRORS.UNAUTHORIZED, data: {} };
yield put(modalShowDialog(DIALOGS.LOGIN));
return result;
} }
return result; return result;
@ -56,9 +51,23 @@ function* checkUserSaga({ key }: RehydrateAction) {
if (key !== 'auth') return; if (key !== 'auth') return;
const { const {
error,
data: { user }, data: { user },
}: IResultWithStatus<{ user: IUser }> = yield call(reqWrapper, apiAuthGetUser); }: IResultWithStatus<{ user: IUser }> = 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 })); yield put(authSetUser({ ...user, is_user: true }));
} }