backend-server-v2/internal/models/auth_tokens.go

39 lines
886 B
Go

package models
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type EmailVerificationToken struct {
ID string `gorm:"primaryKey"`
UserID string `gorm:"not null;index"`
TokenHash string `gorm:"size:64;uniqueIndex;not null"`
ExpiresAt time.Time `gorm:"not null;index"`
CreatedAt time.Time
UpdatedAt time.Time
}
func (token *EmailVerificationToken) BeforeCreate(tx *gorm.DB) (err error) {
// UUID version 4
token.ID = uuid.NewString()
return
}
type PasswordResetToken struct {
ID string `gorm:"primaryKey"`
UserID string `gorm:"not null;index"`
TokenHash string `gorm:"size:64;uniqueIndex;not null"`
ExpiresAt time.Time `gorm:"not null;index"`
CreatedAt time.Time
UpdatedAt time.Time
}
func (token *PasswordResetToken) BeforeCreate(tx *gorm.DB) (err error) {
// UUID version 4
token.ID = uuid.NewString()
return
}