Skip to content

yusuftalhaklc/go-fiber-authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Fiber Authentication API

Go Fiber Authentication API is a RESTful API built using the Fiber web framework.

Installation

First you have to set the .env file

The .env file must be in the main folder

DB_URI="your-mongodb-atlas-uri"
DB_NAME="database-name"
DB_COLLECTION="collection-name"
SECRET_KEY="your-256-bit-secret"
COOKIE_ENC_KEY="secret-thirty-2-character-string"
  1. Clone the repository:
git clone https://github.com/yusuftalhaklc/go-fiber-authentication.git
  1. Navigate to the project directory:
cd go-fiber-authentication
  1. Install the dependencies:
go mod tidy
  1. Start the API server:
go run main.go

It is currently running on localhost port 8080. Postman Collection

API Endpoints

Signup

  • Endpoint: /api/signup
  • Method: POST
  • Description: Signup.

Login

  • Endpoint: /api/user/login
  • Method: POST
  • Description: Login.

Logout

  • Endpoint: /api/user/logout
  • Method: POST
  • Description: Logout.

Get User

  • Endpoint: /api/user/
  • Method: GET
  • Description: Get user details.

Delete User (Admin Only)

  • Endpoint: /api/user/delete/:email
  • Method: DELETE
  • Description: Deletes user.

Request Body and Response Examples

Signup

  • Request Body
{
    "first_name":"User First Name",
    "last_name":"User Last Name",
    "password":"password",
    "email":"[email protected]",
    "phone":"5555555555",
    "user_role": {
        "role_desc":"admin",
        "role_id": 4001
    }
}
  • Response
{
    "data": {
        "ID": "64a55bbe2d689534b97fccef",
        "user_id": "64a55bbe2d689534b97fccef",
        "first_name": "User First Name",
        "last_name": "User Last Name",
        "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8",
        "email": "[email protected]",
        "phone": "5555555555",
        "user_role": {
            "role_desc": "admin",
            "role_id": 4001
        },
        "avatar": null,
        "created_at": "2023-07-05T15:02:06+03:00",
        "last_login_at": "0001-01-01T00:00:00Z",
        "logout_at": "0001-01-01T00:00:00Z",
        "deleted_at": "0001-01-01T00:00:00Z"
    },
    "message": "User has created",
    "status": "success"
}

Login

  • Request
{
    "email": "[email protected]",
    "password": "password"
}
  • Response
{
    "data": {
        "email": "[email protected]",
        "token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2ODc5ODIwOTEsImlkIjoiMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIiwibWFpbCI6InVzZXJuYW1lQGV4YW1wbGUuY29tIn0.QY9WFwJdTi4tod8S8bnh3gRGt6SzwVsf3RXOzRwQlHhPsfkOv9KiK4l3BX9FpBu_kM1aSWzkEO7Mx5Y_vxEH3A"
    },
    "message": "Successfully login",
    "status": "success"
}

Logout

  • Request
    Authorization: Bearer <access_token>
POST /api/user/Logout
  • Response
{
    "message": "Successfully logout",
    "status": "success"
}

Get user

  • Request
    Authorization: Bearer <access_token>
GET /api/user/
  • Response
{
    "data": {
        "first_name": "User First Name",
        "last_name": "User Last Name",
        "password": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8",
        "email": "[email protected]",
        "phone": "5555555555",
        "user_role": {
            "role_desc": "admin",
            "role_id": 4001
        },
        "avatar": null,
        "created_at": "2023-07-05T12:02:06Z",
        "last_login_at": "0001-01-01T00:00:00Z",
        "logout_at": "0001-01-01T00:00:00Z"
    },
    "message": "Successfully found",
    "status": "success"
}

Delete User (Admin Only)

  • Request
    Authorization: Bearer <access_token>
DELETE /api/user/delete/[email protected]
  • Response
{
    "message": "Successfully deleted",
    "status": "success"
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages