Hi there, I'm currently writing a schema where I ...
# ory-network
e
Hi there, I'm currently writing a schema where I want users to log in with either username or email (similar to how twitter handles logins).
Copy code
json
{
  "title": "Person",
  "type": "object",
  "properties": {
    "traits": {
      "type": "object",
      "properties": {
        "username": {
          "type": "string",
          "title": "Username",
          "maxLength": 40,
          "<http://ory.sh/kratos|ory.sh/kratos>": {
            "credentials": {
              "password": {
                "identifier": true
              },
              "webauthn": {
                "identifier": true
              },
              "totp": {
                "account_name": true
              }
            }
          }
        },
        "email": {
          "type": "string",
          "format": "email",
          "title": "E-Mail",
          "<http://ory.sh/kratos|ory.sh/kratos>": {
            "credentials": {
              "password": {
                "identifier": true
              },
              "webauthn": {
                "identifier": true
              },
              "totp": {
                "account_name": true
              }
            },
            "recovery": {
              "via": "email"
            },
            "verification": {
              "via": "email"
            }
          },
          "maxLength": 320
        }
      },
      "anyOf": [
        {
          "required": [
            "email"
          ]
        },
        {
          "required": [
            "username"
          ]
        }
      ],
      "additionalProperties": false
    }
  }
}
I assumed “anyOf” would do the job, however when I register with a username and try to add an email in the account settings, it throws
valid against schemas at indexes 0 and 1
. (As I'm currently still using the default UI of ory, it even renders a random input text box for “traits”:

https://i.imgur.com/8PMpl1S.png

) Anyway, my main issue is how to solve this anyOf thing. According to json-schema.org (https://json-schema.org/understanding-json-schema/reference/combining.html#anyof) "the given data must be valid against any (one or more) of the given subschemas", which is the case here, yet I get an error.
Also, unlike twitter our usernames are optional if an email is set.
b
Hi Marc, thanks for reaching out. Unfortunately I could not reproduce this issue with the config you provided. Just to double check: 1. you created the schema 2. registered a new account with just a username 3. logged in 4. added an email address in the settings Is this correct?
👍 1
e
I just tried it again with a new account, and looks like it solved itself. I guess this is because I was playing with the schemas before, created an account, and changed the schema afterwards again, and then continued testing with that account which was created with an old schema(?)