Skip to content

Commit 688495b

Browse files
committed
Update main example in README.md.
1 parent db8d3a0 commit 688495b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ npm install --save @github/webauthn-json
2020
Then:
2121

2222
```typescript
23-
import { create } from "@github/webauthn-json";
23+
import {
24+
create,
25+
parseCreationOptionsFromJSON,
26+
} from "@github/webauthn-json/browser-ponyfill";
2427

2528
const request = fetch("...");
26-
async createCredential() {
27-
const response = await create((await request).json());
28-
await fetch("...", {
29+
30+
async function createCredential() {
31+
const json = await (await request).json();
32+
const options = parseCreationOptionsFromJSON(json);
33+
const response = await create(options);
34+
fetch("...", {
2935
method: "POST",
30-
body: JSON.stringify(response)
36+
body: JSON.stringify(response.toJSON()),
3137
});
3238
}
3339
```
@@ -46,11 +52,11 @@ function supported(): boolean;
4652
function parseCreationOptionsFromJSON(json: JSON): CredentialCreationOptions;
4753
function parseRequestOptionsFromJSON(json: JSON): CredentialRequestOptions;
4854

49-
// Can call `.toJSON()` on the result.
55+
// You can call `.toJSON()` on the result.
5056
function create(
5157
options: CredentialCreationOptions,
5258
): Promise<PublicKeyCredential>;
53-
// Can call `.toJSON()` on the result.
59+
// You can call `.toJSON()` on the result.
5460
function get(options: CredentialRequestOptions): Promise<PublicKeyCredential>;
5561
```
5662

0 commit comments

Comments
 (0)