feat(auth): Add login, register, session_info and api creation
This commit is contained in:
31
app/models/key.go
Normal file
31
app/models/key.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user