This is a project to logs in the user by email and provide a session token in a http-cookie. This api uses the HATEOAS (Hypermedia as the Engine of Application State) model and GOTH stack to render a login web page.
Stack: Golang, HTMX, Templ, TailwindCSS, MongoDB, Docker Architectural Patterns: Port and Adapters Model, Dependency Injection, Interface-Based Design
Auth Service:
- Login with Email Verification
- Signup with Email Verification
- Golang
- Node.js on Linux & Mac | Windows
- Docker Compose
In the .env file, you can find the global environmental variables I use.
- To configure your email server add your email address to
EMAIL_USER, email password toEMAIL_PASS, and your chosen email provider toEMAIL_HOST. Add whatever subdomain you want to use for your email auth service like 'email+auth@domain.com' toEMAIL_AUTH. - Ports are dynamically set in
compose.yamlusing.env, so you can change them directly in.env.
Checkout the Makefile for my shortcuts if you'd like.
- Build the app image and pull the images for redis, mongo, and mongo-express:
docker-compose build- Create the containers using the images and the environment variables preset in
.env
docker-compose up- To run in detach mode you can add
--detachor-dfor short:
docker-compose up -d- You can run links from routes:
http://localhost:8080/login Docs are coming soon.
Install Templ by running:
go install github.com/a-h/templ/cmd/templ@latestVerify installation was successful by running:
templ versionInstall TailwindCSS and other npm dependencies you can run:
npm installTo install TailwindCSS for your own project ☍
To generate or regenerate templ files:
templ generateFor other commands checkout my Makefile.
-
If you run into the issue
command not foundwhen runningtemplyou need to find the path of the go package. If you use Linux, try running:which templ
If that doesn't work look for it in your home directory. Mine was at:
/home/<username>/go/bin
Once you find the dir, you can add it to your PATH by running:
export PATH=$PATH:/path/to/your/go/bin
The
go/bindirectory is where Go installs command-line tools and executables when you use the go install command. By adding this directory to your PATH, you can run these tools directly from the command line without specifying their full path.Verify installation was successful by running:
templ version
Currently there are only unit tests:
go test ./...Integration tests and CI/CD are in the works.
Currently logging uses structured json logs with a request id. My next steps are to store the logs in a directory and export it to a log server for analysis.