diff options
| author | Bobby <[email protected]> | 2026-03-29 22:52:46 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-29 22:52:46 +0530 |
| commit | 9eb9b7f4bd552a641235764f66483e1f940fcfd9 (patch) | |
| tree | da520b923b5e6758d5457b6233dd6671fc640914 /nexus/models/session.go | |
| parent | 65a143a0871c35989b7c7ea6723d39a0585c089e (diff) | |
| download | echoes-of-vaelun-main.tar.xz echoes-of-vaelun-main.zip | |
Diffstat (limited to 'nexus/models/session.go')
| -rw-r--r-- | nexus/models/session.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/nexus/models/session.go b/nexus/models/session.go new file mode 100644 index 0000000..0adbba2 --- /dev/null +++ b/nexus/models/session.go @@ -0,0 +1,36 @@ +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)
+}
|
