问题描述
我使用 Laravel Fortify 进行注册和电子邮件验证;我也在使用登录,但我需要在用户通过身份验证然后重定向后立即设置一些新的会话变量。
为了使用登录 POST 路由并更改登录获取路由的名称,我将我的 fortifyRoutes 包含在我的路由 Web 文件中:
web.PHP
require_once __DIR__ . '/fortifyRoutes.PHP';
fortifyRoutes.PHP
if ($enableViews) {
Route::get('/signin',[AuthenticatedSessionController::class,'create'])
->middleware(['guest'])
->name('signin');
}
$limiter = config('fortify.limiters.login');
$twoFactorLimiter = config('fortify.limiters.two-factor');
Route::post('/login',[AuthController::class,'authenticate'])
->middleware(array_filter([
'guest',$limiter ? 'throttle:'.$limiter : null,]));
AuthController.PHP
class AuthController extends Controller
{
public function authenticate(Request $request)
{
$credentials = $request->only('email','password');
if (Auth::attempt($credentials)) {
return "Ok";
}
else{
return back()->withErrors([
'email' => 'The provided credentials do not match our records.',]);
}
}
}
我应该如何在我的身份验证功能中手动对我的用户进行身份验证?现在我只是希望从我的 Axios 请求中得到一个 Ok 作为响应。
刀片视图
<script type="text/javascript">
function procesaFormulario(){
axios.post('/login',{
email: document.getElementById('email').value,password: document.getElementById('password').value,})
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error.response.data);
});
};
</script>
提前谢谢各位...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)