GithubHelp home page GithubHelp logo

Comments (6)

ankane avatar ankane commented on July 20, 2024 1

Just added the ability to do ahoy.configure({headers: ...}) on master.

from ahoy.js.

krsyoung avatar krsyoung commented on July 20, 2024

Hey @Startouf, I'm facing the same problem due to JWT. I'm using jwt_sessions as my authentication framework which authentications via a Authorization header.

I ended up forking ajoy.js and implementing support for headers as an additional configuration parameter. You can take a look here under the issue_23 branch: https://github.com/krsyoung/ahoy.js/tree/issue_23

It is pretty bad at the moment but works. In my frontend Vue code I just make a call to set the header once the user has authenticated:

// this.$ahoy is my ahoy instance
this.$ahoy.setHeader('Authorization', 'Bearer: ' + accessToken)

My situation is even more complicated as I need to decode the token on the backend before I can access the current user. I solved this by creating a custom user method for ahoy (called ahoy_user) that manually performs the decode and then returns the user.

What did you end up doing? Could my branch work for you?

from ahoy.js.

Startouf avatar Startouf commented on July 20, 2024

I'm reading the JWT token + user ID from custom headers named X-user-Token and X-user-email so I'm not sure your branch would work if you are just reading from Authorization

I am using the simple_token_authentication gem

from ahoy.js.

krsyoung avatar krsyoung commented on July 20, 2024

Ah, the change I made in my branch is really just to allow ahoy.js to support any arbitrary headers. I think in your case it would be as simple as:

// set customer HTTP headers for ahoy
ahoy.setHeader('X-user-token', 'xxx')
ahoy.setHeader('X-user-email', 'xxx')

I also ate a lot of turkey over the past couple of days so I can't really say I'm 100% confident!

from ahoy.js.

golmansax avatar golmansax commented on July 20, 2024

@krsyoung I started using your branch and it works great. One thing is I needed to set useBeacon to false to get the headers to send when tracking events.

Since it seems like there's sufficient interest in this feature, can we submit a pull for this?

from ahoy.js.

krsyoung avatar krsyoung commented on July 20, 2024

I'm game if @ankane is supportive.

Good call on the useBeacon @golmansax!

from ahoy.js.

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.