deleteCookie function

void deleteCookie(
  1. H4Event event,
  2. String name, {
  3. String path = '/',
  4. String? domain,
})

Parameters:

  • event: An H4Event instance containing the HTTP request.
  • name: The name of the cookie to delete.
  • path: Optional path of the cookie (must match the original cookie's path)
  • domain: Optional domain of the cookie (must match the original cookie's domain)

Example:

deleteCookie(event, 'auth_token');

Implementation

void deleteCookie(H4Event event, String name,
    {String path = '/', String? domain}) {
  final response = event.node["value"]?.response;
  if (response == null) return;
  final cookie = Cookie(name, '');
  cookie.expires = DateTime(1970); // Set expiration to the past
  cookie.maxAge = 0;
  cookie.path = path;
  if (domain != null) {
    cookie.domain = domain;
  }

  response.cookies.add(cookie);
}