Skip to content

Commit

Permalink
Merge pull request #818 from kevinhughes27/fix-graphiql
Browse files Browse the repository at this point in the history
fix graphiql for jwt auth
  • Loading branch information
kevinhughes27 authored Jul 27, 2018
2 parents c4a1bdc + d1f527c commit af28794
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AdminController < ApplicationController

before_action :authenticate_user!
before_action :authenticate_tournament_user!
before_action :set_jwt_cookie

rescue_from(ActiveRecord::RecordNotFound, with: :render_admin_404)

Expand All @@ -18,6 +19,15 @@ def authenticate_tournament_user!
end
end

def set_jwt_cookie
token = Knock::AuthToken.new(payload: { sub: current_user.id }).token

cookies['jwt'] = {
value: token,
domain: :all
}
end

def execute_graphql(mutation, input_type, input, output)
query_string = "mutation #{mutation}($input: #{input_type}!) {#{mutation}(input: $input) #{output}}"
query_variables = {"input" => input.deep_transform_keys { |key| key.to_s.camelize(:lower) }}
Expand Down
1 change: 1 addition & 0 deletions config/initializers/graphiql.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GraphiQL::Rails.config.headers['Authorization'] = -> (context) { "bearer #{context.cookies['jwt']}" }

0 comments on commit af28794

Please sign in to comment.