auth0 / auth0-react

Auth0 SDK for React Single Page Applications (SPA)
MIT License
887 stars 256 forks source link

CacheKey clientId field type does not match string | undefined #760

Closed malinskibeniamin closed 4 months ago

malinskibeniamin commented 5 months ago

Checklist

Description

When building any NextJS app, validity of types will fail when using @auth0/auth0-react package.

The package works fine in development, but the build will fail because of the clientId being

Reproduction

  1. Clone any NextJS 14 app router example
  2. Use @auth0/auth0-react
  3. Run npm run build
  4. Notice the error

Additional context

> next build

  ▲ Next.js 14.2.3
  - Environments: .env

   Creating an optimized production build ...
 ✓ Compiled successfully

   Linting and checking validity of types  ..Failed to compile.

./node_modules/@auth0/auth0-spa-js/src/cache/shared.ts:45:27
Type error: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

  43 |     const [prefix, clientId, audience, scope] = key.split('::');
  44 |
> 45 |     return new CacheKey({ clientId, scope, audience }, prefix);
     |                           ^
  46 |   }
  47 |
  48 |   /**

auth0-react version

2.2.4

React version

18.3.1

Which browsers have you tested in?

Chrome

nandan-bhat commented 4 months ago

Hello @malinskibeniamin, Could you provide additional details on the steps needed to reproduce this issue ?

I attempted to reproduce the issue using Next.js@14.2.3 (with App Router) and @auth0/auth0-react, but I wasn't able to encounter the problem you mentioned. Could you provide more details about how you initiated your Next.js project (whether you used npx, pnpm, or yarn) and the options you selected during the installation process?

malinskibeniamin commented 4 months ago

Hi @nandan-bhat,

Thanks for looking into it - it's been a while but from what I can remember, it could have been due to my older TypeScript version (before 5.0). Sorry for the inconvenience, I will close this issue and if I stumble across it again, I will reopen. Thank you!