Giter VIP home page Giter VIP logo

Comments (6)

bricesanchez avatar bricesanchez commented on August 17, 2024 2

Hi @codingwaysarg and @abdul-shajin,

I use devise_auth_token with this snippet of code. I can connect to the user by passing the email of User model as param, it's not suitable for production mode.

from graphiql-rails.

codingwaysarg avatar codingwaysarg commented on August 17, 2024 1

Hi there!

Could you give me more details about your implementation? I'm trying to do the same thing so I can always get my user automatically authenticated while testing graphiql.

Thank you!

from graphiql-rails.

bricesanchez avatar bricesanchez commented on August 17, 2024

my solution for now is to add a decorator on the GraphiQL::Rails::EditorsController :

# app/decorators/controllers/graphiql/rails/editors_controller_decorator.rb
module GraphiQLRailsEditorsControllerDecorator

  def self.prepended(base)
    base.prepend_before_action :authenticate, if: -> { !Rails.env.development? }
    base.prepend_before_action :set_auth_headers, only: :show
  end

  protected

  def authenticate
    http_basic_authenticate_with name: ENV["HBA_LOGIN"], password: ENV["HBA_PASSWORD"]
  end

  def set_auth_headers
    user = User.find_by_email(params[:email])

    if user.present?
       user_auth_token = user.create_new_auth_token

       GraphiQL::Rails.config.headers['access-token'] = -> (context) { user_auth_token['access-token'] }
       GraphiQL::Rails.config.headers['token-type'] = -> (context) { user_auth_token['token-type'] }
       GraphiQL::Rails.config.headers['client'] = -> (context) { user_auth_token['client'] }
       GraphiQL::Rails.config.headers['expiry'] = -> (context) { user_auth_token['expiry'] }
       GraphiQL::Rails.config.headers['uid'] = -> (context) { user_auth_token['uid'] }
    end
  end
end

GraphiQL::Rails::EditorsController.send :prepend, GraphiQLRailsEditorsControllerDecorator

from graphiql-rails.

abdul-shajin avatar abdul-shajin commented on August 17, 2024

Could you give more info like an example or something?

from graphiql-rails.

basicBrogrammer avatar basicBrogrammer commented on August 17, 2024

Is this ever going to be merged in or do we fork?

from graphiql-rails.

andredantasrocha avatar andredantasrocha commented on August 17, 2024

Hi @bricesanchez,

It is an old post but I think this will be a solution for me as well. I am not sure how to use this module with Rails 6 and graphiql-rails 1.7 though...

I tried to put in app/decorators/controllers/graphiql/rails/editors_controller_decorator.rb but it wasn't pick up by Rails.

Then added it under initializers. In this case it was picked up but nothing happens. The GraphiQL::Rails::EditorsController remained unaffected 🤔

Any help is welcome 😄

Thank you!

from graphiql-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.