Giter VIP home page Giter VIP logo

Comments (8)

lynndylanhurley avatar lynndylanhurley commented on August 26, 2024

This gem comes with a generator that will install the necessary migrations. I would suggest running the generator and then removing any columns that already exist.

Can you elaborate on what you mean by "polymorphic"? I've seen that term used in several contexts when dealing with Rails models.

from devise_token_auth.

ianks avatar ianks commented on August 26, 2024

"With polymorphic associations, a model can belong to more than one other model, on a single association."

In my case, a user class is made which can be used across different models for different types of users. We have vendors, customers, etc. all of which share the common functionality of needing a user account.

from devise_token_auth.

lynndylanhurley avatar lynndylanhurley commented on August 26, 2024

Cool, I think everything should work ok. Please post an issue if you run into any trouble

from devise_token_auth.

lynndylanhurley avatar lynndylanhurley commented on August 26, 2024

@ianks - I'm closing this issue, but please re-open (or create another issue) if you run into any trouble.

from devise_token_auth.

aihaddad avatar aihaddad commented on August 26, 2024

Hi @lynndylanhurley and @ianks
I'm exactly in a similar situation here, and I don't know if I should open a separate issue. I've already gotten Devise to setup my polymorphic user model earlier, then added four role models. By changing to DeviseTokenAuth this morning I got many (RSpec) test errors/failures. The major one being: "PG::NotNullViolation: ERROR: null value in column "uid" violates not-null constraint" on 26 out of 34 failures. The others being validation failures on emails. I've managed to shut off the UID failure by doing:

before_save -> do
    self.uid = SecureRandom.uuid
    skip_confirmation!
end

on the user model as suggested by this airpair tutorial. But then, I saw issue #29 and figured, it should be a bad idea. My factories already include UID and provider is set to 'email' by default. Any ideas on how to fix this? and of course the validations part?

from devise_token_auth.

c0mrade avatar c0mrade commented on August 26, 2024

@lynndylanhurley @ianks @aihaddad why is this still closed it's still happening?

This is what I did :

  1. Created new rails project (rails 4.2.0)
  2. Added gems to my Gemfile 'devise_token_auth' and 'omniauth'
  3. bundle install
  4. rails g devise_token_auth:install
  5. rake db:migrate

I still get validation error when I save the user for Validation failed: Uid can't be blank.
As pointed out in #29 that it's a bad idea. What is the alternative to this solution?

before_save -> do
self.uid = SecureRandom.uuid
skip_confirmation!
end

from devise_token_auth.

lynndylanhurley avatar lynndylanhurley commented on August 26, 2024

@c0mrade - if you're using email authentication, the uid value should be identical to the user model's email value. The uid attribute will be set automatically if the provider attribute is set to email (which should be the case if you're using email authentication).

from devise_token_auth.

c0mrade avatar c0mrade commented on August 26, 2024

@lynndylanhurley

So you're saying that in my test factory (when I'm testing email authentication), both uid and provider should actually be the value of users' email?

And I should remove the part self.uid = SecureRandom.uuid from before_save callback on my model. Because it will be set by provider if I decide to use facebook/google.

Sorry if this is a dumb question, I'm new to all of this

from devise_token_auth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.