fix api auth problem

This commit is contained in:
Nabeel Shahzad 2018-01-02 14:37:52 -06:00
parent 7700bd6683
commit 6d2f705b40
4 changed files with 9 additions and 5 deletions

View File

@ -2,9 +2,9 @@
namespace App\Http\Controllers\Api;
use Auth;
use Log;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Acars;
use App\Models\Pirep;

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\Api;
use Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
@ -30,7 +31,7 @@ class UserController extends AppBaseController
public function index(Request $request)
{
UserResource::withoutWrapping();
return new UserResource($request->user);
return new UserResource(Auth::user());
}
/**

View File

@ -38,7 +38,7 @@ class ApiAuth
// Set the user to the request
Auth::setUser($user);
//$request->merge(['user' => $user]);
$request->merge(['user' => $user]);
$request->setUserResolver(function () use ($user) {
return $user;
});

View File

@ -124,10 +124,13 @@ class AcarsTest extends TestCase
{
$uri = '/api/pireps/prefile';
$user = factory(App\Models\User::class)->create();
$pirep = factory(App\Models\Pirep::class)->make(['id' => ''])->toArray();
$pirep = factory(App\Models\Pirep::class)->make([
'id' => '',
'user_id' => $user->id,
])->toArray();
$response = $this->withHeaders($this->apiHeaders())->post($uri, $pirep);
// $response = $this->withHeaders($this->headers($user->api_key))->post($uri, $pirep);
#$response = $this->withHeaders($this->headers($user->api_key))->post($uri, $pirep);
$response->assertStatus(201);
$pirep = $response->json();