Skip to content

Instantly share code, notes, and snippets.

@LukeSmetham
Created September 23, 2019 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LukeSmetham/1e1871f59532817976d7fa5dedd5085e to your computer and use it in GitHub Desktop.
Save LukeSmetham/1e1871f59532817976d7fa5dedd5085e to your computer and use it in GitHub Desktop.
import { all, call, put } from 'redux-saga/effects';
import shortid from 'shortid';
// Utils //
import history from 'utils/history';
import fetch from 'utils/fetch';
// Types //
import { LOGIN } from '../types';
export default function*({ conferenceAlias, data: { username } }) {
try {
username = username.toLowerCase().replace(/\s/g, '_');
const {
data: { token, user },
} = yield call(fetch, 'post', '/token', {
username,
});
localStorage.setItem('user', JSON.stringify(user));
localStorage.setItem('streamToken', token);
if (!conferenceAlias) {
conferenceAlias = shortid();
}
yield all([
put({
type: LOGIN.SUCCESS,
user,
token,
}),
call(history.push, `/${conferenceAlias}`),
]);
} catch (error) {
yield put({
type: LOGIN.ERROR,
error,
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment