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

31
app/models/key.go Normal file
View File

@@ -0,0 +1,31 @@
package models
import (
"time"
"git.secnex.io/secnex/auth-api/utils"
"github.com/google/uuid"
"gorm.io/gorm"
)
type ApiKey struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
Key string `gorm:"not null" json:"key"`
Enabled bool `gorm:"not null;default:true" json:"enabled"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
}
func (ApiKey) TableName() string {
return "api_keys"
}
func (apiKey *ApiKey) BeforeCreate(tx *gorm.DB) (err error) {
apiKeyHash, err := utils.Hash(apiKey.Key)
if err != nil {
return err
}
apiKey.Key = apiKeyHash
return nil
}