I'm integrating fb into my D6 site and have hit a snag. I've installed the various fb modules, and the Facebook "connect" button is showing up in my registration form at /user/register. Here's what happens:
* I click the FB button and go through the FB authorization process.
* /user/register refreshes, the user's Facebook name and picture is shown, and the username field has been populated with the user's Facebook name.
* I fill out the other stuff that, through the profile module on my reg form: email address and a couple profile fields (first name and last name). I hit submit.
* The form gets handled and I'm sent to the appropriate result page. I also have User Settings set up to send the new user an email after registration, and that email does get sent.
I now have this:
* A new user exists in the users table.
* $fbu is properly set to the user's FB uid, but…
* The user is not logged in: $user is null.
If I click on the Facebook Connect button again, nothing happens other than the alert in the javascript console telling me that FB.login() was called when the user is already connected (which he is, since $fb has a value). I've tried to log out, but I can't logout since I'm not logged in.
What I CAN do is go to another browser and, as admin, go into the new user's settings and give him a password. I can then go to /user/login in the original browser and log in with the user's email address and newly-assigned password. Once I've done that, everything works properly: I have both a defined $user and a defined $fbu; I can logout, which takes me out of both FB and Drupal, and I can log back in via the Facebook connect button.
So, any clues on what might be going on here? Shouldn't the user get logged in, and thus $user set, after doing the registration and authorization bit? Thanks much!
Comments
Comment #1
jim_at_miramontes commentedA possibly relevant update: I just noticed that, after doing the basic registration attempt with the Facebook button, there is no entry in fb_user for this newly-added user. However, once I give the user a password and then have the user log in (cf. "What I CAN do..." above), an fb_user entry for that user is created. Hope that helps...
Comment #2
jim_at_miramontes commentedOne more thing: I have the app's settings in DfB configured as "Do not create accounts automatically" and "Map account when both local uid and Facebook id are known". Maybe I need to do this latter bit of work myself?
Comment #3
Dave Cohen commentedYou're describing how it is intended to work. Drupal doesn't log you in right away when you register, and modules/fb doesn't associate your fbu to your uid until you are logged in.
That said, it would be convenient to automatically log a user in when they register and are already connected. Its a change to Drupal's normal process (login toboggan does something like this). Would probably require a custom submit handler for the registration form in fb_user, or maybe a clause in fb_user_user(). And there should be a way for admin to disable it (restore normal drupal process, which ensures that a users email is actually read).
Comment #4
jim_at_miramontes commentedThanks for the note. Some of this is my own fault, as I've got a certain amount of custom funk around the reg process (getting values for and setting profile variables). But, as a test, I set up DfF on another D6 site that just does a standard reg process. This one was configured as "create local account if user has authorized the app", and, when I use the Facebook Connect button to register, everything works the way it "should" -- a new account is created, and the user is logged in to it.
Anyway, I'm starting to get a handle on the architecture here, and will explore the submit handler matter. Login toboggan is a good pointer; thanks much!
Comment #5
johnTEN commentedDave,
I was confused by this also. So, if I understand this right, the module does not create user accounts, So if I want FB users to be able to create content on our site I need to have them create regular accounts first, then have them link facebook? At drupalforfacebook.org it seems like users can just login via facebook and then can create content. How do you get is so that there is only the facebook login to create users?
Comment #6
jim_at_miramontes commentedJust to restate what I'm seeing here, for clarity:
* On a site that I have configured as "create local account if user has authorized the app", DFF creates a new Drupal user, links that user to his Facebook account, and logs him in.
* On a site that I have configured as "Do not create accounts automatically" and "Map account when both local uid and Facebook id are known", DFF creates a new Drupal user, but does not link him to his Facebook account (even though he's currently logged into Facebook) until hs logs into Drupal with a Drupal-assigned username and password.
There may be other things going on wrt my profile variables, but that's to be defined.
Comment #7
jim_at_miramontes commentedProgress, of a sort: The following _user hook successfully logs in a user after authenticating with Facebook (per my issue above):
Fortunately, my module has a lower weight (due to its filename) than fb_user, so fb_user_user has run and done the preparatory work. If your module is aaa_mymodule, you would probably not be so lucky, and might have to explicitly fiddle with the module weights to get things ordered properly.
CAVEATS: I don't really understand what I've done here other than solve my short-term problem. I may be introducing all sorts of awful things into the register/login process. You'd have to be crazy to use the above code. Stop, now. Really.
Having said that, it does at least succeed in getting the user logged in after the FB registration. I'd love it if there were a more principled solution to this problem (i.e. one written by somebody who actually knows what he or she is doing).
Just checking in,
Jim
Comment #8
Dave Cohen commentedYour code will have unintended consequences, like if you create a new account as an administrator, I think you'll find yourself logged in as the new user. I think you'll also be logged in whether you're connected to facebook or not.
You probably want to test that $GLOBAL['user']->uid == 0 and also that fb_facebook_user() returns a facebook id.