1. 13
    Set Dynamic Auth Header for Apollo Client using Next.js getServerSideProps
    3m 3s

Set Dynamic Auth Header for Apollo Client using Next.js getServerSideProps

InstructorShadid Haque

Share this video with your friends

Send Tweet

To make an authenticated request, we will need to get logged in users auth tokens from Auth0. Auth0 exposes a getAccessToken function that we can use in Next.js getServerSideProps to fetch the user token. It's important to note that this function can only be used server side. We'll pass that token into the page we need to send authed requests.

To enable Apollo Client to set the headers we'll extend the client so that allows us to pass in auth tokens and sets the client context. We will then destructure the client from our useMutation hook and set the context to include the user token.

~ 2 years ago

Hello, amazing course so far, my auth token is being appeneded to my request but I'm getting "Error: Invalid database secret."

Shadid Haqueinstructor
~ 2 years ago

Hey would you be able to share your code. I can take a look.

~ 2 years ago

I solved it, I had copied and pasted the default AUTH0 set up without generating the AUTH0_SECRET.

Eduardo Orozco
~ 2 years ago

I am having the same problem, I have already generated the AUTH0_SECRET in the .env.local now what? I am stuck here

Eduardo Orozco
~ 2 years ago

Solved with help of instructor.

Eduardo Orozco
~ 2 years ago

It was my mistake

Tikal Knowledge
~ 2 years ago

I have the same problem of "Error: Invalid database secret." how to solve it?

Shadid Haqueinstructor
~ 2 years ago

Can you share your code please. I can help you debug this.