Skip to content

Commit

Permalink
Merge branch 'release/0.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
DominusKelvin committed Feb 28, 2024
2 parents dd31187 + 096a41f commit 17b8247
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion inertia-sails/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inertia-sails",
"version": "0.1.8",
"version": "0.1.9",
"description": "The Sails adapter for Inertia.",
"main": "index.js",
"sails": {
Expand Down
42 changes: 22 additions & 20 deletions inertia-sails/private/inertia-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,29 @@ const getPartialData = require('./get-partial-data')
const resolveValidationErrors = require('./resolve-validation-errors')
function inertia(sails, { hook, sharedProps, sharedViewData, rootView }) {
return function inertiaMiddleware(req, res, next) {
/**
* Flash messages stored in the session.
* @typedef {Object} FlashMessages
* @property {Array} message - Flash message(s).
* @property {Array} error - Error message(s).
* @property {Array} success - Success message(s).
*/
const flash = {
message: req.flash('message'),
error: req.flash('error'),
success: req.flash('success')
}
hook.share('flash', flash) // Share the flash object as props
/**
* Validation errors stored in the session, resolved and formatted for Inertia.js.
* @type {Object}
*/
const validationErrors = resolveValidationErrors(req)
req.flash('errors', validationErrors) // Flash the validation error so we can share it later
if (isInertiaRequest(req)) {
/**
* Flash messages stored in the session.
* @typedef {Object} FlashMessages
* @property {Array} message - Flash message(s).
* @property {Array} error - Error message(s).
* @property {Array} success - Success message(s).
*/
const flash = {
message: req.flash('message'),
error: req.flash('error'),
success: req.flash('success')
}
hook.share('flash', flash) // Share the flash object as props
/**
* Validation errors stored in the session, resolved and formatted for Inertia.js.
* @type {Object}
*/
const validationErrors = resolveValidationErrors(req)
req.flash('errors', validationErrors) // Flash the validation error so we can share it later

hook.share('errors', req.flash('errors')[0] || {}) // Share validation errors as props
hook.share('errors', req.flash('errors')[0] || {}) // Share validation errors as props
}

hook.render = function (component, props = {}, viewData = {}) {
const allProps = {
Expand Down

0 comments on commit 17b8247

Please sign in to comment.