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

getting token from api

This commit is contained in:
muerwre 2019-08-03 12:21:59 +07:00
parent dc6f72baf1
commit 6f9f255abf

View file

@ -4,26 +4,22 @@ import {AUTH_USER_ACTIONS} from "~/redux/auth/constants";
import * as ActionCreators from '~/redux/auth/actions'; import * as ActionCreators from '~/redux/auth/actions';
import {authSetToken, userSetLoginError} from "~/redux/auth/actions"; import {authSetToken, userSetLoginError} from "~/redux/auth/actions";
import {apiUserLogin} from "~/redux/auth/api"; import {apiUserLogin} from "~/redux/auth/api";
import {modalSetShown} from "~/redux/modal/actions";
function* sendLoginRequestSaga({ username, password }: ReturnType<typeof ActionCreators.userSendLoginRequest>): SagaIterator { function* sendLoginRequestSaga({ username, password }: ReturnType<typeof ActionCreators.userSendLoginRequest>): SagaIterator {
if (!username || !password) return; if (!username || !password) return;
const { error, data: { access, refresh, user }} = yield call(apiUserLogin, { username, password }); const { error, data: { access, refresh }} = yield call(apiUserLogin, { username, password });
console.log({ access, refresh, user, error }); console.log({ access, refresh, error });
if (error) return yield put(userSetLoginError(error)); if (error) return yield put(userSetLoginError(error));
yield put(authSetToken({ access, refresh })); yield put(authSetToken({ access, refresh }));
// const { token, status, user }:
// { token: string, status: number, user: IApiUser } = yield call(apiUserLogin, { username, password }); // todo: get /auth/me
//
// if (!token) return yield put(userSetLoginError({ error: USER_STATUSES[status] || USER_ERRORS.INVALID_CREDENTIALS })); yield put(modalSetShown(false));
//
// const { id, role, email, activated: is_activated } = user;
//
// yield put(userSetUser({ token, id, role, email, username: user.username, is_activated, is_user: true }));
// yield put(push('/'));
} }
function* mySaga() { function* mySaga() {