-
Notifications
You must be signed in to change notification settings - Fork 218
Open
Description
I created a client that works correctly in Expo (web). It uses a pin-code flow compatible with SPA.
But it throws an error in IOS (error will follow).
/**
* OpenAuth client adapter for SPA applications
*/
import { createClient } from "@openauthjs/openauth/client";
const clientID = "my-auth-client";
// Create and configure the OpenAuth client
export const authClient = (issuer: string) =>
createClient({
clientID,
issuer,
});
// Export the types from OpenAuth for convenience
export type {
AuthorizeOptions,
ExchangeError,
ExchangeSuccess,
RefreshError,
RefreshSuccess,
} from "@openauthjs/openauth/client";
// SPA-compatible pin-code provider flow
export const pinCodeClient = {
/**
* Request a pin code for the given email
*/
async requestCode(issuer: string, email: string): Promise<any> {
const response = await fetch(`${issuer}/pin-code/request`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email }),
});
if (!response.ok) {
const data = await response.json() as { error?: string };
throw new Error(data.error || "Failed to request verification code");
}
return response.json();
},
/**
* Verify a pin code for the given email
*/
async verifyCode(
issuer: string,
email: string,
code: string,
redirectUri: string,
challenge: any
): Promise<any> {
const response = await fetch(`${issuer}/pin-code/verify`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email,
code,
redirect_uri: redirectUri,
client_id: clientID,
state: challenge.state,
response_type: "code",
code_challenge: challenge.challenge,
code_challenge_method: challenge.method,
}),
});
if (!response.ok) {
const data = await response.json() as { error?: string };
throw new Error(data.error || "Invalid verification code");
}
return response.json();
},
};Getting the following error on IOS. It seems to be importing a server node module in client code.
"@openauthjs/openauth": "^0.4.3"
Unable to resolve module node:buffer from /Users/gablabelle/Developer/personal/ephemerald-monorepo/node_modules/@openauthjs/openauth/node_modules/jose/dist/node/esm/runtime/base64url.js: node:buffer could not be found within the project or in these directories:
../../node_modules/@openauthjs/openauth/node_modules
../../node_modules
node_modules
../../node_modules
> 1 | import { Buffer } from 'node:buffer';
| ^
2 | import { decoder } from '../lib/buffer_utils.js';
3 | function normalize(input) {
4 | let encoded = input;

Metadata
Metadata
Assignees
Labels
No labels