<commit_before>import { match } from "path-to-regexp"

const USER_REQUIRED_ROUTES = [
  "/identity-verification(.*)",
  "/orders(.*)",
  "/user/conversations(.*)",
]

const isRequestRequiringUser = req => {
  return USER_REQUIRED_ROUTES.map(route => match(route)).some(matcher =>
    matcher(req)
  )
}

export const userRequiredMiddleware = (req, res, next) => {
  if (isRequestRequiringUser(req.path)) {
    if (!res.locals.sd.CURRENT_USER) {
      return res.redirect(
        `/login?redirectTo=${encodeURIComponent(req.originalUrl)}`
      )
    }
  }<commit_msg>Redirect users to login on purchse routes<commit_after>import { match } from "path-to-regexp"

const USER_REQUIRED_ROUTES = [
  "/identity-verification(.*)",
  "/orders(.*)",
  "/user/conversations(.*)",
  "/user/purchases(.*)",
]

const isRequestRequiringUser = req => {
  return USER_REQUIRED_ROUTES.map(route => match(route)).some(matcher =>
    matcher(req)
  )
}

export const userRequiredMiddleware = (req, res, next) => {
  if (isRequestRequiringUser(req.path)) {
    if (!res.locals.sd.CURRENT_USER) {
      return res.redirect(
        `/login?redirectTo=${encodeURIComponent(req.originalUrl)}`
      )
    }
  }
{'fraction_non_alphanumeric': 0.16568544995794784, 'fraction_numerical': 0.0, 'mean_word_length': 3.857142857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5830942', 'n_tokens_mistral': 422, 'n_tokens_neox': 427, 'n_words': 65}