dbAuth with username or email

Hi everybody,

is there a way to add the ability to log in with email as well as username, using the dbAuth authentication method? Or should I create a new provider by forking the existing one?

Thanks,
Fabio.

Hello! “Username” is just what we call that field in the internals of dbAuth, because it doesn’t have to be an email, it can be anything. But most people will probably use email. In fact in the config that’s generated (src/lib/auth.js) it assumes you’re using an email, and maps the internal username field to a field called email in your database.

The only thing that’s “hardcoded” as Username are the labels in the login and signup pages, but you can change those easily enough!

We’ve got an outstanding PR that’ll let you change those labels at the time you setup dbAuth: Label override flags for dbAuth generator by Josh-Walker-GM · Pull Request #6440 · redwoodjs/redwood · GitHub

I got this, and it’s fine.

my doubt was another one, I think I didn’t explain myself well: I was wondering if it was possible for a user to log in with both username-password and email-password. As it is implemented now, I understand that it cannot be done and that you can only choose a configuration (i.e. username-password OR email-password)

Fabio.

If you don’t have any constraints what data the username column contains in the database, you could store both “usernames” and “emails” in the same column, but it’s really just a big string.

But the way dbAuth currently works, you couldn’t have two separate database fields, like a separate username and email column, and try each of them in turn, no.

1 Like