Skip to content

If Go is good enough for the cool kids at Google, it's good enough for me!

License

Notifications You must be signed in to change notification settings

CodePawfect/hexagonal-auth-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go mongodb

User Authentication With Go, MongoDB And JWT

Go Gopher

Why I Did This?

As a Java developer, I felt like I was stuck in a time machine. Then I heard about this hip new language called Go, and thought, "Hey, if it's good enough for the cool kids at Google, it's good enough for me!"

What We Have Here?

A simple backend server designed with hexagonal architecture to demonstrate how user authentication can be implemented.

We Can Find Here Stuff like:

User Registration

  • Allows new users to create an account and securely stores user data with hashed password in the MongoDB

User Login

  • Verifies provided credentials against stored information in the database and authenticates users

JWT Token for Logged-in Users

  • Generates a JSON Web Token (JWT) upon successful login
  • Contains encoded user information and possibly authorization details
  • Used for authenticating subsequent requests from the client

Hexagonal Architecture

img.png Why Hexagonal Architecture?

Getting started

The application registers new users in a MongoDB database.

MongoDB Inside Docker

We can conveniently start an MongoDB instance in a Docker container. The corresponding Docker Compose file is already located in the root directory.
You can execute the compose.yml with the following command:

docker compose up -d

Running the Go Application

After starting the MongoDB container, the Go application can be launched using the following terminal command:

go run cmd/main.go

Registering a New User

To register a new user, an HTTP POST request can be sent to the appropriate endpoint with a body containing the user credentials. Here's how you might do this:

curl -v -X POST http://localhost:8080/user/register \
-H "Content-Type: application/json" \
-d '{
  "username": "testuser",
  "password": "test123"
}'

Contributing

I welcome contributions from the community! Whether you're fixing bugs, improving documentation, or proposing new features, your efforts are appreciated.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

If Go is good enough for the cool kids at Google, it's good enough for me!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages