Skip to content

Instantly share code, notes, and snippets.

@johnthepink
Created September 21, 2016 16:53
Show Gist options
  • Save johnthepink/2d429f7ae3b2ffbcd4a207f184c2f652 to your computer and use it in GitHub Desktop.
Save johnthepink/2d429f7ae3b2ffbcd4a207f184c2f652 to your computer and use it in GitHub Desktop.
function* login() {
const currentState = yield select();
const { data } = currentState.accounts;
if (data.email && data.password) {
const { email, password } = data;
// set the UI to show the loading screen
yield put(actions.loading());
try {
// make the call to try and login
const isAuthorized = yield cps(accounts.login, email, password);
// this should always be true shouldn't it?
if (isAuthorized) {
// return Meteor login to parent saga
yield cps(Meteor.loginWithPassword, email, password);
if (isAuthorized) {
return { result: isAuthorized };
}
return { error: new Meteor.Error("An unkown error occured") };
}
} catch (error) {
return { error };
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment