Closed dralletje closed 8 years ago
Hi @dralletje
Does this issue mean that there are currently no established way to use user authentication with this driver ? I took a look at the code and there seems to be some auth related parts but I could not figure how it worked.
@nylo-andry Looks like it does not :P, the auth related stuff is to listen if you are already authenticated. I've worked it around keeping a ref of the original firebase object and use it to register/authenticate.
LIke example:
let firebaseRef = new Firebase('https://meetup-planner.firebaseio.com');
const sources = {
DOM: makeDOMDriver('#application'),
firebase: makeFirebaseDriver(firebaseRef),
};
And then:
function registerAndLogin(firebaseRef, email, password) {
// Probably the biggest hack for now.. this should return an observable
// instead of triggering the authWithPassword..
firebaseRef.createUser({
email: email,
password: password
}, function(error, userData) {
// TODO: handle errors
firebaseRef.authWithPassword({
email: email,
password: password
})
});
}
Is not the right pattern (side effects!) but got the job done :S. You can check the repository using this snippet here: https://github.com/Rastikko/meetup-planner-cyclejs/blob/master/src/components/register/register-model.js
This indeed is not the ideal.
Your API proposition does make sense. For the Facebook authentication, I think you may want to use a .map unless there is something I do not get under the hood.
Are you currently working on this or do you need help? I may try to come up with a pull request if I have time, at least for the email authentication.
Thanks for the temporary example!
@Rastikko Oh my, you are using this module already, awesome, exciting, AND SCARY :fearful: I'll get something out today (I've already worked on it) and we can check together if it looks good :smile:
@nylo-andry allow me to build this real quick, and see if the API makes sense in real life as well :)
Yeah man, you did a good job @dralletje . I'm still catching up with cycle.js tech stack but I wanted learn more deeply how drivers are made off.
I got a tight schedule but I'm probably will be coding with cycle this weekend. So if you want to connect and work together on implementing authentication and registration would be awesome. (I really want to remove the hack from my code)
@Rastikko I've landed a big commit, that should solve it as I described above. You may have seen that I commented my code to the extreme, so I hope you feel invited to play with it :-)
@nylo-andry I've added an example. Not as big as I promised, and it doesn't contain as much comments as I want, but I really need to focus on some other work before I can continue :( I hope it gives you an idea of how the authentication works!
This is just my own todo, hehehe
Would look something like
And I guess the easy facebook connection would be something like
Only feedback for a successful login would be the change of the uid$ observable. Should it emit an error when authentication failed? Is it easy to reconnect to the observable afterwards using .retryOnError?
Creation of users is happening automatically for non existing facebook users, but what about email and password? I'd guess we can use another special operator, but I' not sure