loading...

Discussion on: PKCE authenticaton for Nuxt SPA with Laravel as backend

Collapse
thorbn profile image
Thor

Hi again,

Question about logout:

I can do this in the frontend: this.$auth.logout();

But how to logout the laravel backend?

I have tried:

Nuxt:
logout() {
this.$axios.$post(process.env.LARAVEL_ENDPOINT+'/api/logout')
.then(response => {.....

Laravel backend:

API.php *******************

Route::middleware('auth:api')->group(function () {
Route::post('logout', 'Auth\AuthWepAppController@logoutApi')->name('logout');
});

AuthWepAppController *******************

public function logoutApi (Request $request) {

    $token = $request->user()->token();
    $token->revoke();

    $response = 'You have been succesfully logged out!';
    return response($response, 200);
    }

It gives me this error:
message": "Call to undefined method Illuminate\Support\Facades\Request::user()",

What am I missing? thanks