Initializing Square Client (node) in NextJS / SSR Application

I am building an online takeout ordering system for my client that will integrate with their Square POS via the Square Orders/Customers/Payment/Loyalty APIs, using NextJS front end and either Firebase or AWS Cognito for backend auth, to allow customers to re-order previous items from order history and maintain their loyalty points.

My question is where to initialize the Square Client in a NextJS application? in the /API routes, in getServerSideProps, or init in a separate util file that is imported into getServerSideProps?

Thank you for any advice!

You can configure the API client in Square SDKs to use the targeted environment when you initialize the client in your configured .env. You can import using the ES module or CommonJS module syntax. :slightly_smiling_face:

1 Like

Thank you! Got it working great now.