Skip to content

Commit

Permalink
[2.x] Return json response when the request expects a json (#247)
Browse files Browse the repository at this point in the history
* Return json response when the request expects a json

* Update CsrfCookieController.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
nmfzone and taylorotwell authored Jan 25, 2021
1 parent f5695ae commit fecc7ef
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Http/Controllers/CsrfCookieController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

namespace Laravel\Sanctum\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class CsrfCookieController
{
/**
* Return an empty response simply to trigger the storage of the CSRF cookie in the browser.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function show()
public function show(Request $request)
{
if ($request->expectsJson()) {
return new JsonResponse(null, 204);
}

return new Response('', 204);
}
}

0 comments on commit fecc7ef

Please sign in to comment.