ODD SDK Preact hooks and context provider.
pnpm install @oddjs/preact
// app.jsx
import { OddContextProvider } from '@oddjs/preact'
/** @type {import('@oddjs/odd').Configuration} */
const config = {
namespace: {
creator: document.location.host,
name: 'Passkey auth',
},
}
export function App() {
return (
<>
<OddContextProvider
config={config}
componentsFactory={OddPasskey.createComponents}
>
<main className="App">
<Home path="/" />
</main>
</OddContextProvider>
</>
)
}
// home.jsx
import { useOddContext } from '@oddjs/preact'
export default function Home(props) {
const { session, isLoading, login, logout, register } = useOddContext()
}
// home.jsx with preact-router
import { useOdd } from '@oddjs/preact/router'
export default function Home(props) {
const { session, isLoading, login, logout, register } = useOdd({
redirectTo: '/login',
})
}
Check https://oddsdk.github.io/passkeys/modules/_oddjs_preact.html