Skip to content
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

Closed
patekuru opened this issue May 7, 2014 · 3 comments
Closed

Problem with normal laravel user table #4

patekuru opened this issue May 7, 2014 · 3 comments

Comments

@patekuru
Copy link

patekuru commented May 7, 2014

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 != '') { }

@patekuru
Copy link
Author

patekuru commented May 7, 2014

it's more an incompatibility with the user table setup as per
http://laravel.com/docs/quick

but i would bet that a lot of people have done it that way.
Maybe this just calls for the docs to mention something less specific like:

"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."

@patekuru
Copy link
Author

patekuru commented May 7, 2014

I've gone crazy. There is no such problem as per above. I think I had created username in some other side project. Sorry...

@patekuru patekuru closed this as completed May 7, 2014
@hrajchert
Copy link
Contributor

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants