Search code examples
ruby-on-railsruby-on-rails-3deviseomniauth

generate unique username (omniauth + devise)


I have an app with user authentication with devise + omniauth.

In my model that username in my app is unique. I dont want duplicate username in my app.

Some users in facebook has not a defined username in his profile.

I want generate an unique username if the user has not username defined in facebook.

For example for generate password I have this:

:password => Devise.friendly_token[0,20]

How can I generate a unique username for my app if the facebook user has not username in facebook?

Thank you


Solution

  • You can take a part of email before the @ sign and add there smth like user_id, or just take the email itself. Or you can combine somehow the first and last names from the fb response.