~mna/tulip

The tulip.pkg.flash module exports the flash package.

#Dependencies

  • tulip.pkg.middleware

#Configuration

  • cookie_name: string = name of the cookie holding the messages (default: 'flash')
  • domain: string = domain of the flash cookie (default: not set)
  • path: string = path of the flash cookie (default: not set)
  • secure: boolean = secure flag of the flash cookie (default: true)
  • http_only: boolean = http-only flag of the flash cookie (default: true)
  • same_site: string = same-site flag of the flash cookie (default: 'lax')

#API Extensions

Registering this package provides the following method and field extensions.

#ok, err = Request:flash(...)

Adds flash messages to be stored for the next request. Flash messages are (short) feedback messages that are generated in one request, but only used in a subsequent request (e.g. following an account creation, after a redirect to the login page, the "account created, please login" message could be displayed). To that end, the flash messages are stored in a session cookie by the middleware registered with this package.

Args:

  • ...: table|string = the message(s) to add, will be url-encoded in the cookie.

Returns:

  • ok: boolean = true on success
  • err: Error|nil = if v is falsy, the error message

#Registered Middleware

The following middleware are registered and can be referenced by name in the configuration.

#tulip.pkg.flash

Must be added before any handler that writes the response and any handler that uses existing flash messages. Available flash messages for a request (that is, flash messages that were added in a previous request) are stored on req.locals.flash. Messages added by Request:flash will be stored in a cookie before the response is written.

Back to index

About this wiki

commit 3ebfbd288b8e5c95fdf8ce2027a0e94cfa1c8976
Author: Martin Angers <martin.n.angers@gmail.com>
Date:   2021-02-25T14:07:12-05:00

Update to reflect Request:validate_body
Clone this wiki
https://git.sr.ht/~mna/tulip-wiki (read-only)
git@git.sr.ht:~mna/tulip-wiki (read/write)