Flash Messages Middleware For Koa
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.babelrc
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
package.json
release.js

README.md

koa-flash-message

NPM Version Build Status codecov

Flash messages middleware for koa v2 application.

Installation

$ npm install koa-flash-message

koa-flash-message middleware depends on koa-generic-session. You must add koa-generic-session as a middleware prior to adding koa-flash-message

Example

import Koa from 'koa';
import session from 'koa-generic-session';
import koaRedis from 'koa-redis';
import flashMessage from 'koa-flash-message';
import convert from 'koa-convert';

const redisStore = koaRedis({
  url: config.redisUrl
});

const app = new Koa();

app.keys = [config.secretKeyBase];
app.use(convert(session({
  store: redisStore,
  prefix: '__sess:',
  key: '__sid'
})));

app.use(flashMessage);

add message to flash messages

ctx.flashMessage.warning = 'Log Out Successfully!';

read all flash messages

ctx.state.flashMessage.messages
// or ctx.flashMessage.messages

read warning message

ctx.state.flashMessage.warning
// or ctx.flashMessage.warning

Full Example Code

Author

License

MIT