Created
April 19, 2017 03:26
-
-
Save rttomlinson/5c7a38e1dcb0cc17c303e643cc32937b to your computer and use it in GitHub Desktop.
Flash messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // routers/sessions.js | |
| // Destroy | |
| var onDestroy = (req, res) => { | |
| // Display flash message that logout | |
| // was successful | |
| req.flash('success', 'Successfully logged out!'); | |
| req.session.currentUser = null; | |
| res.redirect('/login'); | |
| }; | |
| router.get('/logout', onDestroy); | |
| router.delete('/logout', onDestroy); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // helpers/flash_helper.js | |
| var FlashHelper = {}; | |
| FlashHelper.bootstrapAlertClassFor = function(key) { | |
| return { | |
| "error": "danger", | |
| "alert": "danger", | |
| "notice": "info" | |
| }[key] || key; | |
| }; | |
| module.exports = FlashHelper; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ---------------------------------------- | |
| // Flash Messages | |
| // ---------------------------------------- | |
| var flash = require('express-flash-messages'); | |
| app.use(flash()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment