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

How is it possible to update the client with a new JWT in headers? #126

Open
t-lock opened this issue Nov 17, 2022 · 1 comment
Open

How is it possible to update the client with a new JWT in headers? #126

t-lock opened this issue Nov 17, 2022 · 1 comment

Comments

@t-lock
Copy link

t-lock commented Nov 17, 2022

<script lang="ts">
  import { ApolloClient, InMemoryCache } from "@apollo/client";
  import { setClient } from "svelte-apollo";

  export let token: string = "";

  const cache = new InMemoryCache();

  const client = new ApolloClient({
    uri: import.meta.env.VITE_HASURA_GQL_URL,
    cache,
    headers: {
      Authorization: `Bearer ${token}`,
    },
  });
  setClient(client);
</script>

<slot />

Passing in an updated token via props does not cause a re-render. Since the whole basis of this library is passing the Client through Context, and Context only being able to be set during component initialization, I do not see how it is possible to update the Client after initialization, such as when a new token is provided through a refresh token operation.

Please advise.

@binaryme
Copy link

binaryme commented Feb 8, 2023

It should not re-render in order for your request to grab the most recent token.

every time you request a method post to your request URL (your graphql endpoint)
you will call it with the most recent token.

did you checked your network tab to verify your request includes your most recent token?

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