Laravel JWT API authentication show 401 on production server

21 views Asked by At

I am using JWT for API authentication in LARAVEL 10. I have two user roles. Both works fine in my local environment. But after deploying in cenOS one works fine but another one not working. Shows 401 unauthorized.

route api.php

Route::group(['prefix'=>'client','middleware'=>['jwt.verify:client','jwt.auth']], function (){
    Route::post('verify-otp', [ClientAuthenticationController::class,'verifyOtp']);
    Route::post('logout', [ClientAuthenticationController::class,'logout']);
    Route::post('resend-otp', [ClientAuthenticationController::class,'resendOtp']);
    Route::get('me', [ClientAuthenticationController::class,'userInfo']);
});

Here logout route is working but me is not working.

Route::group(['prefix'=>'student','middleware'=>['jwt.verify:student','jwt.auth']], function (){
    Route::post('verify-otp', [StudentAuthController::class,'verifyOtp']);
    Route::post('logout', [StudentAuthController::class,'logout']);
    Route::post('resend-otp', [StudentAuthController::class,'resendOtp']);
    Route::get('me',function (){
        return response()->json(['foo'=>'student','user'=>auth()->user()]);
    });
});

Here me route is working as expected.

0

There are 0 answers