feat(auth): Add login, register, session_info and api creation

This commit is contained in:
Björn Benouarets
2026-01-15 20:25:17 +01:00
commit 13d908420a
31 changed files with 1421 additions and 0 deletions

38
app/models/users.go Normal file
View File

@@ -0,0 +1,38 @@
package models
import (
"time"
"git.secnex.io/secnex/auth-api/utils"
"github.com/google/uuid"
"gorm.io/gorm"
)
type User struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
FirstName string `gorm:"not null" json:"first_name"`
LastName string `gorm:"not null" json:"last_name"`
Username string `gorm:"not null;unique" json:"username"`
Password string `gorm:"not null" json:"password"`
Email string `gorm:"not null;unique" json:"email"`
Verified bool `gorm:"not null;default:false" json:"verified"`
TenantID *uuid.UUID `gorm:"type:uuid" json:"tenant_id"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
Tenant *Tenant `gorm:"foreignKey:TenantID" json:"tenant"`
}
func (User) TableName() string {
return "users"
}
func (user *User) BeforeCreate(tx *gorm.DB) (err error) {
passwordHash, err := utils.Hash(user.Password)
if err != nil {
return err
}
user.Password = passwordHash
return nil
}