Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. export function loggedIn() {
  2. return {
  3. type: "LOGGED_IN",
  4. loggedIn: false
  5. }
  6. };
  7.  
  8. export default function reducer(state = {
  9. loggedIn: false
  10. }, action) {
  11. switch(action.type) {
  12. case "LOGGED_IN": {
  13. return {
  14. ...state,
  15. loggedIn: true
  16. }
  17. }
  18. case "LOGGED_OUT": {
  19. return {
  20. ...state,
  21. loggedIn: false
  22. }
  23. }
  24. default: return state;
  25. }
  26.  
  27. }
  28.  
  29. // Checks if user is not logged in
  30. const authCheck = (req, res, next) => {
  31. if(!req.user) {
  32. // If user is not logged in, redirect them to login page
  33. res.redirect('/auth/login');
  34. }
  35. else {
  36. // If user is logged in call next in router.get
  37.  
  38. // Would this be the proper place to dispatch to the Redux store
  39. // whether a user is logged in?
  40. dispatch(loggedIn(true));
  41. // After updating the Redux store call next()
  42. next();
  43. }
  44. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement