I have a rails app using devise, in the beggining it was just using rails. Now i am adding some react using the gem react-rails.. To make the story short i have an API controller like this
class Api::CustomersController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :authenticate_user!
def index
customers = Customer.all
render json: customers, status: :ok
end ....
and i want to access that info or test my API using POSTMAN.. Of course when i try the app just redirect me to the login page because of the "before_action:authenticate_user.".: Now the question is? Can i access to that API URL using postman? how?
Thanks in advance
This isn't related to devise
mainly.
You'll need to generate an auth_token
for each user
(and of course, create a db migration for it with uniqueness) and authenticate your user using Authorization
header.
Otherwise, you can check the devise
tokens solutions from here: https://github.com/plataformatec/devise/wiki/How-To:-Simple-Token-Authentication-Example
could you use any of these two gems are interesting to work with devise and a verification token
devise_token_auth documentation
devise-jwt documentation
Plain simple solution is to copy the browser session cookie (after logging in) into insomnia cookie. Look for cookie value in browser dev tools, it needs to be copied into insomnia cookie value for the same page.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.