mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
getting token from api
This commit is contained in:
parent
dc6f72baf1
commit
6f9f255abf
1 changed files with 7 additions and 11 deletions
|
@ -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() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue