walkerpan

214 经验值

我也一直困惑在这里,最后转而去用jwt-auth解决了,凑巧可能你的问题是:axios.interceptors.request.use(function (config) { 这后面的jwt-token没有获取保存的access-token,,直接用window.localStorage.getItem('token');代替试下

执行代理后出现
{message: "Call to a member function post() on null",…}
exception:"Symfony\Component\Debug\Exception\FatalThrowableError"
file:"C:\laragon\www\api\app\Http\Proxy\TokenProxy.php"
line:34
message:"Call to a member function post() on null"
代码如下:
public function proxy($grantType,array $data=[])

{
    $data=array_merge($data,[
            'client_id'     =>env('PASSPORT_CLIENT_ID'),
            'client_secret' =>env('PASSPORT_CLIENT_SECRET'),
            'grant_type'    =>$grantType,
    ]);
    $response =$this->http->post('/oauth/token',[       // 这是提示的第 34行代码
       'form_params'    =>  $data
    ]);

    $token =json_encode((string) $response->getBody(),true);

    return $response()->js([
        'token'      => $token['access_token'],
        'expires_in' => $token['expires_in']
    ])->cookie('refreshToken',$token['refreshToken'],1296000,null,null,false,true);

}