PedroBern / django-graphql-auth

Django registration and authentication with GraphQL.

Home Page:https://django-graphql-auth.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to ensure email is never blank to register?

luis-amarquez opened this issue · comments

Prerequisites

  • Is it a bug?
  • Is it a new feature?
  • Is it a question?

Description

I am currently working on the registration part of my api and stumbled upon an inconvenience. When my user registers, I want them to pass their email. and not leave it blank. Now through my frontend, I can simply validate that the email field is not black and if so indicate to my user to input their email. However, if for whatever reason they may want to send a POST request directly to my api, I do not want them to leave the email field blank. Even though email has to be included in the query, if they enter a blank string, email: "" they will successfully register. How am I able to make sure that when a user registers, the email field always has at least some text to return an invalid email address message?

# schema.py

import graphene
from graphql_auth import mutations
from graphql_auth.schema import UserQuery, MeQuery


class AuthMutation(graphene.ObjectType):
    register = mutations.Register.Field()


class Query(UserQuery, MeQuery, graphene.ObjectType):
    pass


class Mutation(AuthMutation, graphene.ObjectType):
    update_fields_list = ["first_name", "last_name"]
    pass


schema = graphene.Schema(query=Query, mutation=Mutation)

Expected behavior

I want this mutation to result in an error as no email was passed.

mutation {
  register(
    email: "",
    ...
  ) {
    success,
    errors,
  }
}

Actual behavior

The actual behavior of the above mutation results in the successful creation of an account and User instance.