descom/laravel-auth-spa
Composer 安装命令:
composer require descom/laravel-auth-spa
包简介
Template to generate a Laravel Package
README 文档
README
This package is an authentication backend implementation for Laravel. Registers the routes and controllers required to implement all Laravel authentication features from a Frontend SPA or SSR, including login, password reset, and more.
Installation
composer require descom/laravel-auth-spa
Configure
Laravel Sanctum
Run:
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
php artisan migrate
Add Sanctum's middleware to your api middleware group within your application's app/Http/Kernel.php file:
'api' => [ \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, 'throttle:api', \Illuminate\Routing\Middleware\SubstituteBindings::class, ],
Configure cors, you need edit the file config/cors.php and change this lines:
'paths' => ['api/*', 'sanctum/csrf-cookie', 'login', 'logout', 'password/forget', 'password/reset'], /// ... 'supports_credentials' => true,
In production define this environment variables:
Local:
SANCTUM_STATEFUL_DOMAINS=localhost:3000 SESSION_DOMAIN=localhost
Production for domain 'www.app.tld':
SANCTUM_STATEFUL_DOMAINS=www.app.tld SESSION_DOMAIN=.app.tld
Package
php artisan vendor:publish --provider="Descom\AuthSpa\AuthSpaServiceProvider" --tag="config"
You can define your frontend in config file config/authspa.php
/// 'frontend' => [ 'url' => env('FRONTEND_URL', 'http://localhost:3000'), 'reset_password_url' => env('FRONTEND_RESET_PASSWORD_URL', '/login/reset'), ], ///
Usage
Login
POST /login { "email": " <email>", "password": "<password>" }
Logout
POST /logout
Get reset password link
POST /password/forgot { "email": " <email>" }
Reset password with link
POST /password/reset { "token": "<token>", "email": " <email>", "password": "<password>", "password_confirmation": "<password>" }
Update password for current user logged
PUT /api/user/password { "current_password": "<current_password>", "password": "<newpassword>", "password_confirmation": "<newpassword>" }
Get user info
GET /api/user
Nuxt.js
Install Nuxt Auth:
yarn add --exact @nuxtjs/auth-next yarn add @nuxtjs/axios
And configure file nuxt.config.js:
{ modules: [ '@nuxtjs/axios', '@nuxtjs/auth-next' ], auth: { strategies: { laravelSanctum: { provider: 'laravel/sanctum', url: process.env.API_URL || 'http://localhost:8000', }, }, } }
Customize
Defining Default Password Rules
You may find it convenient to specify the default validation rules for passwords in a single location of your application. You can easily accomplish this using the Password::defaults method, which accepts a closure. The closure given to the defaults method should return the default configuration of the Password rule. Typically, the defaults rule should be called within the boot method of one of your application's service providers:
use Illuminate\Validation\Rules\Password; /** * Bootstrap any application services. * * @return void */ public function boot() { Password::defaults(function () { $rule = Password::min(8); return $this->app->isProduction() ? $rule->mixedCase()->uncompromised() : $rule; }); }
More info
descom/laravel-auth-spa 适用场景与选型建议
descom/laravel-auth-spa 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.08k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 06 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 descom/laravel-auth-spa 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 descom/laravel-auth-spa 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.08k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-15