PHPackages                             arjunyuvanesh/common-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. arjunyuvanesh/common-auth

ActiveLibrary

arjunyuvanesh/common-auth
=========================

v1.0.1(1mo ago)02MITPHP

Since Jul 14Pushed 1mo agoCompare

[ Source](https://github.com/arjunyuvanesh/common-auth)[ Packagist](https://packagist.org/packages/arjunyuvanesh/common-auth)[ RSS](/packages/arjunyuvanesh-common-auth/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Common Auth Package for Laravel
===============================

[](#common-auth-package-for-laravel)

A highly professional, dynamic, and enterprise-grade Laravel Authentication package. Built specifically to support **Email, Mobile, or Username** logins seamlessly, integrated deeply with `spatie/laravel-permission`, Dual Email Verification, and Dynamic Rate Limiting.

Features
--------

[](#features)

- **Headless Design**: Provides 100% of the backend logic. You build the UI in React, Vue, Blade, or Mobile SDKs.
- **Dynamic Login**: Users log in using Email, Mobile, or Username via a single input field.
- **Dual Architecture**: Native support for both Web Browsers (Session/CSRF) and Mobile Apps (Sanctum Tokens).
- **Dual Email Verification**: Supports both Magic Links and stateless 6-digit OTPs (stored efficiently in Cache).
- **Account Management**: Endpoints for updating profiles, changing passwords securely, and account deletion.
- **Enterprise Security**: Mathematically strict password enforcement and dynamic Brute-Force Rate Limiting.

---

Installation &amp; Setup
------------------------

[](#installation--setup)

1. **Install the package:**

```
composer require arjunyuvanesh/common-auth
```

2. **Publish config and migrations:**

```
php artisan common-auth:install
```

3. **Run migrations:**

```
php artisan migrate
```

4. **Update your User Model (`app/Models/User.php`):**Add the `HasCommonAuth` trait to inject the package engine into your app.

```
namespace App\Models;

use Arjunyuvanesh\CommonAuth\Traits\HasCommonAuth;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasCommonAuth; // Add this line!

    // Add any custom fields you want users to submit during registration
    protected $fillable = [
        'name', 'email', 'password', 'username', 'mobile', 'address'
    ];
}
```

---

How to Connect Your Frontend
----------------------------

[](#how-to-connect-your-frontend)

This package exposes two identical sets of endpoints.

- Use the `/common-auth/*` endpoints for **Web Browsers** (Blade, React/Vue SPAs using Sanctum stateful domains).
- Use the `/api/common-auth/*` endpoints for **Mobile Apps** (iOS/Android/Flutter using Bearer Tokens).

### Scenario 1: Connecting a Web Browser (React / Vue / Blade)

[](#scenario-1-connecting-a-web-browser-react--vue--blade)

Web browsers rely on Cookies and CSRF tokens.

1. **Submit the Login Request:**Your frontend should make an AJAX request to `/common-auth/login`.

```
// Example using Axios
axios.post('/common-auth/login', {
    login: 'arjun15247@gmail.com', // Can be email, mobile, or username
    password: 'SuperSecretPassword123!',
    remember: true
}).then(response => {
    console.log(response.data.message); // "Successfully logged in."
    console.log(response.data.user);    // The user's profile
});
```

2. **Accessing Authenticated Routes:**Because Web Browsers use cookies, once you log in, your browser automatically saves the session. You can immediately call `/common-auth/me` without passing any tokens!

### Scenario 2: Connecting a Mobile App (React Native / Flutter / Swift)

[](#scenario-2-connecting-a-mobile-app-react-native--flutter--swift)

Mobile apps cannot use cookies or CSRF tokens. They must use the `/api` prefix.

1. **Submit the Login Request:**Make a JSON request to `/api/common-auth/login`.

```
fetch('https://yourwebsite.com/api/common-auth/login', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
    body: JSON.stringify({
        login: 'arjun15247@gmail.com',
        password: 'SuperSecretPassword123!'
    })
})
.then(res => res.json())
.then(data => {
    // SAVE THIS TOKEN IN YOUR MOBILE APP (e.g. AsyncStorage or SecureStorage)
    const token = data.token;
});
```

2. **Accessing Authenticated API Routes:**To get the user's profile or change their password, you must pass the token in the `Authorization` header.

```
fetch('https://yourwebsite.com/api/common-auth/me', {
    method: 'GET',
    headers: {
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + token // Pass the token here!
    }
});
```

---

Complete API Reference
----------------------

[](#complete-api-reference)

### Guest Endpoints

[](#guest-endpoints)

*Available under both `/common-auth/` and `/api/common-auth/`*

- `POST /login` - Accepts `login` (email/mobile/username) and `password`. Returns a Token if called via `/api`.
- `POST /register` - Accepts your dynamically configured registration fields (see `config/common-auth.php`).
- `POST /forgot-password` - Sends a password reset link (requires `email`).
- `POST /reset-password` - Resets the password (requires `token`, `email`, `password`, `password_confirmation`).

### Authenticated Endpoints

[](#authenticated-endpoints)

*Web uses Cookies. APIs require `Authorization: Bearer `*

- `GET /me` - Returns the current user's profile.
- `POST /logout` - Logs the user out and securely revokes API tokens.
- `PUT /profile` - Updates the user profile. Accepts `name`, `email`, `mobile`, `username`.
- `PUT /password` - Securely changes the password. Accepts `current_password`, `password`, `password_confirmation`.
- `DELETE /account` - Permanently deletes the user and revokes all tokens.

### Verification Endpoints

[](#verification-endpoints)

- `GET /email/verify/{id}/{hash}` - Magic Link verification endpoint.
- `POST /email/verify-otp` - Submits the 6-digit OTP. Accepts `otp`.
- `POST /email/verification-notification` - Resends the OTP/Link to the user's email.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance90

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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 ~0 days

Total

2

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2acc3ffb358e15596bb3668a70f07ed88507e57ab6a723b5cc7917bb0ce46c26?d=identicon)[arjunyuvanesh](/maintainers/arjunyuvanesh)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/arjunyuvanesh-common-auth/health.svg)

```
[![Health](https://phpackages.com/badges/arjunyuvanesh-common-auth/health.svg)](https://phpackages.com/packages/arjunyuvanesh-common-auth)
```

###  Alternatives

[typicms/base

A modular multilingual CMS built with Laravel, enabling developers to manage structured content like pages, news, events, and more.

1.6k20.4k](/packages/typicms-base)[althinect/filament-spatie-roles-permissions

3531.2M12](/packages/althinect-filament-spatie-roles-permissions)[nasirkhan/laravel-starter

A CMS like modular Laravel starter project.

1.4k2.7k](/packages/nasirkhan-laravel-starter)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1346.4k29](/packages/fleetbase-core-api)

PHPackages © 2026

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