New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Username / nickname not saved in database #14
Comments
The package won't save any data to your user by default, it assumes your username/email field is being used for accounts that are signed up for manually, not using OAuth. Since the username field is used as login credentials for regular accounts, it would be a little confusing for OAuth-created accounts to have usernames, at least by default. You can easily do this though by passing a closure to your OAuth::login call like so: OAuth::login('facebook', function($user, $details) {
$user->username = $details->nickname;
$user->save();
}); |
Ah, I must've created the User table on auto-pilot then since it contained a username field which was not being filled in :-) Thanks! |
It is odd though.. responses that are being returned via the |
Auth::user()->username won't work unless you actually save that manually. The stuff in the OAuth::login('facebook', function($user, $details) {
$user->username = $details->nickname;
$user->save();
}); So if you want to have access to the nickname after the account is created, you have to save it manually somewhere else, like If you just make this call: OAuth::login('facebook'); ...none of the extra details will be saved anywhere. The extra callback is just in case you do want to save that data (most of the time you would want to save something) but it's impossible for me to guess what you want to save or where you want to save it, so it's just made available in that callback so you can persist that extra meta data yourself wherever and in whatever format you want. By default it only saves their unique ID from the external service and the access token, and even the access token actually doesn't really need to be saved since it's not used later unless you are making extra API calls yourself. |
Hmm. the $user is always NULL. Details are filled in, creating a new user based on that (and saving) works (the user shows up in the DB) but then there is a FatalErrorException caused by
|
This may be a documentation error. If the closure returns the $user it works fine, without errors. However, the user is only being logged in the first time. Logging out and in again (with existing or new data) doesn't work. Edit: Hmm something is calling the logout route after being logged in. Could be the Redirect::intended.. investigating.. |
You shouldn't have to return from the closure, this is where it's being called and the return value is not used: https://github.com/adamwathan/eloquent-oauth/blob/master/src/AdamWathan/EloquentOAuth/OAuthManager.php#L45 Is the $user getting passed in to the closure NULL? If there's a way you can create a simple reproducible situation where the user ends up NULL I can investigate. I know someone else had an issue once where their id column on the user table was not an integer and that created problems. Can you show me what your login call looks like? |
The problem turned out to be
Seems to work fine. I only have to figure out how I can temporarily store the user data in the User rather than having to save it in the DB. But that should be probably be safe enough as it will replace the existing data with new if it has changed. |
Cool glad it's working as expected! |
After a successful login an entry is inserted into
oauth_identities
andusers
. However, theusername
field remains empty. I have tried renaming "username" to "nickname" in the table definition but this didn't have any result.This is being returned by the userdata service and the field is correctly configured in the provider
The text was updated successfully, but these errors were encountered: