WebCallSession class

When a request is made to the web server a WebCallSession object is created. It contains all data associated with the current connection and provides easy access to the database.

Inheritance
Available extensions

Properties

authenticated AuthenticationInfo?
The authentication information for the session. This will be null if the session is not authenticated.
no setterinherited
authenticationKey String?
The authentication key used to authenticate the session.
no setterinherited
caches → Caches
Provides access to all caches used by the server.
no setterinherited
db Database
Access to the database.
no setterinherited
duration Duration
Returns the duration this session has been open.
no setterinherited
enableLogging bool
True if logging is enabled for this session. Normally, logging should be enabled but it will be disabled for internal sessions used by Serverpod.
finalinherited
endpoint String
Endpoint that triggered this session.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
isUserSignedIn bool
Returns true if the user is signed in.
no setterinherited
isWebAuthCookieRequest bool

Available on Session, provided by the WebAuthCookieSession extension

Whether the request participates in cookie-based web auth transport (via the webAuthModeHeaderName header) and the server has a ServerpodConfig.authCookie configured.
no setter
logQuery LogQueryFunction?
Optional function to log a query.
no setterinherited
logWarning LogWarningFunction?
Optional function to log a warning during the execution of a query.
no setterinherited
messages MessageCentralAccess
Access to the MessageCentral for passing real time messages between web socket streams and other listeners.
getter/setter pairinherited
method String?
Method that triggered this session, if any.
finalinherited
passwords Map<String, String>
Map of passwords loaded from config/passwords.yaml
no setterinherited
request Request?
The Request associated with the call, if any. This is null for InternalSession and FutureCallSession.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
server Server
The Server that created the session.
finalinherited
serverpod Serverpod
The Serverpod this session is running on.
no setterinherited
sessionId UuidValue
The id of the session.
finalinherited
startTime DateTime
The time the session object was created.
no setterinherited
storage StorageAccess
Provides access to the cloud storages used by this Serverpod.
latefinalinherited
transaction Transaction?
Optional transaction to use for all database queries. Only exists to support the serverpod_test package.
no setterinherited
userObject ↔ dynamic
A custom object associated with this Session.
getter/setter pairinherited
webAuthBasePath String?

Available on Session, provided by the WebAuthCookieSession extension

The browser-visible base path the cookie-mode client declared via the webBasePathHeaderName header, or null when absent or malformed.
no setter

Methods

addWillCloseListener(WillCloseListener listener) → void
Adds a listener that will be called when the session is about to close. The listener should return a FutureOr that completes when the listener is done.
inherited
alert(String message, {LogLevel? level}) → void
Logs message as an alert. Works like log, but the serverpod CLI shows it as a copyable alert in its terminal UI. Wrap a copyable segment in angle brackets, e.g. 'Code: <123456>'. Other log destinations treat it as a regular log message.
inherited
clearWebAuthCookie({String? refreshCookiePath}) → void

Available on Session, provided by the WebAuthCookieSession extension

Clears the auth cookie for cookie-mode requests (a no-op otherwise).
close({dynamic error, StackTrace? stackTrace}) Future<void>
Closes the session. This method should only be called if you have manually created a the Session e.g. by calling createSession on Serverpod. Closing the session finalizes and writes logs to the database. After a session has been closed, you should not call any more methods on it. Optionally pass in an error/exception and stackTrace if the session ended with an error and it should be written to the logs.
inherited
log(String message, {LogLevel? level, dynamic exception, StackTrace? stackTrace, Map<String, Object?>? metadata}) → void
Logs a message. Default LogLevel is LogLevel.info. The log is written to the database when the session is closed.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readWebAuthRefreshCookie() String?

Available on Session, provided by the WebAuthCookieSession extension

Reads the JWT refresh token from the refresh cookie for cookie-mode requests, or null when cookie mode is not active or the cookie is absent.
removeWillCloseListener(WillCloseListener listener) → void
Removes a listener that will be called when the session is about to close.
inherited
setResponseCookie(SetCookie cookie) → void
Adds a Set-Cookie to this call's HTTP response. See setResponseHeader for which calls this applies to. To remove a cookie on the client, set one with the same name and maxAge: 0.
inherited
setResponseHeader(String name, String value) → void
Sets the HTTP response header name to value for this call.
inherited
toString() String
A string representation of this object.
inherited
updateAuthenticated(AuthenticationInfo? info) → void
Updates the authentication information for the session. This is typically done by the Server when the user is authenticated. Using this method modifies the authenticated user for this session.
inherited
writeWebAuthCookie(String token, {int? maxAgeSeconds}) bool

Available on Session, provided by the WebAuthCookieSession extension

If isWebAuthCookieRequest, writes token as the auth cookie and returns true. Otherwise returns false and the caller should return the token in the response body as usual. maxAgeSeconds sets the cookie lifetime; omit it for a session cookie.
writeWebAuthRefreshCookie(String refreshToken, {int? maxAgeSeconds, String? path}) bool

Available on Session, provided by the WebAuthCookieSession extension

If isWebAuthCookieRequest, writes refreshToken as the JWT refresh cookie and returns true. Otherwise returns false and the caller should return the refresh token in the response body as usual.

Operators

operator ==(Object other) bool
The equality operator.
inherited