# authLink Setup?

**URL:** <https://community.apollographql.com/t/authlink-setup/7575>\
**Category:** Client SDKs\
**Tags:** client\
**Created:** [May 31, 2024, 2:12pm UTC](https://community.apollographql.com/t/authlink-setup/7575 "2024-05-31T14:12:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikr00001](https://avatars.discourse-cdn.com/v4/letter/v/f05b48/32.png) [@vikr00001](https://community.apollographql.com/u/vikr00001)\
**Post date:** [May 31, 2024, 2:12pm UTC](https://community.apollographql.com/t/authlink-setup/7575/1 "2024-05-31T14:12:28Z")

</div>

With this code:

```auto
let theWsLinkUrl = `wss://localhost:3000/graphql`
let appApiUrl = `http://localhost:3000/graphql`;
let errorLink = `http://localhost:3000/myPageThatShowsGraphQLerrors`;

const authLinkContext = setContext((_, { headers }) => {
    // return the headers to the context so httpLink can read them
    return {
        headers: {
            ...headers,
            authorization: token || "",
        },
    };
});

const authLink = ApolloLink.from([
    errorLink,
    authLinkContext.concat(httpAuthLink),
]);

```

…I’m getting an authLink that looks like this:

![Screenshot 2024-05-31 at 10.04.09 AM](https://us1.discourse-cdn.com/flex019/uploads/apollographql/optimized/2X/e/edb0f989254fa5626000d704dc9de11406cec2fb_2_345x21.png)

What am I missing?

---

<div class="post-metadata">

**Author:** ![JeffAuriemma](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/jeffauriemma/32/2845_2.png) [@JeffAuriemma](https://community.apollographql.com/u/JeffAuriemma)\
**Post date:** [May 31, 2024, 4:53pm UTC](https://community.apollographql.com/t/authlink-setup/7575/2 "2024-05-31T16:53:44Z")

</div>

Hi @vikr00001 👋 I recommend taking a closer look at our Apollo Link documentation overall:

> **[Apollo Link overview](https://www.apollographql.com/docs/react/api/link/introduction/#providing-to-apollo-client)**
>
> Customize Apollo Client's data flow

Your `errorLink` variable is a string, where it should be an instance of `ApolloLink`. Hope that helps point you in the right direction!

---

<div class="post-metadata">

**Author:** ![vikr00001](https://avatars.discourse-cdn.com/v4/letter/v/f05b48/32.png) [@vikr00001](https://community.apollographql.com/u/vikr00001)\
**Post date:** [June 1, 2024, 4:01pm UTC](https://community.apollographql.com/t/authlink-setup/7575/3 "2024-06-01T16:01:46Z")

</div>

> [@vikr00001](#):
>
> ```auto
> const authLink = ApolloLink.from([
> errorLink,
> authLinkContext.concat(httpAuthLink),
> ]);
> 
> ```

If I’m creating an authLink, is an errorLink required?

I’m planning to use it here:

```auto
export default new ApolloClient({
    link: ApolloLink.split(
        ({ query }) => {
            const definition = getMainDefinition(query);
            return (
                definition.kind === "OperationDefinition" &&
                definition.operation === "subscription"
            );
        },
        wsLink ? wsLink : appLink,
        ApolloLink.split(
            operation => operation.getContext().clientName === "auth",
            authLink, // <= apollo will send to this if clientName is "auth"
            appLink, // <= otherwise will send to this
        ),
    ),
    cache: new InMemoryCache({

    }),
});

```

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [June 3, 2024, 8:40am UTC](https://community.apollographql.com/t/authlink-setup/7575/4 "2024-06-03T08:40:13Z")

</div>

That `authLink` at this point is just a variable name that you assigned to it.

What you have is a link that adds an authorization header, but that’s all the functionality it has - there is no implicit or hidden logic added on top of that.

If you want to handle any kind of errors, you will probably need an `ErrorLink`.

But again, giving a variable a name doesn’t make something magical happen. You will need to actually use an `ErrorLink` instance, not just a variable with that name and a string as a content.

Variable names hold no meaning in JavaScript, and Apollo Client has no way of knowing what names you assign to variables. Apollo Client only see the values inside of the variables.  
The variable names are just there so you can read the code better, and choosing the names is up to you, but has no runtime consequence.
