Rtk Query and auth0


I’m trying to integrate auth0 in a react+typescript project using auth0-react. So far so good I’m able to login and logout.

However I’m a bit blocked on how to add the auth0 bearer token to the API requests using rtk query.

Digging a bit on it I found this issue: Provide access to the underlying `auth0-spa-js` methods · Issue #266 · auth0/auth0-react · GitHub
That lead me to this gist: auth0-react-gettoken.md · GitHub

All the information is for the Apollo client so I was wondering if anybody on the forum has any experience making rtk-query and auth0 working with auth0-react or point me to some resource/example that helps me getting this to work.

Hi @dln,

Welcome to the Auth0 Community!

You should add the token as a header to the request. Like this

Authorization: Bearer <token>

I am not familiar with rtk-query, but they provide an example of adding a bearer token here:

Hope that helps!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.