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