Add complete database schema and ORM models (#4)
This commit was merged in pull request #4.
This commit is contained in:
27
internal/models/auth_token.go
Normal file
27
internal/models/auth_token.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// AuthToken represents an authentication token for a user session.
|
||||
type AuthToken struct {
|
||||
Base
|
||||
|
||||
Token string `json:"-"`
|
||||
UserID string `json:"userId"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
|
||||
LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
|
||||
}
|
||||
|
||||
// User returns the user who owns this token.
|
||||
func (t *AuthToken) User(ctx context.Context) (*User, error) {
|
||||
if ul := t.GetUserLookup(); ul != nil {
|
||||
return ul.GetUserByID(ctx, t.UserID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("user lookup not available")
|
||||
}
|
||||
Reference in New Issue
Block a user