linstrom/storage-new/models/TokenAccess.go
mStar e182949a8d
Remove id autogeneration from db models
Remove automatic uuid v4 ID generation from the models and replace it
with `shared.NewId()`, which generates an Id depending on the config
setting
2025-05-06 14:34:32 +02:00

29 lines
943 B
Go

package models
import (
"time"
"gorm.io/gen"
)
// AccessToken maps a unique token to one account.
// Access to server resource may only happen with a valid access token.
// Access tokens are granted by [auth-new/auth.Authenticator].
// Each account may have multiple access tokens at any time
type AccessToken struct {
User User // The account the token belongs to
UserId string
// The token itself is a uuid value
Token string `gorm:"primarykey"`
Name string // Token name will be empty if autogenerated with sucessful login
// Every token expires, even if set to "not expire". If set to "not expire", it just expires
// at a point in the future this server should never reach
ExpiresAt time.Time `gorm:"default:TIMESTAMP WITH TIME ZONE '9999-12-30 23:59:59+00'"`
}
type IAccessToken interface {
// Get the data for a token
//
// SELECT * FROM @@table WHERE token = @token
GetTokenIfValid(token string) (*gen.T, error)
}