Reputation: 755
Im trying to add the devise-jwt to an existent app I have. Im adding API endpoints now, and want to use the same Model I have already
I added the gem devise-jwt following this article here: https://medium.com/@mazik.wyry/rails-5-api-jwt-setup-in-minutes-using-devise-71670fd4ed03
I had configured my devise.rb file with:
config.jwt do |jwt|
jwt.secret = ENV['DEVISE_JWT_SECRET_KEY']
jwt.dispatch_requests = [
['POST', %r{^/login$}]
]
jwt.revocation_requests = [
['DELETE', %r{^/logout$}]
]
jwt.expiration_time = 1.day.to_i
end
Had created my jwt_blacklist.rb and migrations for it:
class CreateJwtBlacklist < ActiveRecord::Migration[6.0]
def change
create_table :jwt_blacklist do |t|
t.string :jti, null: false
end
add_index :jwt_blacklist, :jti
end
end
class JWTBlacklist < ApplicationRecord
include Devise::JWT::RevocationStrategies::Blacklist
self.table_name = 'jwt_blacklist'
end
When I try to add those lines to my user.rb
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, omniauth_providers: [:facebook],
:jwt_authenticatable,
jwt_revocation_strategy: JWTBlacklist
And when I try to start my server im getting:
/Users/fmaymone/.rvm/gems/ruby-2.6.3/gems/activesupport-
6.0.0/lib/active_support/dependencies.rb:511:in `load': /booksculp/app/models/user.rb:6:
syntax error, unexpected ',', expecting => (SyntaxError)
:jwt_authenticatable ,
Someone knows what Im doing wrong here?
thanks
Upvotes: 2
Views: 651
Reputation: 314
Change your User
model to the following:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable,
:jwt_authenticatable, jwt_revocation_strategy: JWTBlacklist, omniauth_providers: [:facebook]
Upvotes: 2