Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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