This is related to my previous question. The context is, I have created a NextJS app, which uses NextAuth with OneLogin for authentication and Mongo Atlas for database. Session is stored in db btw. And is hosted in Vercel.
The problem is, MongoDB connections exceeds the limit most of the times as Vercel considers each HTTP requests separately and thus caching of the connections is not possible. So am planning to separate the API part to a separate NodeJS+Express+MongoDB application, hosted separately. So the db communication will take place through this NodeJS API app that am gonna create, so that the connections could be cached. And the NextJS app hosted in Vercel won't directly communicate with the db.
Place where am stuck is, how would I take care of the authentication part. Since am using NextAuth at the moment for the NextJS app, and OneLogin is the provider that am using and sessions are stored directly in database, confused at implementing the authentication in my new NodeJS+Express API app.
Btw, I plan to code a mobile app(ReactNative) later too. So separating the authentication part to the API app seems to be the better option.