Giter Site home page Giter Site logo

Comments (4)

iLikeKoffee avatar iLikeKoffee commented on August 28, 2024

Added PR #48 for this issue.

from knock.

nsarno avatar nsarno commented on August 28, 2024

It should definitely be possible to achieve this by modifying the controller rather than relying on configuration. I'll have a look at merging your PR or coming with another solution whenever I can.

Thanks a lot for contributing and apologies for the late reply! 👍

from knock.

iLikeKoffee avatar iLikeKoffee commented on August 28, 2024

@nsarno No problem! Now, I achieve this customization by the entire Knock::AuthController to my project. It looks like this:

class AuthTokenController
  before_action :authenticate!

  def create
    user = find_user
    render json: {jwt: auth_token(user).token, user: user}, status: :created
  end

  # Private methods copied from Knock::AuthController.
  # This is is a workaround because those methods in Knock::AuthTokenController are private.
  # I hope this will be removed when my PR (https://github.com/nsarno/knock/pull/48) merged.

  private

  def authenticate!
    raise ActiveRecord::RecordNotFound unless user.authenticate(auth_params[:password])
  end

  def auth_token(user)
    Knock::AuthToken.new payload: {sub: user.id}
  end

  def find_user
    Knock.current_user_from_handle.call auth_params[Knock.handle_attr]
  end

  def auth_params
    params.require(:auth).permit Knock.handle_attr, :password
  end
end

It works, but It's not the most beautiful solution.
Instead, i want It look like this:

class AuthTokenController < Knock::AuthTokenController
  before_action :authenticate!

  def create
    user = find_user
    render json: {jwt: auth_token(user).token, user: user}, status: :created
  end
end

Thanks in advance!

from knock.

nsarno avatar nsarno commented on August 28, 2024

Closing this. Cf #48 and #72.

from knock.

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.