Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expo] Unable to resolve "@openauthjs/openauth/client" #113

Open
fredericrous opened this issue Dec 27, 2024 · 4 comments
Open

[expo] Unable to resolve "@openauthjs/openauth/client" #113

fredericrous opened this issue Dec 27, 2024 · 4 comments

Comments

@fredericrous
Copy link

fredericrous commented Dec 27, 2024

reproduction workflow

  1. create an expo app
npx create-expo-app@latest

for info, the tsconfig of the expo app will be https://github.com/expo/expo/blob/main/packages/expo/tsconfig.base.json

  1. now import createClient like documented at https://github.com/openauthjs/openauth?tab=readme-ov-file#auth-client
import { createClient } from "@openauthjs/openauth/client"

You will get the error

Cannot find module '@openauthjs/openauth/client' or its corresponding type declarations.
  There are types at 'node_modules/@openauthjs/openauth/dist/types/client.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.
  1. I update the tsconfig.json of the project accordingly
{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
     "moduleResolution": "bundler",
   ...
   }
}

The type error disappear, but now I get an error at build time

iOS Bundling failed 4901ms node_modules/.pnpm/[email protected]_3gehy7dkrrruk2u5bv74pkqgha/node_modules/expo-router/entry.js (1285 modules)
Unable to resolve "@openauthjs/openauth/client" from "app/(tabs)/index.tsx"
@fredericrous fredericrous changed the title Cannot find module '@openauthjs/openauth/client' or its corresponding type declarations [expo] Unable to resolve "@openauthjs/openauth/client" Dec 27, 2024
@fredericrous
Copy link
Author

apparently I'm not the only one. a user found a workaround, which is to copy the client in a local context, along with the files it depends on:

  • session
  • utils
  • error
  • pkce

https://gist.github.com/xinha-sh/723fae6bad78a303bbaeeb2b41634c76

@vitostamatti
Copy link

any improvements on this?? i dont like the copy/paste approach

@fredericrous
Copy link
Author

fredericrous commented Jan 5, 2025

Forking the client is an approach hard to maintain.
I do not know how to fix this error so I tried another approach, which is to ditch OpenAUTH client and use instead Expo AuthSession. However, Expo AuthSession does not work with OpenAUTH server as is. I first noticed that when calling AuthSession.fetchDiscoveryAsync(issuer), the url called was hardcoded to .well-known/openid-configuration and OpenAUTH uses .well-known/oauth-authorization-server. I then came across another issue when fetching this same address (json decoding error). I finally gave up and forked OpenAUTH client for now

@vitostamatti
Copy link

i managed to make it work using AuthSession by manually providing the urls for discovery .

const discovery = {
    authorizationEndpoint: "your.auth.domain/authorize",
    tokenEndpoint: "your.auth.domain/token"
}
const [ request, response, promptAsync] = useAuthRequest(
    {
        clientId:"your-mobile-app",
        redirectUri: makeRedirectUri() // from expo-auth-session
    },
    discovery
) 

Have you try this option on metrobundler ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants