I have a rest api which has organisations as a top level object and all other data belongs to an organisation e.g. orders, invoices, projects etc..
Users have the ability to belong to multiple organisations and on my frond end SPA I want them to be logged into one application at a time with the ability to switch.
Should I be storing the current organisation id on the client side and passing it with every request or should i have a rest endpoint that sets the current org id on the user table etc, which will also mean when they come back and login it is already set to the last organisation they accessed.
Yes, a general practice is sending the information in each API because API are stateless.
NO you should not, one of the reason is let say user logs in browser1 you will store that organizationId in table, same user login from browser2 this will override your previous Id
Now if you go back to browser1 it will have inconsistent data unless you had designed a mechanism not to override the previous value.
Hope that make sense