<commit_before>import {Resolver, Mutation, Arg, Ctx, ID, Authorized} from "type-graphql"

import createError from "http-errors"

import ApiContext from "server/type/Context"

import SignUpInput from "server/api/input/auth/SignUpInput"
import LogInInput from "server/api/input/auth/LogInInput"

import Viewer from "server/api/type/user/Viewer"

import User from "server/model/User"

@Resolver()
class AuthResolver {
  @Mutation(() => Viewer)
  async authSignUp(
    @Ctx() ctx: ApiContext,
    @Arg("user", () => SignUpInput) user: SignUpInput
  ): Promise<Viewer> {
    const created = await User.createAndSave(user)

    ctx.req.session.userId = created.id

    return created
  }

  @Mutation(() => Viewer)
  async authLogIn(
    @Ctx() ctx: ApiContext,
    @Arg("credentials", () => LogInInput) {username, password}: LogInInput
  ): Promise<Viewer> {
    const user = await User.findOne({
      where: [{email: username}, {login: username}]
    })

    if (!(user || await user.comparePassword(password))) {
      createError(401, "Auth failed: Check your credentials")
    }

    ctx.req.session.userId = user.id

    return user
  }

  @Authorized()
  @Mutation(() => ID)
  authLogOut(@Ctx() ctx: ApiContext): Promise<string> {
    return new Promise<string>((resolve, reject) => {
      const id = ctx.req.sessionId

      ctx.req.session.destroy(error => error ? reject(error) : resolve(id))
    })
  }
}

export default AuthResolver<commit_msg>Fix returning type for authLogOut<commit_after>import {Resolver, Mutation, Arg, Ctx, ID, Authorized} from "type-graphql"

import ApiContext from "server/type/Context"

import unauthorized from "server/error/common/unauthorized"

import SignUpInput from "server/api/input/auth/SignUpInput"
import LogInInput from "server/api/input/auth/LogInInput"

import Viewer from "server/api/type/user/Viewer"

import User from "server/model/User"

@Resolver()
class AuthResolver {
  @Mutation(() => Viewer)
  async authSignUp(
    @Ctx() ctx: ApiContext,
    @Arg("user", () => SignUpInput) user: SignUpInput
  ): Promise<Viewer> {
    const created = await User.createAndSave(user)

    ctx.req.session.userId = created.id

    return created
  }

  @Mutation(() => Viewer)
  async authLogIn(
    @Ctx() ctx: ApiContext,
    @Arg("credentials", () => LogInInput) {username, password}: LogInInput
  ): Promise<Viewer> {
    const user = await User.findOne({
      where: [{email: username}, {login: username}]
    })

    if (!(user || await user.comparePassword(password))) {
      unauthorized("Auth failed: Check your credentials")
    }

    ctx.req.session.userId = user.id

    return user
  }

  @Authorized()
  @Mutation(() => ID)
  authLogOut(@Ctx() ctx: ApiContext): Promise<number> {
    return new Promise<number>((resolve, reject) => {
      const id = ctx.req.session.userId

      ctx.req.session.destroy(error => error ? reject(error) : resolve(id))
    })
  }
}

export default AuthResolver
{'fraction_non_alphanumeric': 0.14048184594502885, 'fraction_numerical': 0.0010179843909060061, 'mean_word_length': 3.8407224958949095, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '6688540', 'n_tokens_mistral': 944, 'n_tokens_neox': 943, 'n_words': 228}