Created
March 6, 2015 10:48
-
-
Save abdullin/0908e878347870de74de to your computer and use it in GitHub Desktop.
Flux action with login
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
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