graphile / starter

Opinionated SaaS quick-start with pre-built user account and organization system for full-stack application development in React, Node.js, GraphQL and PostgreSQL. Powered by PostGraphile, TypeScript, Apollo Client, Graphile Worker, Graphile Migrate, GraphQL Code Generator, Ant Design and Next.js
https://graphile-starter.herokuapp.com
Other
1.75k stars 220 forks source link

Username check fails with short first names. #226

Closed dts closed 3 years ago

dts commented 3 years ago

Summary

Usernames automatically generated from short first names, e.g "A B" cause an error, the check fails (i.e. it doesn't match '^[a-zA-Z]([a-zA-Z0-9][_]?)+$').

Steps to reproduce

Run a link_or_register_user with the name "A B".

Expected results

A username like "A_B", or at worst, "user1"

Actual results

Exception: new row for relation "users" violates check constraint "users_username_check"

Additional context

None seems relevant.

Possible Solution

Possible Chesterton's fence notwithstanding, the regexp for username checks could be changed from

^[a-zA-Z]([a-zA-Z0-9][_]?)+$

to

^[a-zA-Z]([a-zA-Z0-9_]?)+$

This has the unfortunate side effect of allowing multiple underscores in a row, but I don't think that's more important than allowing short first names.

benjie commented 3 years ago

The underscore should be at the front of the parens not at the end; I did not intend to allow trailing underscore, and I did intend to allow A_B. I.e. the regexp should be: '^[a-zA-Z]([_]?[a-zA-Z0-9])+$'