HELP!
I recently added API functionality for User registration and login via API and devise-jwt. When I pushed this onto my heroku production environment now, it suddenly throws a new error when somebody tries to sign up.
NoMethodError (undefined method `jti' for #<User:0x00007f59d0453ab8>):
app/models/user.rb:33:in `add_jti'
Signing up locally on my development environment works without any problems. Here are other key points:
- logging in works fine for already created users
- Already existing users also have the "jti" attribute and it can be called as a method
- It is possible to create users via terminal commands on the production environement, here it basically does the same thing as in normal registration but for some reason has no problem calling this "jti" method.
- The versions of the gems seems to be the same in both variables.
- debugging in the method that causes the problem shows no problem in development environment
Here is the code for the User model, where the bug is caused...
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable, :trackable
validates :email, uniqueness: true
validates :username, uniqueness: true, format: { without: /\s/ }
has_many :ratings, dependent: :destroy
has_many :reports, dependent: :destroy
has_many :posts, dependent: :destroy
acts_as_voter
before_create :add_jti
def add_jti
self.jti ||= SecureRandom.uuid
end
end
There is also a model for "Api-User", which makes use of the jwt strategies any everything
class ApiUser < User
include Devise::JWT::RevocationStrategies::JTIMatcher
devise :jwt_authenticatable, jwt_revocation_strategy: self
validates :jti, presence: true
def generate_jwt
JWT.encode({ id: id,
exp: 5.days.from_now.to_i },
Rails.env.devise.jwt.secret_key)
end
end
Thanks for any help!
CodePudding user response:
are you sure your migrations ran on heroku? Doesn't happen automatically on deploy unless you automate that.
CodePudding user response:
ALRIGHT I somehow fixed it myself my accident right now, for anybody in the future experiencing something similar to this, just repeat git push heroku master
, that somehow solved the problem.
Thanks anybody for suggestions tho ^^.