Bonsai CMS backend auth package

Installs: 46

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:bonsaicms-plugin

0.2.1 2021-04-07 14:15 UTC

This package is auto-updated.

Last update: 2024-03-07 21:09:13 UTC


README

This package is a part of Bonsai CMS.

Introduction

This package is a server-side (frontend agnostic) authentication backend for Laravel. It's designed to be used in a combination with an SPA (Single-Page-Application) frontend. It uses these Laravel packages under the hood:

Installation Steps

1. Install the package

$ composer require bonsaicms/auth

2. Update your .env file

Add the following lines to your .env file.

APP_PROTOCOL=http
APP_DOMAIN="localhost:8080"
APP_URL=${APP_PROTOCOL}://${APP_DOMAIN}
SANCTUM_STATEFUL_DOMAINS=${APP_DOMAIN}

3. Publish package resources

$ php artisan vendor:publish --provider="BonsaiCms\Providers\AuthServiceProvider"

4. Register service provider

In your config/app.php file, add the following service provider class in the providers array.

'providers' => [
    ...
+   App\Providers\BonsaiAuthServiceProvider::class,
]

5. Update your HTTP Kernel

Add the following lines to your App\Http\Kernel.php file.

protected $middlewareGroups = [
    ...
    'api' => [
+       \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
        'throttle:api',
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],
+
+   'fortify' => [
+       \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
+       \Illuminate\Routing\Middleware\SubstituteBindings::class,
+   ],
];

6. Update your User model

Update your app/Models/User.php model.

Your model should implement our interface BonsaiCms\Auth\AuthenticatableContract.

Your model should use our trait BonsaiCms\Auth\AuthenticatableTrait.

    <?php
    
    namespace App\Models;

+   use Illuminate\Database\Eloquent\Model;
+   use BonsaiCms\Auth\AuthenticatableTrait;
+   use BonsaiCms\Auth\AuthenticatableContract;
    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
+   class User extends Model implements AuthenticatableContract
    {
-       use HasFactory, Notifiable;
+       use HasFactory, AuthenticatableTrait;

7. Run migrations

$ php artisan migrate