Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function loggedIn() {
- return {
- type: "LOGGED_IN",
- loggedIn: false
- }
- };
- export default function reducer(state = {
- loggedIn: false
- }, action) {
- switch(action.type) {
- case "LOGGED_IN": {
- return {
- ...state,
- loggedIn: true
- }
- }
- case "LOGGED_OUT": {
- return {
- ...state,
- loggedIn: false
- }
- }
- default: return state;
- }
- }
- // Checks if user is not logged in
- const authCheck = (req, res, next) => {
- if(!req.user) {
- // If user is not logged in, redirect them to login page
- res.redirect('/auth/login');
- }
- else {
- // If user is logged in call next in router.get
- // Would this be the proper place to dispatch to the Redux store
- // whether a user is logged in?
- dispatch(loggedIn(true));
- // After updating the Redux store call next()
- next();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement