PHPackages                             notion/swaycookie - 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. notion/swaycookie

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

notion/swaycookie
=================

A custom Laravel authentication package with Redis and database fallback for API authentication.

v1.4.4(6mo ago)045MITPHPPHP ^8.1 || ^8.2 || ^8.3

Since Jul 23Pushed 6mo agoCompare

[ Source](https://github.com/sayednaweed/sway-cookie)[ Packagist](https://packagist.org/packages/notion/swaycookie)[ RSS](/packages/notion-swaycookie/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (10)Used By (0)

Notion Sway
===========

[](#notion-sway)

### What is Included:

[](#what-is-included)

- **Project Introduction**: Brief overview of the package.
- **Features**: Key features of the package listed in bullet points.
- **Installation**: Step-by-step guide to install and publish the configuration file.
- **Usage**: How to configure and use the package in your Laravel project.
- **Configuration**: Details of the `config/sway.php` file and how to adjust settings.
- **Contribute**: How users can contribute to the project.
- **License**: Specifies that the package is licensed under the MIT License.

🎉 **Notion Sway** is a custom Laravel authentication package that provides a flexible JWT-based authentication system with database fallback options for API authentication.

Features
--------

[](#features)

- **JWT token-based API authentication**: Secure API authentication with JWT tokens.
- **Redis and database fallback authentication methods**: Provides fallback methods in case the primary authentication method fails.
- **Customizable guards**: Easily customize authentication guards and configuration.
- **Middleware to protect routes**: Use middleware to protect routes with custom authentication.
- **Easy integration into Laravel**: Quick and simple integration into your existing Laravel applications.
- **Fully configurable**: Configure JWT token expiration time and token prefix.
- **Flexible authentication**: Supports multiple authentication methods (Redis, Database).

Installation
------------

[](#installation)

To install the package, run the following command in your Laravel project:

Installation
------------

[](#installation-1)

```
$ composer require notion/sway
$ php artisan vendor:publish --provider="Sway\Providers\SwayAuthServiceProvider"

```

Usage
-----

[](#usage)

### Configure Authentication Guard

[](#configure-authentication-guard)

In your `config/auth.php` file, configure the `sway` guard by adding it to the `guards` array:

```
'guards' => [
    'user:api' => [
        'driver' => 'sway',
        'provider' => 'users',  // Define the provider for your model
    ],
    'admin:api' => [
        'driver' => 'sway',
        'provider' => 'admins',  // Define the provider for your model
    ],
],
```

### Protect Routes with Middleware

[](#protect-routes-with-middleware)

In your `routes/web.php` or `routes/api.php` file, set `authorized` middleware then pass the guard to middleware. This is required to get correct auth user while in controller:

```
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

Route::prefix('v1')->middleware(["authorized:" . 'user:api'])->group(function () {
    // Your routes
});

Route::prefix('v1')->middleware(["authorized:" . 'admin:api'])->group(function () {
    // Your routes
});
```

### Generate token

[](#generate-token)

In order to generate token call `attempt()` method on the `guard`

- **Important**: Make sure to pass array and must hold email and password data.
- **Output**: After success it will return `access_token` and `refresh_token`.

```
public function login(Request $request)
    {
        // Validate the request input
        $request->validate([
            'email' => 'required|email',
            'password' => 'required|string',
        ]);

        $credentials = $request->only('email', 'password');

        // Use the custom guard to attempt login and generate tokens
        $accessToken = Auth::guard('user:api')->attempt($credentials);

        return response()->json([
            'tokens' => $accessToken,
            'token_type' => 'bearer',
        ]);
    }
```

### Get Authenticated User

[](#get-authenticated-user)

To obtain the `auth user` you can get through `Guard` or `Request`:

```
// Get Authenticated User model
Auth::guard('user:api')->user();
// Get Authenticated Admin model
Auth::guard('admin:api')->user();
```

- **OR**:

```
// Recomended approach
$request->user()
```

### Invalidate Token

[](#invalidate-token)

- **Update Model**: use `InvalidatableToken` on your model:

```
use Sway\Traits\InvalidatableToken;

class User extends Authenticatable
{
    use InvalidatableToken;
}
```

- **Clear Token**: call `invalidateToken` to delete token:

```
public function logout(Request $request)
{
    $user = $request->user();
    $deleted = $user->invalidateToken(); // Calls the invalidateToken method defined in the trait

    return response()->json([
        'success' => $deleted,
    ]);
}
```

---

Contributors
------------

[](#contributors)

[![Contributors](https://camo.githubusercontent.com/e5dde6633ba6090e6581298c10a199958805dc8770f13880642f56e6dd7a7148/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f73617965646e61776565642f73776179)](https://github.com/sayednaweed/sway/graphs/contributors)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance68

Regular maintenance activity

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~14 days

Total

9

Last Release

185d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bb97f84649ad2660a1cb4d46d46edeaed04d4b6d8f546f95691d7adb106cba94?d=identicon)[Sayed Naweed Sayedy](/maintainers/Sayed%20Naweed%20Sayedy)

---

Top Contributors

[![sayednaweed](https://avatars.githubusercontent.com/u/94922099?v=4)](https://github.com/sayednaweed "sayednaweed (8 commits)")

### Embed Badge

![Health badge](/badges/notion-swaycookie/health.svg)

```
[![Health](https://phpackages.com/badges/notion-swaycookie/health.svg)](https://phpackages.com/packages/notion-swaycookie)
```

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[laragear/two-factor

On-premises 2FA Authentication for out-of-the-box.

339785.3k8](/packages/laragear-two-factor)[alajusticia/laravel-logins

Session management in Laravel apps, user notifications on new access, support for multiple separate remember tokens, IP geolocation, User-Agent parser

2011.0k](/packages/alajusticia-laravel-logins)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
