diff options
author | Matthew Miller <matthew@millerti.me> | 2020-12-22 07:51:39 -0800 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2020-12-22 07:51:39 -0800 |
commit | a62ff95e9a16c531e2096e55b8d04f7c0d664774 (patch) | |
tree | 07c4a97529314a203d8806baaeb312856ecaad59 | |
parent | 973797b1351829bae24ad42ae2bdddcebc6c518a (diff) |
Improve typing in Example
-rw-r--r-- | example/index.ts | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/example/index.ts b/example/index.ts index b3ecd4d..1492395 100644 --- a/example/index.ts +++ b/example/index.ts @@ -21,6 +21,10 @@ import { generateAssertionOptions, verifyAssertionResponse, } from '@simplewebauthn/server'; +import type { + AttestationCredentialJSON, + AuthenticatorDevice, +} from '@simplewebauthn/typescript-types'; import { LoggedInUser } from './example-server'; @@ -65,15 +69,7 @@ const inMemoryUserDeviceDB: { [loggedInUserId: string]: LoggedInUser } = { [loggedInUserId]: { id: loggedInUserId, username: `user@${rpID}`, - devices: [ - /** - * { - * credentialID: string, - * publicKey: string, - * counter: number, - * } - */ - ], + devices: [], /** * A simple way of storing a user's current challenge being signed by attestation or assertion. * It should be expired after `timeout` milliseconds (optional argument for `generate` methods, @@ -135,7 +131,7 @@ app.get('/generate-attestation-options', (req, res) => { }); app.post('/verify-attestation', async (req, res) => { - const { body } = req; + const body: AttestationCredentialJSON = req.body; const user = inMemoryUserDeviceDB[loggedInUserId]; @@ -165,11 +161,12 @@ app.post('/verify-attestation', async (req, res) => { /** * Add the returned device to the user's list of devices */ - user.devices.push({ + const newDevice: AuthenticatorDevice = { publicKey: base64PublicKey, credentialID: base64CredentialID, counter, - }); + }; + user.devices.push(newDevice); } } |