我正在尝试为我们现有的 laravel 站点(laravel 5.2)的注销功能添加一些逻辑,但它不像登录那样简单。
客户端的现有注销工作正常,但我想要做的就是向我的 Cognito 实例添加一个调用,以将用户从他们的 Cognito 会话中注销。基本上,当用户单击注销时,我想将他们从网站上注销,因为它已经这样做了,但也点击了我的注销端点以进行 cognito
我的困惑来自这样一个事实,即用于身份验证的现有路由和控制器并不完全匹配。
路由.api.php
Route::get('logout', 'API\Auth\AuthController@getLogout');
Run Code Online (Sandbox Code Playgroud)
路由.auth.php
Route::get('logout', 'Auth\AuthController@getLogout')
->name('auth.logout');
Run Code Online (Sandbox Code Playgroud)
Auth/AuthController.php(在我的构造函数中)
$this->middleware('guest', ['except' => 'getLogout']);
Run Code Online (Sandbox Code Playgroud)
我的注销链接命中site/logout,它肯定会注销用户,但我想将我的呼叫放在正确的位置。我还想确保在成功注销时刷新或销毁会话
最近有人告诉我,我可能(并且可能应该)为注销事件添加一个侦听器并在那里打电话。
在这种情况下,我究竟会怎么做,它到底会去哪里?
在你EventServiceProvider可以附加一个侦听注销事件,以及如何在你的听众全部注销逻辑。
protected $listen = [
'Illuminate\Auth\Events\Logout' => [
'App\Listeners\LogSuccessfulLogout',
],
];
Run Code Online (Sandbox Code Playgroud)
然后你可以在里面创建你的 LogSuccessfulLogout 监听器App\Listeners:
namespace App\Listeners;
use Illuminate\Auth\Events\Logout;
class LogSuccessfulLogout
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param Logout $event
* @return void
*/
public function handle(Logout $event)
{
// Do your logic
}
}
Run Code Online (Sandbox Code Playgroud)
来源:https : //laravel.com/docs/5.2/authentication#events
| 归档时间: |
|
| 查看次数: |
2045 次 |
| 最近记录: |