Rails 5 JWT for authentication pattern - proudcloud/awesome GitHub Wiki

Add JWT & bcrypt gems

gem 'jwt'
gem 'bcrypt'

Generate User model

$ rails g model User email:string password_digest:string

spec/models/user_spec.rb

require 'rails_helper'

# Test suite for User model
RSpec.describe User, type: :model do
  it { should validate_presence_of(:email) }
  it { should validate_presence_of(:password_digest) }
end

spec/factories/users.rb

FactoryGirl.define do
  factory :user do
    email '[email protected]'
    password 'foobar'
  end
end

Add bcrypt stuff into app/models/users.rb

class User
  ...
  include ActiveModel::SecurePassword

  has_secure_password
  ...
end