<commit_before>import { updateUser } from '../db'
import { success, unauthorized, badRequest } from '../util/http'
import { validWatchingStars } from '../util/validations'

export default async function watchingStars ({ body, token }, res, next) {
  if (!token) { return next(unauthorized()) }
  if (!body || !validWatchingStars(body.watchingStars)) { return next(badRequest()) }
  const attrs = { watchingStars: body.watchingStars }
  await updateUser(token, attrs)
  success(res, attrs)
}<commit_msg>fix(server): forbid watching stars if user has no access token<commit_after>import { updateUser, loadUser } from '../db'
import { success, unauthorized, badRequest } from '../util/http'
import { validWatchingStars } from '../util/validations'

export default async function watchingStars ({ body, token }, res, next) {
  if (!token) { return next(unauthorized()) }
  if (!body || !validWatchingStars(body.watchingStars)) { return next(badRequest()) }
  const { accessToken } = await loadUser(token)
  if (!accessToken)  { return next(badRequest()) }
  const attrs = { watchingStars: body.watchingStars }
  await updateUser(token, attrs)
  success(res, attrs)
}
{'fraction_non_alphanumeric': 0.13941480206540446, 'fraction_numerical': 0.0, 'mean_word_length': 5.025906735751295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6603220', 'n_tokens_mistral': 343, 'n_tokens_neox': 346, 'n_words': 100}