call method

Future<void> call(
  1. Context context,
  2. Next next
)

As the session manager is a Spry middleware, it must implement the call method.

Implementation

Future<void> call(Context context, Next next) async {
  // Store the session manager in the context.
  context[SessionManager] = this;

  // Resolve the session identifier.
  final info = await findOrCreateIdentifierInfo(context.request);

  /// Create a session.
  final session = Session(adapter: adapter, info: info);

  // Store the session in the context.
  context[Session] = session;

  // Calls the next middleware.
  await next();

  print(info.renewed);

  // Send the session cookie.
  if (info.renewed) {
    final cookie = await createCookie(session);
    context.response.cookies.add(cookie);
  }
}