0

我在我的单页 vue 应用程序中使用 laravel fortify。当我向我发送 XHR 请求时,sitePath + '/login'我得到{two_factor: false}响应并且用户已登录。如何添加用户信息以便将数据保存在本地存储中。

let response = await this.$root.requestPost(data, url);
async requestPost(data, requestUrl) {
    const response = await axios.post(requestUrl, {
        // ...data
    }).catch(error => {
        //
    });
    return response;
},
4

1 回答 1

1

对不起,迟到的答案。

但是今天我解决了同样的问题。

在 FortifyServiceProvider 的 register() 方法中,你需要实现自己的 LoginResponse:

$this->app->instance(LoginResponse::class, new class implements LoginResponse {
        public function toResponse($request)
        {
            /**
             * @var User $user
             */
            $user = $request->user();
            return $request->wantsJson()
                ? response()->json(['two_factor' => false, 'email' => $user->email ])
                : redirect()->intended(Fortify::redirects('login'));
        }
    });

文档 - https://laravel.com/docs/8.x/fortify#customizing-authentication-redirects

于 2021-09-29T17:42:48.240 回答