fauth-template
Version:
Generate auth templates for your projects
133 lines (101 loc) • 3 kB
Markdown
# 🔑 Auth Template API 🚀
## Overview
This is a robust authentication API built with **Go**, **Fiber**, and **MongoDB**, providing user registration, login, and session management functionalities. It leverages JWTs for secure authentication and `.env` files for configuration.
## Features
- 🔐 **Secure Authentication**: Utilizes JWTs for session management.
- 💾 **Database Integration**: MongoDB for user data storage.
- ⚡ **High Performance**: Built with Fiber for speed.
- ⚙️ **Easy Configuration**: Uses `.env` files for configuration.
## Getting Started
### Installation
1. **Clone the Repository**:
```bash
git clone https://github.com/onosejoor/auth-template.git
cd auth-template/server
```
2. **Install Dependencies**:
```bash
go mod download
```
3. **Set Up Environment Variables**:
* Create a `.env` file in the root directory.
* Define the following environment variables:
### Environment Variables
- `JWT_SECRET`: Secret key for JWT encryption (e.g., `supersecretkey123`).
- `ENVIRONMENT`: Set to `production` for secure cookies in production (e.g., `development`).
## API Documentation
### Base URL
`http://localhost:8080/auth`
### Endpoints
#### POST `/auth/signup`
**Request**:
```json
{
"username": "testuser",
"email": "test@example.com",
"password": "password123"
}
```
**Response**:
```json
{
"success": true,
"message": "User created successfully"
}
```
**Errors**:
- 400: Invalid request body.
- 409: User already exists.
- 500: Internal error.
#### POST `/auth/signin`
**Request**:
```json
{
"email": "test@example.com",
"password": "password123"
}
```
**Response**:
```json
{
"success": true,
"message": "Welcome testuser"
}
```
**Errors**:
- 400: Incorrect Password / Error parsing data.
- 404: User not found.
- 500: Internal error.
#### GET `/auth/user/:id`
**Request**:
No body required.
**Response**:
```json
{
"success": true,
"user": {
"_id": "66789as7dy2y3ibasd89",
"email": "test@example.com",
"username": "testuser",
"created_at": "2024-05-01T12:00:00Z"
}
}
```
**Errors**:
- 404: Invalid Id / User does not exist.
- 500: Error getting user data.
## Technologies Used
| Technology | Link |
| :----------- | :----------------------------------------- |
| Go | [https://go.dev/](https://go.dev/) |
| Fiber | [https://gofiber.io/](https://gofiber.io/) |
| MongoDB | [https://www.mongodb.com/](https://www.mongodb.com/) |
| JWT | [https://jwt.io/](https://jwt.io/) |
## License
This project is licensed under the [MIT License](LICENSE).
## Author Info
- Author: Onos
- Social Media:
- [Twitter](https://twitter.com/YOUR_TWITTER_HANDLE)
- [LinkedIn](https://linkedin.com/in/YOUR_LINKEDIN_HANDLE)
[](https://www.npmjs.com/package/dokugen)