add notifications logic and add support of both JWT and Sanctum

This commit is contained in:
root
2026-03-11 01:20:31 -04:00
parent f6be51576c
commit 182036cc41
141 changed files with 8685 additions and 648 deletions
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use PHPOpenSourceSaver\JWTAuth\Exceptions\JWTException;
use PHPOpenSourceSaver\JWTAuth\Facades\JWTAuth;
use Symfony\Component\HttpFoundation\Response;
class MultiAuth
{
public function handle(Request $request, Closure $next): Response
{
$sanctumUser = Auth::guard('sanctum')->user();
if ($sanctumUser) {
Auth::setUser($sanctumUser);
return $next($request);
}
$token = $request->bearerToken();
if ($token) {
try {
$jwtUser = JWTAuth::setToken($token)->authenticate();
if ($jwtUser) {
Auth::setUser($jwtUser);
return $next($request);
}
} catch (JWTException $e) {
// fall through to unauthorized response
}
}
return response()->json(['message' => 'Unauthorized.'], 401);
}
}