Token
final class Token : Model
extension Token: ModelTokenAuthenticatable
A Token
model associates a randomly generated string with a User
.
A Token is generated upon each login, and revoked by deletion upon each logout.
The .token
value is used in between those events in an HTTP Bearer Authorization
header field to authenticate the user sending API requests. There is no
identifying user info in a .token
; the association to a specific User
is
done internally on the API server through this model.
-
Declaration
Swift
static let schema: String
-
The Token’s ID, provisioned automatically.
Declaration
Swift
@ID var id: UUID?
-
The generated token value.
Declaration
Swift
@Field var token: String
-
Timestamp of the model’s creation, set automatically.
Declaration
Swift
@Timestamp var createdAt: Date?
-
Declaration
Swift
init()
-
Initializes a new Token.
Declaration
Swift
init(token: String, userID: UUID)
Parameters
token
The generated token string.
userID
The
User
associated to the token. -
Required key for HTTP Bearer Authorization token.
Declaration
Swift
static let valueKey: <<error type>>
-
Declaration
Swift
static let userKey: <<error type>>
-
Declaration
Swift
var isValid: Bool { get }