waiting-for-dev/devise-jwt

Dispatch request not sending me token when i login from api

adnanmirza1 opened this issue · 18 comments

When i login with simple login, I'm receiving the token but i have made another login for API
when i login through it, i'm able to login but i'm not receiving jwt token with it.
In my dispatch request in devise config, i have added the path as well. still i'm not receiving the token.
Here's the screenshot of devise config:
image

And here's the screenshot of my routes for user

image

No need to give a full start and end URL for the dispatch request. Just try with below code and you are good to go.

jwt.dispatch_requests = [
    ['POST', /sign_in/]
]

I tried it but still i'm not receiving the token

And also make sure to have following code inside your user model.

devise(
    :jwt_authenticatable,
    :database_authenticatable,
    jwt_revocation_strategy: self
)

devise(
:jwt_authenticatable,
:database_authenticatable,
jwt_revocation_strategy: JwtDenyList
)

Instead of self i have JwtDenyList

That's fine. It should work. For me, I didn't have any relations for deny_list so using the same user table.

I tried both none is working

Hi @adnanmirza1 , I need the debugging information that is requested on the bug report template to be able to help you.

These are my routes:

image

i think problem is here somewhere
it's giving me proper response with token in my
users/sign_in
but not giving it to me in
api/v1/users/sign_in

Change to the below code to see if it works. As far as I am concerned the route is supposed to be like the following one. I am afraid that your API routes look sneaky. Please try the following code and let me know if it helps.

scope 'api/v1' do
  devise_for(
    :users,
    controllers: {
      sessions: 'api/v1/users/sessions',
    },
    defaults: { format: :json }
  )
end

Adding routes like that gives me following error:
image

Ah yes. You have already defined devise_for. We cannot define twice. What you can do is, now you have to use as keyword like below.

scope 'api/v1' do
    devise_scope :user do
        get 'users/sign_in' => 'sessions#new', as: :new_user_session
        post 'users/sign_in' => 'sessions#create', as: :user_session
        delete 'users/sign_out' => 'sessions#destroy', as: :destroy_user_session
    end
end

It still gives me this error that new_user_session is already in used
image

@waiting-for-dev what else do you need from my side to help me?

Please share your route file.

These are my complete routes related to this:
image

I have also similar application as yours. It's working fine. Check the attachment.
Screen Shot 2021-06-11 at 3 14 00 PM

Just copied your routes and pasted in mine and now it's working.
Thank You so much for all the help. <3