CatchTheTornado / doctor-dok

Doctor Dok is an AI based medical data framework. Parse any health related PDF/Image to JSON and then use Chat GPT / LLama to discuss it!
http://doctordok.com
MIT License
8 stars 2 forks source link

[feat] SaaS authorization + provisioning #74

Open pkarw opened 1 month ago

pkarw commented 1 month ago

Would be great to react on ENV variable specifying the SaaS provisioning API having three main features:

pkarw commented 2 weeks ago
  1. The current app will have an ENV setting: process.env.NEXT_PUBLIC_SAAS_MODE
  2. When this mode is enabled we get into SaaS mode with the support for quotas during registration and other ops.
  3. In SaaS mode the app is expecting a ?userToken= (generated by the SaaS management app, valid for 1-2 days just for registration) to be passed which contains the following user data OR application is requestin user's email which is then send to the server:

{ "userIdHash": "user unique identifier", "email": "email given during registration"} the data is stored in the dbContext.userToken

  1. The userIdHash or email is being sent on the db/create form to get the available quota to https://saas.doctordock.com/api/quota (URL is set via process.env.SAAS_MGMT_URLthe quota is returned for specificuserIdHash`:

{ "userIdHash": "unique user hash", "instancesAllowed": "1", "instancesUsed": "0", "tokensAllowed": "124000" }

then the request to api/quota is again sent during the db creation process to validate the quota server side.

  1. The db/create requests is sending the PUT https://saas.doctordock.com/api/sites request assiging the current - newly created databaseIdHash with the userIdHash - with the user account.

We might want to store the user data in the database manifest file (JSON) - at least userIdHash

Important: The subsequent requests are using databaseHashId instead of userIdHash

  1. The db/authorize after successfull authorization is always sending the api/quota request and returns it in the additional data record along with accessKey

  2. Application stores the quota in the dbContext.quota and uses it for ongoing request validation / approvals