package models import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) type Session struct { gorm.Model ID uuid.UUID `gorm:"type:uuid;primaryKey"` AccountID uuid.UUID `gorm:"type:uuid;not null;index"` AuthToken string `gorm:"uniqueIndex;not null"` RefreshToken string `gorm:"uniqueIndex;not null"` AuthExpiry time.Time `gorm:"not null"` RefreshExpiry time.Time `gorm:"not null"` IPAddress string UserAgent string Account Account `gorm:"foreignKey:AccountID"` } func (self *Session) BeforeCreate(tx *gorm.DB) error { if self.ID == uuid.Nil { self.ID = uuid.New() } return nil } func (self *Session) IsAuthExpired() bool { return time.Now().After(self.AuthExpiry) } func (self *Session) IsRefreshExpired() bool { return time.Now().After(self.RefreshExpiry) }