-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
50 lines (43 loc) · 1.28 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React, { useCallback, useState } from 'react';
import { webAuthn } from './hooks/webAuthn.ts';
const rpOptions = {
rpId: 'localhost',
rpName: 'webauthn-demo'
}
function App() {
const [login, setLogin] = useState('')
const { getCredential, getAssertion } = webAuthn(rpOptions)
const onChangeLogin = useCallback((e: any) => {
setLogin(e.target.value)
}, [])
const onRegister = useCallback(async () => {
const credential = await getCredential({
challenge: 'stringFromServer',
userDisplayName: login,
userId: login,
userName: login
})
console.log(credential)
}, [getCredential, login])
const onAuth = useCallback(async () => {
const assertion = await getAssertion({ challenge: 'stringFromServer' })
console.log(assertion)
}, [getAssertion])
return (
<div className="App">
<main>
<div className="section">
<input onInput={onChangeLogin} placeholder="login" type="text" />
</div>
<div className="section">
<button onClick={onRegister} type="button">register</button>
</div>
<div className="del" />
<div className="section">
<button onClick={onAuth} type="button">auth</button>
</div>
</main>
</div>
);
}
export default App;