#Auth with username or email

3 messages · Page 1 of 1 (latest)

pulsar glacier
#
public function username(): string
    {
        $login = request()->input('login');
        return filter_var($login, FILTER_VALIDATE_EMAIL) ? 'name' : 'email';
    }```

with this users can login with only email but if I switch places `'email' : 'name'` then user will be able to login with username
how to make it login with both?

Well I can make if statemnt to check if it contains `@` and fix it but is there a better way?
next harbor
#

As it is currently structured it returns the name field even if their login is an email.

The syntax of the return statement can be expressed as

if ( $login is an email address ) return 'name' otherwise return 'email'

So right now your conditions are backwards

#

and technically filter_var isn't the best way to determine if it's a legitimate email, it may not return correctly for 100% of emails, just something that looks like an email