A11yWatch/a11ywatch-core

View on GitHub
src/core/graph/mutations/authentication/register.ts

Summary

Maintainability
B
4 hrs
Test Coverage
import { EMAIL_ERROR } from "../../../strings";
import { UsersController } from "../../../controllers";
import { cookieConfigs } from "../../../../config";

// register a user account via mutation
export async function register(
  _,
  { email, password, googleId, githubId },
  context
) {
  const loginUser = await UsersController().createUser({
    email,
    password,
    googleId,
    githubId,
  });

  if (!loginUser) {
    throw new Error(EMAIL_ERROR);
  }

  if (context?.res?.cookie) {
    context.res.cookie("jwt", loginUser.jwt, cookieConfigs);
  }

  return loginUser;
}