Skip to content

Commit

Permalink
feat(react-native): added e2e example and ready-to-use component
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBorland committed Oct 17, 2023
1 parent b3afa16 commit 5f57245
Show file tree
Hide file tree
Showing 96 changed files with 25,365 additions and 894 deletions.
42 changes: 41 additions & 1 deletion client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,28 @@ export interface Config {
* Overriding history implementation. Default: globalThis.history
*/
history?: MinimalHistory;
/**
* Overriding URL implementation. Default: globalThis.URL
*/
URL?: MinimalURL;
/**
* Overriding TextDecoder implementation. Default: globalThis.TextDecoder
*/
TextDecoder?: MinimalTextDecoder;
}

export type ConfigWithDefaults = Config &
Required<
Pick<Config, "storage" | "crypto" | "fetch" | "location" | "history">
Pick<
Config,
| "storage"
| "crypto"
| "fetch"
| "location"
| "history"
| "URL"
| "TextDecoder"
>
>;

let config_: ConfigWithDefaults | undefined = undefined;
Expand All @@ -102,6 +119,8 @@ export function configure(config?: Config) {
fetch: config.fetch ?? Defaults.fetch,
location: config.location ?? Defaults.location,
history: config.history ?? Defaults.history,
URL: config.URL ?? Defaults.URL,
TextDecoder: config.TextDecoder ?? Defaults.TextDecoder,
};
config_.debug?.("Configuration loaded:", config);
} else {
Expand Down Expand Up @@ -227,6 +246,15 @@ class Defaults {
if (typeof globalThis.history !== "undefined") return globalThis.history;
return Defaults.getFailingProxy("history") as MinimalHistory;
}
static get URL(): MinimalURL {
if (typeof globalThis.URL !== "undefined") return globalThis.URL;
return Defaults.getFailingProxy("URL") as MinimalURL;
}
static get TextDecoder(): MinimalTextDecoder {
if (typeof globalThis.TextDecoder !== "undefined")
return globalThis.TextDecoder;
return Defaults.getFailingProxy("TextDecoder") as MinimalTextDecoder;
}
}

export interface MinimalResponse {
Expand Down Expand Up @@ -263,3 +291,15 @@ export interface MinimalCrypto {
sign: Crypto["subtle"]["sign"];
};
}

export interface MinimalURL {
new (url: string): {
href: string;
hash: string;
};
}
export interface MinimalTextDecoder {
new (): {
decode(buffer: Uint8Array): string;
};
}
6 changes: 3 additions & 3 deletions client/fido2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export async function fido2UpdateCredential({
}).then(throwIfNot2xx);
}

interface Fido2Options {
export interface Fido2Options {
challenge: string;
timeout?: number;
userVerification?: UserVerificationRequirement;
Expand Down Expand Up @@ -351,7 +351,7 @@ function assertIsFido2Options(o: unknown): asserts o is Fido2Options {
}
}

async function fido2getCredential({
export async function fido2getCredential({
relyingPartyId,
challenge,
credentials,
Expand Down Expand Up @@ -484,7 +484,7 @@ export function authenticateWithFido2({
}
const abort = new AbortController();
const signedIn = (async () => {
const { debug, fido2 } = configure();
const { debug, fido2, TextDecoder } = configure();
if (!fido2) {
throw new Error("Missing Fido2 config");
}
Expand Down
4 changes: 2 additions & 2 deletions client/magic-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ export const requestSignInLink = ({

const failedFragmentIdentifieres = new Set<string>();
function checkCurrentLocationForSignInLink() {
const { debug, location } = configure();
const { debug, location, URL } = configure();
let url: URL;
let fragmentIdentifier: string;
try {
url = new URL(location.href);
url = new URL(location.href) as URL;
fragmentIdentifier = url.hash?.slice(1);
if (!fragmentIdentifier) {
debug?.(
Expand Down
Loading

0 comments on commit 5f57245

Please sign in to comment.