1275e38c19dbd000c5b949f7c979a8616a55997b
Authentication
Authentication consists of the following parts:
next-authboilerplatemiddleware.ts= hooks-upnext-authinto the page processing pipeline - user session is checked before any page is renderedauth.ts= defines how the authentication is done, and how session is checked (used by middleware)/app/api/[...nextauth]/route.ts= defines route which shows an authentication form
Source:
- How to Implement Google Authentication in a Next.js App Using NextAuth
- Next Js 14 Authentication on Edge Runtime
Multi-User Support
Each location record is marked with a user ID.
All the actions user withUser to fetch user ID, which is then used in all the DB operations.
Deploying
The deployment is done via Docker:
- build docker image
- deploy Docker service
Building Docker image
Run the following command:
docker build . -t utility-bills-tracker:1.0.0
The image will be stored in the local Docker instance.
Deploying Docker service
Run the following command:
docker stack deploy \
-c docker-compose-deploy.yml \
utility-bills-tracker
Implementation details
Issues with HOSTNAME
When deplyed via docker and published via Cloudflare there's an issue with HOSTNAME env variable:
- if left unset, the server will use IP address assigned to container by Docker and will not accept connections from outside
- if set to "0.0.0.0" the server will serve static pages, but will reject API calls when submitting form
- if set to "rezije.app" the server will not start since the IP address it resolves with the given FQDN does not match any of the IP addresses assigned to the container
So there are the following issues:
- server will not accept external request - can be fixed by setting
HOSTNAMEto0.0.0.0 - server rejects API requests - can be fixed by adding
serverActions.allowedOriginsoption tonextjs.config.jsfile
So these are the fixes which were implemented in order to be able to run server in production.
Description
Languages
JavaScript
74.7%
TypeScript
24.3%
Shell
0.9%