PHPackages                             bonsaicms/auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. bonsaicms/auth

ActiveBonsaicms-plugin[Authentication &amp; Authorization](/categories/authentication)

bonsaicms/auth
==============

Bonsai CMS backend auth package

0.2.1(5y ago)050MITPHP

Since Oct 31Pushed 5y ago1 watchersCompare

[ Source](https://github.com/bonsaicms/auth)[ Packagist](https://packagist.org/packages/bonsaicms/auth)[ RSS](/packages/bonsaicms-auth/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

Bonsai CMS - Auth
=================

[](#bonsai-cms---auth)

This package is a part of [Bonsai CMS](https://github.com/bonsaicms).

Introduction
------------

[](#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:

- [Laravel Fortify](https://github.com/laravel/fortify)
- [Laravel Sanctum](https://laravel.com/docs/8.x/sanctum)

Installation Steps
------------------

[](#installation-steps)

### 1. Install the package

[](#1-install-the-package)

```
$ composer require bonsaicms/auth

```

### 2. Update your `.env` file

[](#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

[](#3-publish-package-resources)

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

```

### 4. Register service provider

[](#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

[](#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

[](#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`.

```
