Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authenticate_and_set_user without restricting access #38

Closed
xxSkyy opened this issue Jan 15, 2021 · 2 comments
Closed

authenticate_and_set_user without restricting access #38

xxSkyy opened this issue Jan 15, 2021 · 2 comments

Comments

@xxSkyy
Copy link

xxSkyy commented Jan 15, 2021

I'm using with my projects GraphQL, recently implemented your api_guard. Honestly its pretty good but I dont see option to like authenticate user but despite that user is logged allow to pass through just leaving current user nil.
It's needed to me as all graphql requests passes through one controller that passes user info to all queries. When I'm logged in all works well but in other way it dont stopping on unauthorized error on all queries.

@Gokul595
Copy link
Owner

@xxSkyy You can add a condition for authenticate_and_set_user before action to skip for unauthenticated controller actions. I think this should be a good way to handle your case.

Let me know if you have any difficulties in doing this.

@xxSkyy
Copy link
Author

xxSkyy commented Jan 15, 2021

I know but that's not the case. Like - all queries passing execute method in graphQL controller so I can't add condition to it as there's one method for all.

I fixed it myself by doing simple method for before action, I need to improve query but for now need some sleep

  def jwt_auth 
    @token = request.headers['Authorization']&.split('Bearer ')&.last
    @user = nil

    if @token
    begin
      user = decode_token
      @user = User.find(user["user_id"])
    rescue Exception => e
      raise Exception, "JWT Token is not valid or user don't exist"
    end  
    end
  end 

It'd be nice to see sth like it implemented 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants