Pretend there's a unique user and pass a User argument to each server-side function
Before migrating to SQL, I'd like use to pave the way for multiple users management. The SQL tables will all contain a userId
, and each model function on the backend will make sure to provide the userId, to filter by user.
To prepare for this, and instead of doing it in the same commit/MR as the SQL migration (as I've started before, sigh, which was a terrible idea), I think we can do it ahead of time. It will also make it easier to spot issues.
My intent is to add, when setting up the server, a (temporary until it's real) middleware that mocks the Passport API: it will just add a user
object to the current request, with an id
key. The id will be 0 for the (existing) user, and we'll use an internal SQL database index when we have one.
Then, each function on the backend can retrieve the userId from req.user.id
, and pass it to the model it calls.
As for the renaming issue, I think there's a nice way to do it in small bundles of functions on the server, to split it into several commits and several MRs. Help would be gladly appreciated here :)