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

Allow Facebook users with empty emails #194

Open
wants to merge 2 commits into
base: 3.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,10 @@ Naturally you'll need to create a column for every other piece of information yo

You can store the access token in the database if you need to make requests on behalf of the user when they are not browsing your app (like a 3AM cron job). But in general you won't need to store the access token in the database.

Also you have to make the `email` field nullable. That's because [email permission](https://developers.facebook.com/docs/facebook-login/permissions/#reference-email) for Facebook apps is optional. It means users may choose not to share their email address with your app. Also even if you request the email permission it is not guaranteed you will get an email address. For example, if someone signed up for Facebook with a phone number instead of an email address, the email field may be empty.

By default the `email` field is not null and has a unique index on it. It means it can only accept one user with empty email. Starting from the second user you'll get the database error 'Duplicate entry for unique key'. To fix this just make `email` nullable.

You'll need to generate a migration to modify your `users` table and add any new columns.

> **Note:** Make sure to change `<name-of-users-table>` to the name of your user table.
Expand All @@ -681,6 +685,8 @@ class AddFacebookColumnsToUsersTable extends Migration
$table->bigInteger('facebook_user_id')->unsigned()->index();
// Normally you won't need to store the access token in the database
$table->string('access_token')->nullable();
// Make `email` nullable
$table->string('email')->nullable()->change();
});
}

Expand All @@ -692,6 +698,7 @@ class AddFacebookColumnsToUsersTable extends Migration
'facebook_user_id',
'access_token'
);
$table->string('email')->nullable(false)->change();
});
}
}
Expand Down