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

fixed auth

This commit is contained in:
muerwre 2019-08-09 15:40:50 +07:00
parent 87d59b4905
commit 92f097d161

View file

@ -12,7 +12,7 @@ import { selectToken } from './selectors';
import { URLS } from '~/constants/urls'; import { URLS } from '~/constants/urls';
import { DIALOGS } from '../modal/constants'; import { DIALOGS } from '../modal/constants';
import { IResultWithStatus } from '../types'; import { IResultWithStatus } from '../types';
import { IToken, IUser } from './types'; import { IUser } from './types';
export function* reqWrapper(requestAction, props = {}): ReturnType<typeof requestAction> { export function* reqWrapper(requestAction, props = {}): ReturnType<typeof requestAction> {
const { access } = yield select(selectToken); const { access } = yield select(selectToken);
@ -29,17 +29,15 @@ export function* reqWrapper(requestAction, props = {}): ReturnType<typeof reques
return result; return result;
} }
function* sendLoginRequestSaga({ username, password }: ReturnType<typeof ActionCreators.userSendLoginRequest>): SagaIterator { function* sendLoginRequestSaga({ username, password }: ReturnType<typeof ActionCreators.userSendLoginRequest>) {
if (!username || !password) return; if (!username || !password) return;
const { error, data: { token, user } }: IResultWithStatus<{ token: string; user: IUser }> = yield call(apiUserLogin, { username, password }); const { error, data: { token, user } }: IResultWithStatus<{ token: string; user: IUser }> = yield call(apiUserLogin, { username, password });
console.log({ token, error }); if (error) { yield put(userSetLoginError(error)); return; }
if (error) return yield put(userSetLoginError(error));
yield put(authSetToken(token)); yield put(authSetToken(token));
yield put(authSetUser(user)); yield put(authSetUser({ ...user, is_user: true }));
yield put(modalSetShown(false)); yield put(modalSetShown(false));
} }