engagementgamelab/CivicSeed

View on GitHub
server/middleware/account.js

Summary

Maintainability
A
1 hr
Test Coverage
'use strict'

// Only let a request through if the session has been authenticated
exports.authenticated = function (framework) {
  return function (req, res, next) {
    if (req.session && (req.session.userId !== null)) {
      return next()
    } else {
      if (framework === 'express') {
        if (req.url.match(/^\/admin/g)) {
          return res.redirect('/')
        }
        return next()
      } else {
        return res('NOT_AUTHENTICATED')
      }
    }
  }
}