https://github.com/fadhil-riyanto/noauth-laravel
Static auth library without database for Laravel 11.x, good for single user App
https://github.com/fadhil-riyanto/noauth-laravel
auth authentication laravel without-db
Last synced: over 1 year ago
JSON representation
Static auth library without database for Laravel 11.x, good for single user App
- Host: GitHub
- URL: https://github.com/fadhil-riyanto/noauth-laravel
- Owner: fadhil-riyanto
- License: gpl-2.0
- Created: 2025-01-22T04:06:40.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-21T06:42:42.000Z (over 1 year ago)
- Last Synced: 2025-02-21T07:29:16.776Z (over 1 year ago)
- Topics: auth, authentication, laravel, without-db
- Language: PHP
- Homepage: https://packagist.org/packages/fadhil_riyanto/noauth-laravel
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
## NoAuth Laravel
is a non-database authentication that keeps authentication as small as possible. good for single-user APP
## Setup
create your password list inside .env with comma-separated string
```env
NOAUTH_PASSWORD="abc123,foobar123,otherxyz"
```
first, use the namespace
```php
use FadhilRiyanto\NoAuthLaravel\NoAuth;
```
defining routes for guest which try access route with `NoAuthMiddleware` class, the route must be named as 'noauth-guest', example
```php
// guest will redireced here
Route::get('login', function() {
return view('admin/login');
})->name("noauth-guest");
```
define admin route with middleware, example
```php
// protect admin page using middleware NoAuthMiddleware
Route::get('home', [Controllers\AdminController::class, 'handle_admin_homepage'])
->middleware(NoAuthMiddleware::class);
```
authentication example, `NoAuth::attemp` is automatically create a session if successful and return false otherwise
```php
class AdminController extends Controller
{
public function handle_admin_login_ajax(Request $request)
{
$validator = Validator::make($request->all(), [
'password' => 'required',
]);
$validated = $validator->validated();
if (NoAuth::attemp($request)) {
return response()->json(["message" => "Welcome"], 200);
} else {
return response()->json(["message" => "The provided credentials do not match our records"], 400);
}
}
}
```
### Maintainer:
[Fadhil-Riyanto](https://github.com/fadhil-riyanto)
## License
GPL-2.0