hapi-stateless-notifications

    4.1.0 • Public • Published

    hapi-stateless-notifications

    A plugin to handle saving notifications to pass to a following page, so you can redirect after post and all those niceties without having to fall back to session-associated flash messages.

    Use

    // step 0: set up a plugin that gives a request.redis property that's a
    // client connection, ready to use for this request. We steal the
    // connection from `catbox-redis`.
    
    server.register({
        register: require('hapi-stateless-notifications'),
        options: {
            queryParameter: 'notice',
            prefix: 'notice:',
            timeout: 3600
        }
    });
    

    The options are optional.

    options.queryParameter controls which query parameter will cause the plugin to look up a token and defaults to 'notice' options.prefix controls the key prefix in redis, and defaults to 'notice:' options.timeout controls the the expiration timeout of the key in redis, in seconds. The default is 3600, that is, one hour.

    Then in a handler:

    reply.saveNotifications([
        Promise.resolve('Success message here ...'),
        Promise.reject(new Error('Error message here ...')),
    ]).then(function (token) {
        // if there's a token, put it in the query of the page you load next as `notice={token}`
        // Otherwise, there's nothing to do.
    });
    

    Or more completely:

    reply.redirectAndNotify([
        Promise.resolve('Success message here ...'),
        Promise.reject(new Error('Error message here ...')),
    ], '/next-page')
    

    or if the failure path leads a different place:

    reply.redirectAndNotify([
        Promise.resolve('Success message here ...'),
        Promise.reject(new Error('Error message here ...')),
    ], { success: '/next-page', failure: '/this-page' })
    

    Install

    npm i hapi-stateless-notifications

    DownloadsWeekly Downloads

    6

    Version

    4.1.0

    License

    ISC

    Last publish

    Collaborators

    • kmkumaran
    • fauldsh
    • trevrosen
    • vipuljain
    • bhaveshbhati
    • devyani-chowdhury2
    • ben-1997
    • raashidanwar
    • ruslan-bikkinin
    • makhmudjon-inadullaev
    • isaacs
    • fritzy
    • npm
    • kirupakaranh
    • npmci
    • 20shivangi
    • akshayagh
    • nishantms
    • prabum3
    • ghostdevhv
    • s121pradhan
    • amit-avit
    • saquibkhan
    • nehsharmms
    • dhilipdkkumar
    • sandeepmeduru
    • singit
    • lisayu
    • neeldani
    • arjgupta
    • ashishonce
    • nlf
    • asranja
    • phanikm
    • andrialexandrou
    • thedave42
    • gar
    • darcyclarke
    • ruyadorno
    • mangwana
    • npm-sre-readonly
    • npm-sre-write
    • robdnpm
    • john7doe
    • soph2k
    • lumaxis
    • meijin007
    • sapieneptus
    • jacobe
    • gordey4doronin
    • hilli
    • christoflemke
    • maxxkrakoa
    • owenniblock
    • olefriis
    • ethomson
    • baj-
    • stoneman
    • radiantspace
    • smeirsha
    • jmoody
    • t-dekell
    • t-dedim
    • mylesborins
    • ndorfman
    • npm-qa
    • npm-qa-tfa1
    • npm-qa-tfa2
    • jar349
    • trevorsg
    • rzhade3
    • seryozha95
    • royetadmor
    • synse
    • fabyus
    • lukekarrys
    • levenleven
    • timaramazanov
    • anurbol
    • aredridel