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;type:uuid;default:gen_random_uuid()"` 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) }