jwt-auth-in-golang

command module
v0.0.0-...-073e33b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 4 Imported by: 0

README

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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL