Vapor Documentation Beta

Class Session

public final class Session

Sessions are a method for associating data with a client accessing your app.

Each session has a unique identifier that is used to look it up with each request to your app. This is usually done via HTTP cookies.

See Request.session() and SessionsMiddleware for more information.

Initializers

init(id:​data:​)

public init(id: SessionID? = nil, data: SessionData = .init())

Create a new Session.

Normally you will use Request.session() to do this.

Properties

id

var id: SessionID?

This session's unique identifier. Usually a cookie value.

data

var data: SessionData

This session's data.

Methods

authenticate(_:​)

public func authenticate<A>(_ a: A) where A: SessionAuthenticatable

Authenticates the model into the session.

unauthenticate(_:​)

public func unauthenticate<A>(_ a: A.Type) where A: SessionAuthenticatable

Un-authenticates the model from the session.

authenticated(_:​)

public func authenticated<A>(_ a: A.Type) -> A.SessionID? where A: SessionAuthenticatable

Returns the authenticatable type's ID if it exists in the session data.

destroy()

public func destroy()

Invalidates the current session, removing persisted data from the session driver and invalidating the cookie.