No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to update auth token using app-extension-apollo each time a user log in?

    Help
    2
    3
    810
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Q
      QuaDgf last edited by

      Hello, I have a working demo using quasar, axios, and a rest api backend (jwt auth).

      Following @Hawkeye64 guidelines (https://forum.quasar-framework.org/topic/5100/how-can-i-pass-the-jwt-token-to-axios-get-request/7) it works well, axios instance are saved on vuex store, and when users log in an action calls a mutation. This mutation update axios instance header (token jwt). It checks when the token expires on router.beforeEach and axios request (401). When the token expires I redirect the user to the login screen (in the future I wish I could check the validation date of the token and renew the token before the expiration date).

      I have an api platform backend with graphQL and I would like to test it. I would like to update apolloClient object each time the user login similar as I am doing with the axios object:

        axiosInstance.defaults.headers.common.Authorization = 'Bearer <token>'
      

      But I don’t find how I could update the apolloClient object when users log in and update the token. Everybody creates a new apolloClient object:
      https://github.com/apollographql/apollo-client/issues/4990
      https://github.com/apollographql/apollo-client/issues/6212

      Maybe, I am missing an obvious method or simple change on apolloClient object for example on apolloClientAfterCreate function?

      Thank you very much

      1 Reply Last reply Reply Quote 0
      • Q
        QuaDgf last edited by QuaDgf

        I was obsessed with apolloClientAfterCreate. It was more simple using apolloClientBeforeCreate.

        Following:
        https://github.com/quasarframework/app-extension-apollo/issues/37#issuecomment-619650193
        https://github.com/quasarframework/app-extension-apollo/issues/67

        I configure a function getToken() on apolloClientBeforeCreate.

        Thank you

        1 Reply Last reply Reply Quote 1
        • G
          ghosteye1.wg last edited by

          Can you share the full implementation here. Plz

          1 Reply Last reply Reply Quote 0
          • First post
            Last post