ronasit/laravel-clerk

Package provides auth guard to auth user via the Clerk

0.0.2-beta 2024-12-05 07:55 UTC

README

Introduction

This package offers an authentication guard to seamlessly integrate Clerk authentication into your Laravel project.

Installation

  1. Use Composer to install the package:
composer require ronasit/laravel-clerk
  1. Publish the package configuration:
php artisan vendor:publish --provider=RonasIT\\Clerk\\Providers\\ClerkServiceProvider
  1. Add a new clerk guard within the guards array in your config/auth.php file:
return [
    'defaults' => [
        'guard' => 'clerk',
        'passwords' => 'users',
    ],

    'guards' => [
        'clerk' => [
            'driver' => 'clerk_session',
            'provider' => 'users',
        ],
        // Other guards...
    ],
  1. Populate the necessary configuration options in config/clerk.php.

Usage

By default, your app returns the User class with just the external_id property, which holds the user's ID in Clerk.

To customize this behavior, you'll need to create your own UserRepository that implements the UserRepositoryContract. Then, rebind it in one of the service providers:

use RonasIT\Clerk\Contracts\ClerkUserRepositoryContract;
use App\Support\Clerk\MyAwesomeUserRepository;

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->bind(ClerkUserRepositoryContract::class, MyAwesomeUserRepository::class);
    }
}