Skip to content

Instantly share code, notes, and snippets.

@abdullin
Created March 6, 2015 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdullin/0908e878347870de74de to your computer and use it in GitHub Desktop.
Save abdullin/0908e878347870de74de to your computer and use it in GitHub Desktop.
Flux action with login
var client = require("shared/client");
module.exports = function(context, payload, done) {
if (payload.login === undefined) {
throw new Error("Login must be defined");
}
if (payload.password === undefined) {
throw new Error("Password must be defined");
}
context.dispatch("event:LoginStarted");
var login = payload.login;
var password = payload.password;
client.login(login, password, function(err, res) {
if (err !== undefined) {
context.dispatch("event:LoginFailed", err);
done();
} else {
context.dispatch("event:LoginSucceeded", res);
done();
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment