Redirect unauthorized routes

PHOTO EMBED

Sun May 07 2023 18:04:06 GMT+0000 (Coordinated Universal Time)

Saved by @eneki #php

<?php

namespace App\Http\Middleware;

use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Http\Request;

class Authenticate extends Middleware
{
    /**
     * Get the path the user should be redirected to when they are not authenticated.
     */
    protected function redirectTo(Request $request): ?string
    {
        return $request->expectsJson() ? null : route('login');
    }

    protected function unauthenticated($request, array $guards)
    {
        abort(response()->json(
            [
                'status' => 'false',
                'message' => 'Unauthenticated',
            ], 401));
    }
}
content_copyCOPY

https://stackoverflow.com/questions/61450239/laravel-passport-to-return-403-error-instead-of-routelogin