An open API service indexing awesome lists of open source software.

https://github.com/u4aew/react-webauthn

React hook for webAuthn
https://github.com/u4aew/react-webauthn

hook react webauthn

Last synced: about 1 year ago
JSON representation

React hook for webAuthn

Awesome Lists containing this project

README

          

[![npm version](https://badge.fury.io/js/react-hook-webauthn.svg)](https://badge.fury.io/js/react-hook-webauthn)
# React-hook-webauthn
Simple Hook for react, serverless use of webAuthn

![demo](./img/demo.gif)

## Installing as a package

```
npm i react-hook-webauthn
```

## Usage
A detailed setup process can be read in this [article](https://dev.to/u4aew/adding-webauthnto-the-web-application-59gp).
```js
import React, { useCallback, useState } from 'react';
import {useWebAuthn} from 'react-hook-webauthn'
import './App.css';

const rpOptions = {
rpId: 'localhost',
rpName: 'my super app'
}

function App() {
const [login, setLogin] = useState('')
const {getCredential, getAssertion} = useWebAuthn(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 (







register



auth



);
}

export default App;
```

## Options
| name | type | required |
|-----------------|--------|----------|
| rpName | string | true |
| rpId | string | true |
| userName | string | true |
| userDisplayName | string | true |
| challenge | string | true |
| credentialOpt | object | false |
| assertionOpt | object | false |