Auth0 Home Blog Docs

How to use auth0 spa with TypeScript?

I’m implementing Auth0 in a React TypeScript site and am trying to get the https://auth0.com/docs/quickstart/spa/react to work.

Specifically, when the react-auth0-wrapper.js is converted to react-auth0-wrapper.tsx I get TS errors on the following lines.

const loginWithPopup = async () => {
const handleRedirectCallback = async () => {

An async function or method in ES5/ES3 requires the Promise constructor. Make sure you have a declaration for the Promise constructor or include ES2015 in your --lib option.

The lib option of tsconfig.json looks like this

"lib": [
  "dom",
  "dom.iterable",
  "esnext"
],

Any thoughts or insights appreciated.

Hi there @treasurer and welcome to the Auth0 Community!

I will dive into this, give it a build, and let you know what I find :+1: Thanks!

Hi @James.Morrison, any update on that front, I’d be interested to use the wrapper in typescript as well.

Thanks

Still investigating on this front, will share details as they emerge.

Also doing the same implementation so I want to follow up with you all here. I’ve gotten my react-auth0-spa.tsx to work but unsure if I’m doing things right.

My lib option of tsconfig.json looks exactly the same but I’m not getting the TS errors:

    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],

When would Auth0 create an official Typescript wrapper?

Any updates James? Still can’t get react-auth0-spa.js to compile in TypeScript. This is preventing us from using Auth0 in our SPA website even though we are an Auth0 customer.

Thanks
Chris

Hi,

Same here :wink:

Thanks

Hi folks,

We should have a blog post coming soon on react + typescript. I don’t have any dates, but hopefully it will provide some insight when it arrives. In the mean time, have you seen this thread on GitHub?

1 Like

There are some possibilities here. However, our site is 100% TypeScript and w/o TS support forAuth0 we can’t proceed. Authentication is critical and our development is pretty much on hold. Is there any way this can be expedited?

@treasurer,

Can you give us more insight on what you would like to see specifically? What is confusing, what part of the stack, what frameworks, etc. I am happy to share your feedback with the relevant parties if you describe your needs. I can’t guarantee any dates on when the content will be live, but I can certainly advocate for you.

Let me know.

Thanks,
Dan

Hi Dan

The problem is the react-auth0-spa.js sample in the React Starter code does not work in TypeScript. If I take the sample code and put it in a .ts file there are a number of TypeScript errors. I’ve tried several approaches to get it to work without success.

It would be really helpful is the React starter code included both JS and TypeScript samples. Without a TS sample we are unable to use Auth0 in our site despite being a customer. Whatever you can do to expedite this would be appreciated.

Thanks
Chris

1 Like

FYI I am maintaining an example on how to use auth0-spa-js with Typescript at https://github.com/tommedema/startup-boilerplate

More specifically you may be interested in https://github.com/tommedema/startup-boilerplate/blob/master/packages/react-app/src/lib/auth0.tsx

3 Likes

Hello, it is been some time since. Is there any date when we can expect auth0 react typescript?
Thank you, keep up the good work. :+1:
Frank

While I don’t have a ETA on the article being published, I can share with you that it’s a priority and we will share it here as soon as it’s released.

2 Likes