-
-
Save LukeSmetham/1e1871f59532817976d7fa5dedd5085e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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