Why Use Laravel Socialite for Facebook Authentication in Laravel 11?
Social authentication is exploding in 2026—easy, password-free logins reduce cart abandonment by 30% (per Medium/DEV.to benchmarks). Laravel Socialite handles OAuth for Facebook sign-in in Laravel 11 seamlessly, paired with Breeze for UI scaffolding. No more custom sessions!
Table Of Content
1 Prerequisites for Laravel Socialite Facebook Setup
2.) Composer, Node.js 20+.
3.) MySQL 8+ (or PostgreSQL).
4.) Facebook Developer Account (free).
2 Introduction
Adding social login to your Laravel application is one of the best ways to improve user experience, reduce registration friction, and increase conversion rates. Instead of forcing users to create yet another password, you let them sign in instantly with their existing social accounts — starting with Facebook
.In this step-by-step guide, you'll learn how to implement Facebook sign-in in Laravel 11 using two powerful first-party packages:
- Laravel Socialite — the official library that provides a clean, fluent interface for OAuth authentication with multiple providers.
- Laravel Breeze — the lightweight authentication starter kit that gives you beautiful, modern login/register views out of the box (perfect for adding social buttons).
Laravel Socialite is not included by default in a fresh Laravel installation, so you'll add it via Composer. Once set up, it handles the entire OAuth flow — redirecting users to Facebook, processing the callback, and retrieving user data — with minimal code.
As of Laravel 11/12 (2026), Socialite officially supports the following OAuth providers out of the box:
- X (formerly Twitter)
- GitHub
- GitLab
- Bitbucket
- Slack.
(For hundreds of additional providers like Discord, Reddit, Twitch, Instagram, and more, check the excellent community package collection at socialiteproviders.com.)
In this tutorial, we'll focus specifically on Facebook OAuth login because it's one of the most popular and reliable options for user authentication. By the end, you'll have a fully working "Login with Facebook" button integrated into your Breeze-powered auth pages — secure, production-ready, and easy to extend to other providers later. Let's get started!
3 Install Fresh Laravel 11 Project
3.1 Install Laravel Project
composer create-project laravel/laravel facebook-socialite-app
Then, navigate to your project directory:
cd facebook-socialite-app
3.2 Configure MySql Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel11_socialite
DB_USERNAME=root
DB_PASSWORD=
4 Install Laravel Breeze & Socialite Packages
4.1 Install Breeze Package
Breeze scaffolds auth UI—perfect for laravel 11 socialite facebook integration.
Use the following command to Install Laravel Breeze Package
composer require laravel/breeze --dev
After Composer has installed the Laravel Breeze package, you should run the breeze:install Artisan command. This command publishes the authentication views, routes, controllers, and other resources to your application.
php artisan breeze:install
php artisan migrate
npm install
npm run dev
4.2 Install Socialite Package
composer require laravel/socialite
5 Create Facebook OAuth App (developers.facebook.com)
5.1 Login into Facebook Developers Portal
5.2 Create a Facebook App

5.3 Configure OAuth Settings


Fill the Details of the App in following Screen and Press " Create App " Button

In the Facebook App dashboard, navigate to " App Settings" Menu and then "Basic"

Now Copy App Id and App Secret to update in .env file and enter the website Domain URL in App Domains field, Again Scroll down in same screen to "Add Platform" details then Select Website and update Site URL.


5.4 Update App Information


Now fill the authorised redirect URIs. This is the URI that we will use to redirect user after they choose their Facebook account to login to our web. For example here I use http://127.0.0.1:8000/callback/facebook for the callback URI..

6 Configure Facebook Credentials in Laravel
6.1 .env
FACEBOOK_CLIENT_ID=Your Client ID
FACEBOOK_CLIENT_SECRET=Your Client Secret
FACEBOOK_REDIRECT_URI=http://127.0.0.1:8000/callback/facebook
6.2 config/services.php:
<?php
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => env('FACEBOOK_REDIRECT'),
],
?>
6.3 Database Migration: Add facebook_id to Users
php artisan make:migration add_facebook_id_to_users
In the generated new migration file, update the up and down methods as described below:
database/migrations/2024_03_27_110820_add_facebook_id_to_users.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('facebook_id')->after('password')->nullable()->unique();
});
}
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('facebook_id');
});
}
};
Use the following command to run the migration to update your database.
php artisan migrate
6.4 Update the User Model
app/Models/User.php
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable
{
use HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
'facebook_id'
];
/**
* The attributes that should be hidden for serialization.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
}
?>
7 Create FacebookSocialiteController
php artisan make:controller Auth/FacebookSocialiteController
app/Http/Controllers/FacebookLoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Laravel\Socialite\Facades\Socialite;
use Exception;
class FacebookSocialiteController extends Controller
{
public function redirectToFacebook()
{
return Socialite::driver('facebook')->redirect();
}
public function handleFacebookCallback(Request $request)
{
try {
$facebookUser = Socialite::driver('facebook')->user();
// Check existing by facebook_id or email (best practice—FB may null email)
$user = User::where('facebook_id', $facebookUser->id)
->orWhere('email', $facebookUser->email)
->first();
if ($user) {
Auth::login($user);
} else {
$user = User::create([
'name' => $facebookUser->name,
'email' => $facebookUser->email ?? 'fb_' . $facebookUser->id . '@temp.com',
'facebook_id' => $facebookUser->id,
'password' => bcrypt(Str::random(16)), // Secure random—no dummy!
]);
Auth::login($user);
}
return redirect('/dashboard'); // Breeze dashboard
} catch (Exception $e) {
return redirect('/login')->with('error', 'Facebook login failed: ' . $e->getMessage());
// Log: \Log::error($e);
}
}
}
?>
Security Upgrades (2026 best practices from Reddit/DEV.to):
- Email fallback (FB allows phone-only).
- Random password (not 'my-facebook'—vulnerable!).
- Exception handling → User-friendly error.
- Add middleware: ->middleware('throttle:60,1') for rate limit.
8 Define Routes for Facebook OAuth
routes/web.php
use App\Http\Controllers\Auth\FacebookSocialiteController;
Route::get('/auth/facebook', [FacebookSocialiteController::class, 'redirectToFacebook'])->name('facebook.redirect');
Route::get('/auth/facebook/callback', [FacebookSocialiteController::class, 'handleFacebookCallback'])->name('facebook.callback');
9 Add Facebook Login Button to Breeze Views
resources/views/auth/login.blade.php
<div class="social-login mt-4">
<a href="{{ route('facebook.redirect') }}" class="btn btn-primary w-100">
<img src="{{ asset('images/facebook-login-button.png') }}" alt="Facebook Login Button for Laravel 11 Socialite OAuth" width="20" height="20">
Login with Facebook
</a>
<p class="text-center mt-2">
<small>New to Laravel? Check <a href="/category/laravel-programming-sample-code">Laravel Sample Code</a></small>
</p>
</div>
10 Folder Structure After Setup
11 Test Laravel 11 Facebook Socialite Login
php artisan serve
- Visit http://127.0.0.1:8000/login.
- Click "Login with Facebook" → Authorize → Dashboard!
Production Tips:
- HTTPS via Let's Encrypt.
- Queue jobs for heavy traffic.
- Sanctum for API: See Google post.
12 Conclusion
Written by Revathi M
PHP Developer & Technical Writer · 10+ years building web applications with CodeIgniter and Laravel
Revathi specializes in PHP backend development, authentication systems, and REST API design. She writes practical, production-tested tutorials at Get Sample Code to help developers build secure applications faster.
Frequently Asked Questions
You need PHP 8.2 or higher, Composer, a MySQL database, and a Facebook account to create a developer app.
Run `composer create-project laravel/laravel facebook-auth-app`, then `cd facebook-auth-app`.
Install Breeze with `composer require laravel/breeze --dev`, then `php artisan breeze:install`, `php artisan migrate`, `npm install`, and `npm run dev`. Install Socialite with `composer require laravel/socialite`.
Go to the Facebook Developers Portal[](https://developers.facebook.com/), create an app, select 'Authenticate and request data from users with Facebook Login', copy App ID and Secret, and add Valid OAuth Redirect URIs (e.g., `http://127.0.0.1:8000/callbac
Add `FACEBOOK_CLIENT_ID`, `FACEBOOK_CLIENT_SECRET`, and `FACEBOOK_REDIRECT_URI=http://127.0.0.1:8000/callback/facebook` to the `.env` file. Then add the 'facebook' array to `config/services.php`.
Run `php artisan make:migration add_facebook_id_to_users`, add `$table->string('facebook_id')->nullable()->unique();` in the migration, then run `php artisan migrate`. Update the User model's `$fillable` array to include 'facebook_id'.
Run `php artisan make:controller FacebookSocialiteController`, then implement `redirectToFacebook()` to redirect using Socialite and `handleCallback()` to handle the user response, find or create the user (with a dummy password), and log them in.
In `routes/web.php`, add `Route::get('auth/facebook', [FacebookSocialiteController::class, 'redirectToFacebook']);` and `Route::get('callback/facebook', [FacebookSocialiteController::class, 'handleCallback']);`.
In the login view (e.g., from Breeze), add <a href=`{{ url('auth/facebook') }}`><img src='images/facebook_button.png'></a> or a similar button linking to `/auth/facebook`.
The Valid OAuth Redirect URI in the Facebook app settings must exactly match the `FACEBOOK_REDIRECT_URI` in `.env` and the callback route (including http:// and port).
Use the try-catch block with `dd($e->getMessage())` to debug. Common causes: invalid Client ID/Secret, mismatched redirect URI, or missing permissions in the Facebook app.
Since Facebook login doesn't provide a password, the tutorial uses `bcrypt('my-facebook')` as a placeholder. In production, consider passwordless strategies or hiding password fields.
The tutorial checks by `facebook_id`. If found, logs in; otherwise, creates a new user with name, email, and facebook_id from the Socialite response.
Run `php artisan serve`, visit `http://127.0.0.1:8000`, go to login, click the Facebook button, and complete the OAuth flow.
