mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
fixed authorization somehow
This commit is contained in:
parent
2f11bb80aa
commit
6ba94881c9
3 changed files with 19 additions and 9 deletions
|
@ -64,7 +64,7 @@ const NodeLayoutUnconnected: FC<IProps> = ({
|
|||
<Padder>
|
||||
<Group horizontal className={styles.content}>
|
||||
<Group className={styles.comments}>
|
||||
<CommentForm id={0} />
|
||||
{is_user && <CommentForm id={0} />}
|
||||
|
||||
{is_loading_comments || !comments.length ? (
|
||||
<NodeNoComments is_loading={is_loading_comments} />
|
||||
|
|
|
@ -8,8 +8,9 @@ export const AUTH_USER_ACTIONS = {
|
|||
};
|
||||
|
||||
export const USER_ERRORS = {
|
||||
UNAUTHORIZED: 'Вы не авторизованы',
|
||||
INVALID_CREDENTIALS: 'Неверное имя пользователя или пароль. Очень жаль.',
|
||||
EMPTY_CREDENTIALS: 'Давайте введем логин и пароль. Это обязательно.'
|
||||
EMPTY_CREDENTIALS: 'Давайте введем логин и пароль. Это обязательно.',
|
||||
};
|
||||
|
||||
export const USER_STATUSES = {
|
||||
|
|
|
@ -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<typeof reques
|
|||
const result = yield call(requestAction, { access, ...props });
|
||||
|
||||
if (result && result.status === 401) {
|
||||
yield put(push(URLS.BASE));
|
||||
yield put(modalShowDialog(DIALOGS.LOGIN));
|
||||
|
||||
return result;
|
||||
return { error: USER_ERRORS.UNAUTHORIZED, data: {} };
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -56,9 +51,23 @@ function* checkUserSaga({ key }: RehydrateAction) {
|
|||
if (key !== 'auth') return;
|
||||
|
||||
const {
|
||||
error,
|
||||
data: { user },
|
||||
}: 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 }));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue