Go Fiber Authentication API is a RESTful API built using the Fiber web framework.
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"
- Clone the repository:
git clone https://github.com/yusuftalhaklc/go-fiber-authentication.git
- Navigate to the project directory:
cd go-fiber-authentication
- Install the dependencies:
go mod tidy
- Start the API server:
go run main.go
It is currently running on localhost port 8080. Postman Collection
- Endpoint:
/api/signup
- Method:
POST
- Description: Signup.
- Endpoint:
/api/user/login
- Method:
POST
- Description: Login.
- Endpoint:
/api/user/logout
- Method:
POST
- Description: Logout.
- Endpoint:
/api/user/
- Method:
GET
- Description: Get user details.
- Endpoint:
/api/user/delete/:email
- Method:
DELETE
- Description: Deletes user.
- 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"
}
- Request
{
"email": "[email protected]",
"password": "password"
}
- Response
{
"data": {
"email": "[email protected]",
"token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2ODc5ODIwOTEsImlkIjoiMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIiwibWFpbCI6InVzZXJuYW1lQGV4YW1wbGUuY29tIn0.QY9WFwJdTi4tod8S8bnh3gRGt6SzwVsf3RXOzRwQlHhPsfkOv9KiK4l3BX9FpBu_kM1aSWzkEO7Mx5Y_vxEH3A"
},
"message": "Successfully login",
"status": "success"
}
- Request
Authorization: Bearer <access_token>
POST /api/user/Logout
- Response
{
"message": "Successfully logout",
"status": "success"
}
- 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"
}
- Request
Authorization: Bearer <access_token>
DELETE /api/user/delete/[email protected]
- Response
{
"message": "Successfully deleted",
"status": "success"
}