janko / rodauth-omniauth

OmniAuth login and registration for Rodauth authentication framework
MIT License
48 stars 3 forks source link

"identities" association not found #10

Closed Dainii closed 1 year ago

Dainii commented 1 year ago

Hello,

With my current project, the identities association does not work, but the rest of the authentication works like a charm, and the entry in the account_identities table is present.

Version info:

Account model

# frozen_string_literal: true

class Account < ApplicationRecord
  include Rodauth::Rails.model

  enum :status, unverified: 1, verified: 2, closed: 3
end

When I try to access the identities through Account.first.identities, I got

/home/user/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.2/lib/active_model/attribute_methods.rb:458:in `method_missing': undefined method `identities' for #<Account id: 5, status: "verified", email: "user@email.com", password_hash: nil> (NoMethodError)"

I put a debug string after this line to be sure that if defined?(Rodauth::Model) is true and that's the case.

Other association like verification_key works fine.

janko commented 1 year ago

Hello, thanks for reporting. I'm trying to find a scenario in which the association would not be defined, but I'm not coming up with anything concrete. Any chance you could reproduce it in a fresh Rails app that you can share?

Dainii commented 1 year ago

Hello, thank you for the answer.

I created a rails app here. You just need to copy the /.env.exampe to /.env and set the discord client id and secret to test.

With this setup, I am able to login through discord, the account is created, the account_identities entry too, but i'm still not able to call the .identities relation.

janko commented 1 year ago

There was a mistake in the association registration, so it never worked 🙈 In the rodauth-demo-rails app it only worked because there was a leftover has_many :identities association defined from when the OmniAuth integration was implemented manually. I fixed it now and released a new version.

Dainii commented 1 year ago

Hello @janko Thank you for this ;)