jonnybarnes.uk/app/Http/Middleware/MyAuthMiddleware.php
Jonny Barnes 5d8929ac29
Save full url during login
This means the query params should be kept when redirecting back to
`/auth?...` during the IndieAuth flow.
2024-06-22 20:28:18 +01:00

30 lines
662 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
class MyAuthMiddleware
{
/**
* Check the user is logged in.
*
* @psalm-suppress PossiblyUnusedMethod
*/
public function handle(Request $request, Closure $next): Response
{
if (Auth::check() === false) {
// theyre not logged in, so send them to login form
redirect()->setIntendedUrl($request->fullUrl());
return redirect()->route('login');
}
return $next($request);
}
}