Start Coding with Codelab | Jaeves AI

Laravel return json not authentication – Jaeves Codelab

Written by Admin | Oct 2, 2023 7:58:56 PM

Laravel return json not authentication

Open app\Http\Middleware\Authenticate.php

protected function redirectTo($request)
{
    if( $request->is('api/*')){
        abort(response()->json(['status' => 401, 'message' => 'Unauthorized'], 401));
    }

    if (! $request->expectsJson()) {
        return route('login');
    }else{
        abort(response()->json(['status' => 401, 'message' => 'Unauthorized'], 401));
    }
}

click for more Laravel codes read about laravel authentication