Alternate to Session Storage in Laravel Token Based API

  laravel, php, session-state

I’m building an Electron app that connects to a Laravel 8 App (with Jetstream using Inertia) and the API.

I’m porting over the existing Inertia Jetstream Vue components to replicate the same functionality that appears in the actual web app.

When using the password confirm functionality Laravel uses session storage to store the time the password was confirmed, and then later again to check the status of the confirmed password.

When using token authentication, there is no session.

I can create new controllers to handle this no problem, but how can I substitute the calls to $request->session()?

The code to store the password confirmation looks like this:

public function store(Request $request)
{
    $confirmed = app(ConfirmPassword::class)(
        $this->guard, $request->user(), $request->input('password')
    );

    if ($confirmed) {
       // here is the problem ... no session with tokens 
       $request->session()->put('auth.password_confirmed_at', time());
    }

    return $confirmed
                ? app(PasswordConfirmedResponse::class)
                : app(FailedPasswordConfirmationResponse::class);
}

What’s the best way to store this so it can be retrieved on subsequent calls?

Source: Laravel

Leave a Reply