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

feat(react-native): added e2e example and ready-to-use component #103

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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