Skip to content

This project demonstrates how to implement JWT (JSON Web Token) authentication in a Golang web application using Gin framework.

License

Notifications You must be signed in to change notification settings

CABON-TECH/jwt-auth-in-golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JWT Authentication in Golang

This project demonstrates how to implement JWT (JSON Web Token) authentication in a Golang web application using Gin framework.

Features

  • User signup: Users can register by providing a username, email, and password.
  • User login: Registered users can log in using their email and password.
  • JWT Authentication: JWT is used to generate and authenticate user tokens for secure access to protected routes.

Prerequisites

  • Go (v1.16 or later)
  • PostgreSQL (v9.5 or later)

Getting Started

  1. Clone the repository:

    git clone https://github.com/CABON-TECH/jwt-auth-in-golang.git
  2. Navigate to the project directory:

    cd jwt-auth-in-golang
  3. Install dependencies:

    go mod tidy
  4. Set up the PostgreSQL database:

    • Create a PostgreSQL database named jwt_db.
    • Update the database connection details in initializers/connectDB.go file.
  5. Set environment variables:

    Create a .env file in the root directory and define the following environment variables:

    SECRET=your-secret-key
    
  6. Run the application:

    go run main.go
  7. Access the application in your web browser at http://localhost:8080.

API Endpoints

User Signup

  • URL: /signup

  • Method: POST

  • Body:

    {
        "username": "Cabon TEch",
        "email": "cabontech@gmail.com",
        "password": "cabon123"
    }

User Login

  • URL: /login

  • Method: POST

  • Body:

    {
        "email": "cabontech@gmail.com",
        "password": "cabon123"
    }

License

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

About

This project demonstrates how to implement JWT (JSON Web Token) authentication in a Golang web application using Gin framework.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages