#why getUserName return email ?

1 messages · Page 1 of 1 (latest)

trim abyss
#

I use interface UserDetails in java and when i implement method getUserName its return email. Is that correct ?

brave sluiceBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

The getUserName() method in the UserDetails interface does not necessarily return the email. The purpose of this method is to return the username associated with the user account.

However, in some implementations of the UserDetails interface, such as User class provided by Spring Security, the username is often set to be an email address. This is a common practice since email addresses are unique and can serve as a good identifier for user accounts.

So, if you are using a specific implementation of the UserDetails interface that sets the username to be an email address, then it is correct for the getUserName() method to return the email. But keep in mind that this behavior may vary depending on how you have implemented or configured your user details object.

quasi brook
wintry flame
#

you should know yourself lol

#

but based of the name it shouldnt return email

quasi brook
#

^^^ however in some apps the username is the same as the email

#

but you should know that yourself

trim abyss
trim abyss
trim abyss
wintry flame
trim abyss
wintry flame
#

A method returning the email should be called like getEmail though

trim abyss
quasi brook
# trim abyss

As Squid said, in code it's better to have a method return exactly what it says

#

If you don't have a separate username value, and your application is supposed to use the user's email as their username this may be valid.

#

But only in case you really can't rename that method to getEmail

spiral shore
trim abyss
trim abyss
brave sluiceBOT
trim abyss
spiral shore
#

You'll also have to also take into consideration when registering a user that the username must be unique for each user to be able to load the user on login later on, same concept applies to email.