-
Notifications
You must be signed in to change notification settings - Fork 136
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
Problem with normal laravel user table #4
Comments
it's more an incompatibility with the user table setup as per but i would bet that a lot of people have done it that way. "You should modify the onLogin function, or modify your users table, to be compatible. As just one example, the above code does not create usernames, and your users table may require unique usernames for each user." |
I've gone crazy. There is no such problem as per above. I think I had created username in some other side project. Sorry... |
Jaja, no problem. Just keep in mind that the onLogin hook is meant as a way to connect a user from Auth0 to a user from Laravel, without assuming any structure on the Laravel site. Something you may encounter is that the user structure in the quick docs doesn't allow for 2 users having the same email. So you, as a developer can decide if you want to join the accounts, put a provisory email, remove that restriction and many more options. Thats why the plugin tries to be unnopinated and the example is a basic one to build upon |
There are a couple of problems i had with this:
Auth0::onLogin(function($auth0User) {
// See if the user exists
$user = User::where("auth0id", $auth0User->user_id)->first();
if ($user === null) {
// If not, create one
$user = new User();
$user->email = $auth0User->email;
$user->auth0id = $auth0User->user_id;
$user->nickname = $auth0User->nickname;
$user->name = $auth0User->name;
$user->save();
}
return $user;
});
Upon the 2nd user created in thus manner, there is an error because normal laravel user tables have a unique username column.
Creating the 2nd user with the username '' as per above code, causes the problem.
I solved this simply by dropping the username column from the table.
Is that ok? If so you should mention that in the docs.
If have OLD users from BEFORE when you installed the "laravel-auth0" (aka "login") package, where the auth0id = ''.
The above code will log you in as the first user in the database even if you're not logged in because $auth0User->user_id == ''.
Perhaps fix by adding something like
if ($auth0User->user_id != '') { }
The text was updated successfully, but these errors were encountered: