Storing logged-in customer ID


First off, thanks so much for making Slim! I love it!

I’m currently investigating the feasibility of using Slim as a replacement enterprise solution for my company. I have a middleware layer dedicated to authentication and I want to know where there best place to store the logged-in customer ID is. I’ve narrowed it down to two solutions, but am open to other options:

  1. Store it as an attribute on the request object
  2. Store it in the metadata of the request body

Which solution is more correct and congruent with the roles of the various objects? For context, the reason we need the customer ID is for route-specific authorization middleware. Each route has unique privileges based on the customer ID, but all of them need the customer ID, hence authentication is application-level middleware layer.


I set it as an atrribute on the request object in my middleware like this:

$request = $request->withAttribute('userId', $userId);

As @tflight says, attribute is the way to approach this.

1 Like

Great, thanks so much!