Skip to content

kevin07696/email-auth

Repository files navigation

Email Authentication

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.

Tech

Stack: Golang, HTMX, Templ, TailwindCSS, MongoDB, Docker Architectural Patterns: Port and Adapters Model, Dependency Injection, Interface-Based Design

Features

Auth Service:

  • Login with Email Verification
  • Signup with Email Verification

Getting Started

Prerequisites

Configuration

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 to EMAIL_PASS, and your chosen email provider to EMAIL_HOST. Add whatever subdomain you want to use for your email auth service like 'email+auth@domain.com' to EMAIL_AUTH.
  • Ports are dynamically set in compose.yaml using .env, so you can change them directly in .env.

Usage

Checkout the Makefile for my shortcuts if you'd like.

  1. Build the app image and pull the images for redis, mongo, and mongo-express:
docker-compose build
  1. Create the containers using the images and the environment variables preset in .env
docker-compose up
  • To run in detach mode you can add --detach or -d for short:
docker-compose up -d
  1. You can run links from routes:
http://localhost:8080/login    

Contribution

Docs are coming soon.

Setup

Install Templ by running:

go install github.com/a-h/templ/cmd/templ@latest

Verify installation was successful by running:

templ version

Install TailwindCSS and other npm dependencies you can run:

npm install

To install TailwindCSS for your own project

Usage

To generate or regenerate templ files:

templ generate

For other commands checkout my Makefile.

Troubleshooting

  • If you run into the issue command not found when running templ you 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/bin directory 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

Running the tests

Currently there are only unit tests:

go test ./...

Integration tests and CI/CD are in the works.

Logging

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors