Files
backend_pendaftaran/app/Http/Middleware/Authenticate.php
2024-12-27 16:50:09 +07:00

40 lines
1.1 KiB
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Auth\Middleware\Authorize;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
public function handle($request, Closure $next, ...$guards)
{
$jwt = $request->cookie('jwt');
if ($jwt) {
# code...
$request->headers->set('Authorization', 'Bearer ' . $jwt);
}
// $output = new \Symfony\Component\Console\Output\ConsoleOutput();
// $output->writeln($request->cookie('jwt'));
// $output->writeln('author : ' . $request->header('Authorization'));
// $output->writeln('cookie : ' . $request->header('cookie'));
$this->authenticate($request, $guards);
return $next($request);
}
}