This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("when user inputs more characters ", () => { | |
const { getByLabelText, getByText } = render(<Component />); | |
const input = getByLabelText("label", { selector: "input" }); | |
beforeEach(() => { | |
fireEvent.change(input, { target: { value: "new value" } }); | |
}); | |
it("displays suggestions", () => { | |
expect(getByText("new value")).toBeInTheDocument(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe 'POST /signup', type: :request do | |
let(:url) { '/signup' } | |
let(:params) do | |
{ | |
user: { | |
email: '[email protected]', | |
password: 'password' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe 'POST /login', type: :request do | |
let(:user) { Fabricate(:user) } | |
let(:url) { '/login' } | |
let(:params) do | |
{ | |
user: { | |
email: user.email, | |
password: user.password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::API | |
def render_resource(resource) | |
if resource.errors.empty? | |
render json: resource | |
else | |
validation_error(resource) | |
end | |
end | |
def validation_error(resource) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RegistrationsController < Devise::RegistrationsController | |
respond_to :json | |
def create | |
build_resource(sign_up_params) | |
resource.save | |
render_resource(resource) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devise_for :users, | |
path: '', | |
path_names: { | |
sign_in: 'login', | |
sign_out: 'logout', | |
registration: 'signup' | |
}, | |
controllers: { | |
sessions: 'sessions', | |
registrations: 'registrations' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < Devise::SessionsController | |
respond_to :json | |
private | |
def respond_with(resource, _opts = {}) | |
render json: resource | |
end | |
def respond_to_on_destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JWTBlacklist < ApplicationRecord | |
include Devise::JWT::RevocationStrategies::Blacklist | |
self.table_name = 'jwt_blacklist' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateJwtBlacklist < ActiveRecord::Migration[5.0] | |
def change | |
create_table :jwt_blacklist do |t| | |
t.string :jti, null: false | |
end | |
add_index :jwt_blacklist, :jti | |
end | |
end |
NewerOlder