Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion auth-jwt/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=
DB_NAME=
SECRET=
SECRET=
ACCESS_TOKEN_TTL_MINUTES=15
2 changes: 2 additions & 0 deletions auth-jwt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ The following endpoints are available in the API:

- **POST /api/auth/register**: Register a new user.
- **POST /api/auth/login**: Authenticate a user and return a JWT.
- **POST /api/auth/logout**: Logout a user and revoke their JWT.
- **POST /api/auth/refresh-token**: Refreshes a user token and return a JWT.
- **GET /api/user/:id**: Get a user (requires a valid JWT).
- **POST /api/user**: Create a new user.
- **PATCH /api/user/:id**: Update a user (requires a valid JWT).
Expand Down
32 changes: 0 additions & 32 deletions auth-jwt/database/connect.go

This file was deleted.

28 changes: 27 additions & 1 deletion auth-jwt/database/database.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
package database

import "gorm.io/gorm"
import (
"fmt"

"auth-jwt-gorm/config"
"auth-jwt-gorm/models"

"gorm.io/driver/postgres"
"gorm.io/gorm"
)

// DB gorm connector
var DB *gorm.DB

// ConnectDB connect to db
func ConnectDB() {
dsn := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",
config.Config("DB_HOST"),
config.Config("DB_PORT"),
config.Config("DB_USER"),
config.Config("DB_PASSWORD"),
config.Config("DB_NAME"))

var err error
DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}

DB.AutoMigrate(&models.Product{}, &models.User{})
}
4 changes: 2 additions & 2 deletions auth-jwt/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module api-fiber-gorm
module auth-jwt-gorm

go 1.23.0

require (
github.com/gofiber/contrib/jwt v1.1.2
github.com/gofiber/fiber/v2 v2.52.9
github.com/golang-jwt/jwt/v5 v5.3.0
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
golang.org/x/crypto v0.40.0
gorm.io/driver/postgres v1.6.0
Expand All @@ -15,7 +16,6 @@ require (
require (
github.com/MicahParks/keyfunc/v2 v2.1.0 // indirect
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.5 // indirect
Expand Down
8 changes: 0 additions & 8 deletions auth-jwt/handler/api.go

This file was deleted.

114 changes: 0 additions & 114 deletions auth-jwt/handler/auth.go

This file was deleted.

53 changes: 0 additions & 53 deletions auth-jwt/handler/product.go

This file was deleted.

Loading