'Login with devise-jwt authentication?

I cannot figure out how to send a post request to login on devise with devise-jwt

I use devise as web authentication, but want to add an endpoint for api authentication

This is my route

  namespace :api do
    namespace :v1 do
      devise_for :users,
                 path: '',
                 path_names: {
                   sign_in: 'login',
                   sign_out: 'logout'
                 },
                 controllers: {
                   sessions: 'api/v1/sessions'
                 }
    end
  end

This is my controller:

module Api
  module V1
    class SessionsController < Devise::SessionsController
      respond_to :json

      private

      def respond_with(resource, _opts = {})
        render json: resource
      end

      def respond_to_on_destroy
        head :ok
      end
    end
  end
end

If I use postman and post to http://localhost:3000/api/v1/login

this Body/raw/JSON formatted data { "email": "[email protected]", "password": "0123456789" }

But I get a 422 Unprocessable Entity :/

Does anyone know how we are supposed to format this?



Solution 1:[1]

It's probably because of the authenticity_token. Just skip verifying it in your controller

skip_before_action :verify_authenticity_token

Check this for more information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AbdUlRahman Shawareb