Support the ongoing development of Laravel.io →
Authentication Laravel Requests

Hi friends,

I try laravel API authendicate token so i add a middleware method and check api verification to make request . It correctly working in localhost but

My issue: It not properly work in live server.

show 'Unauthorized' in live server api response

i also checked manually code in server (local and server is same code)

My code

Middleware Method

	public function handle($request, Closure $next)

	{

	if ($request->header('APP_KEY') == env('APP_KEY'))

	return $next($request);

	else

	return response()->json('Unauthorized', 401);

	}
	
	API Route
	
	Route::get('/showfaq','faq\faqController@getfaqList')->middleware('API_verification');
	
	Frontend API Call
	
	
	$http({
    url:'./api/faq/showfaq',
    method: 'get',
    headers: {'APP_KEY': 'XXXXX'},
 }).then(function (response){
     $scope.faq = response.data;
			 },function(error){
      consloe.log("soming wrog")
   });
Last updated 3 years ago.
0

Make sure that in your config/auth you have this:

'guards' => [
		'web' => [
				'driver' => 'session',
				'provider' => 'users',
		],

		'api' => [
				'driver' => 'passport',
				'provider' => 'users',
		],
],
	
	
	Then your API routes should be protected like this:
	
Route::group(['prefix' => 'v1', 'middleware' => ['auth:api'], function () {

});
	
	Now from here:
	[https://laravel.com/docs/5.8/authentication](http://)
	
Path Customization

When a user is successfully authenticated, they will be redirected to the /home URI. You can customize the post-authentication redirect location by defining a redirectTo property on the LoginController, RegisterController, ResetPasswordController, and VerificationController:

protected $redirectTo = '/'; Next, you should modify the RedirectIfAuthenticated middleware's handle method to use your new URI when redirecting the user.

If the redirect path needs custom generation logic you may define a redirectTo method instead of a redirectTo property:

protected function redirectTo() { return '/path'; }

Hope this helps,

Ben

0

Visit Icetutor.com For Your Solution

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.