This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

TerjeN
TerjeN

This script worked for me before I updated to latest build, but now it just returns null, even though I am logged into backend. Anyone got a idea?:

public function checkUser() {

$user = BackendAuth::getUser();

    dd($user);

    if ($user) {
        return response()->json($user);
    } else { 
        return response()->json(array('error'=>'Not logged in'));
    }
}
TerjeN
TerjeN

Fixed it by adding ->middleware('web') on the api route:

Route::post('api/nameOfApi', [    
 'uses' => 'Brand\Plugin\Controller@checkUser'
])->middleware('web');

Must also be applied to eventual logout and login routes to work together.

Last updated

thiago33406
thiago33406

TerjeN said:

Fixed it by adding ->middleware('web') on the api route:

Route::post('api/nameOfApi', [
'uses' => 'Brand\Plugin\Controller@checkUser' ])->middleware('web');

Must also be applied to eventual logout and login routes to work together.

You are very helpful sir. thanks for the fix

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.