Skip to content

Commit 5f57245

Browse files
committed
feat(react-native): added e2e example and ready-to-use component
1 parent b3afa16 commit 5f57245

File tree

96 files changed

+25365
-894
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+25365
-894
lines changed

client/config.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,28 @@ export interface Config {
8585
* Overriding history implementation. Default: globalThis.history
8686
*/
8787
history?: MinimalHistory;
88+
/**
89+
* Overriding URL implementation. Default: globalThis.URL
90+
*/
91+
URL?: MinimalURL;
92+
/**
93+
* Overriding TextDecoder implementation. Default: globalThis.TextDecoder
94+
*/
95+
TextDecoder?: MinimalTextDecoder;
8896
}
8997

9098
export type ConfigWithDefaults = Config &
9199
Required<
92-
Pick<Config, "storage" | "crypto" | "fetch" | "location" | "history">
100+
Pick<
101+
Config,
102+
| "storage"
103+
| "crypto"
104+
| "fetch"
105+
| "location"
106+
| "history"
107+
| "URL"
108+
| "TextDecoder"
109+
>
93110
>;
94111

95112
let config_: ConfigWithDefaults | undefined = undefined;
@@ -102,6 +119,8 @@ export function configure(config?: Config) {
102119
fetch: config.fetch ?? Defaults.fetch,
103120
location: config.location ?? Defaults.location,
104121
history: config.history ?? Defaults.history,
122+
URL: config.URL ?? Defaults.URL,
123+
TextDecoder: config.TextDecoder ?? Defaults.TextDecoder,
105124
};
106125
config_.debug?.("Configuration loaded:", config);
107126
} else {
@@ -227,6 +246,15 @@ class Defaults {
227246
if (typeof globalThis.history !== "undefined") return globalThis.history;
228247
return Defaults.getFailingProxy("history") as MinimalHistory;
229248
}
249+
static get URL(): MinimalURL {
250+
if (typeof globalThis.URL !== "undefined") return globalThis.URL;
251+
return Defaults.getFailingProxy("URL") as MinimalURL;
252+
}
253+
static get TextDecoder(): MinimalTextDecoder {
254+
if (typeof globalThis.TextDecoder !== "undefined")
255+
return globalThis.TextDecoder;
256+
return Defaults.getFailingProxy("TextDecoder") as MinimalTextDecoder;
257+
}
230258
}
231259

232260
export interface MinimalResponse {
@@ -263,3 +291,15 @@ export interface MinimalCrypto {
263291
sign: Crypto["subtle"]["sign"];
264292
};
265293
}
294+
295+
export interface MinimalURL {
296+
new (url: string): {
297+
href: string;
298+
hash: string;
299+
};
300+
}
301+
export interface MinimalTextDecoder {
302+
new (): {
303+
decode(buffer: Uint8Array): string;
304+
};
305+
}

client/fido2.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export async function fido2UpdateCredential({
314314
}).then(throwIfNot2xx);
315315
}
316316

317-
interface Fido2Options {
317+
export interface Fido2Options {
318318
challenge: string;
319319
timeout?: number;
320320
userVerification?: UserVerificationRequirement;
@@ -351,7 +351,7 @@ function assertIsFido2Options(o: unknown): asserts o is Fido2Options {
351351
}
352352
}
353353

354-
async function fido2getCredential({
354+
export async function fido2getCredential({
355355
relyingPartyId,
356356
challenge,
357357
credentials,
@@ -484,7 +484,7 @@ export function authenticateWithFido2({
484484
}
485485
const abort = new AbortController();
486486
const signedIn = (async () => {
487-
const { debug, fido2 } = configure();
487+
const { debug, fido2, TextDecoder } = configure();
488488
if (!fido2) {
489489
throw new Error("Missing Fido2 config");
490490
}

client/magic-link.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ export const requestSignInLink = ({
101101

102102
const failedFragmentIdentifieres = new Set<string>();
103103
function checkCurrentLocationForSignInLink() {
104-
const { debug, location } = configure();
104+
const { debug, location, URL } = configure();
105105
let url: URL;
106106
let fragmentIdentifier: string;
107107
try {
108-
url = new URL(location.href);
108+
url = new URL(location.href) as URL;
109109
fragmentIdentifier = url.hash?.slice(1);
110110
if (!fragmentIdentifier) {
111111
debug?.(

0 commit comments

Comments
 (0)