Skip to content

Instantly share code, notes, and snippets.

@OleksivO OleksivO/post.js
Created Jan 16, 2019

What would you like to do?
the description for this gist
import {delay} from 'redux-saga';
import {put, call, takeEvery} from 'redux-saga/effects';
import axios from "axios";
import * as actions from '../actions/authorization'
export default function* watchAuthSaga() {...}
function* authUser(action) {
yield put(actions.authStart());
const url = action.signin ? 'SIGNIN_URL' : 'SIGNUP_URL';
try {
const response = call(() => yield, { email:, password: action.password}))
const expirationDate = new Date(new Date().getTime() + * 1000);
yield localStorage.setItem('token',;
yield localStorage.setItem('expirationDate', expirationDate);
yield localStorage.setItem('userId',;
yield put(actions.authSuccess(,;
yield put(actions.checkAuthTimeout(;
} catch (error) {
yield put(actions.authFail(error))
function* checkAuthTimeout(action) {
yield delay(action.expirationTime * 1000);
yield put(actions.logout());
function* logout(action) {
yield localStorage.removeItem('token');
yield localStorage.removeItem('expirationDate');
yield localStorage.removeItem('userId');
yield put(actions.logoutSucceed())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.