Add ability to change message type in middleware util
This commit is contained in:
@ -24,12 +24,14 @@ import {
|
||||
|
||||
const sendNonUserToSignIn = ifNoUserRedirectTo(
|
||||
'/login',
|
||||
'You must be signed in to commit to a non-profit'
|
||||
'You must be signed in to commit to a nonprofit.',
|
||||
'info'
|
||||
);
|
||||
|
||||
const sendNonUserToCommit = ifNoUserRedirectTo(
|
||||
'/commit',
|
||||
'You must be signed in to update commit'
|
||||
'You must be signed in to update commit',
|
||||
'info'
|
||||
);
|
||||
|
||||
const debug = debugFactory('freecc:commit');
|
||||
|
@ -1,11 +1,11 @@
|
||||
export function ifNoUserRedirectTo(url, message) {
|
||||
export function ifNoUserRedirectTo(url, message, type = 'errors') {
|
||||
return function(req, res, next) {
|
||||
const { path } = req;
|
||||
if (req.user) {
|
||||
return next();
|
||||
}
|
||||
|
||||
req.flash('errors', {
|
||||
req.flash(type, {
|
||||
msg: message || `You must be signed to go to ${path}`
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user