refactor: remove univoq components until jsr-io/jsr#24
This commit is contained in:
parent
6d56d9ec1f
commit
ba9a1ad15c
9
components/Button.tsx
Normal file
9
components/Button.tsx
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { JSX } from 'preact'
|
||||||
|
|
||||||
|
export function Button(
|
||||||
|
{ variant, ...props }:
|
||||||
|
& { variant: 'primary' | 'secondary' | 'tertiary' }
|
||||||
|
& JSX.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||||
|
) {
|
||||||
|
return <button class={`button button-${variant}`} {...props}></button>
|
||||||
|
}
|
||||||
42
components/Input.tsx
Normal file
42
components/Input.tsx
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import { useSignal, useSignalEffect } from '@preact/signals'
|
||||||
|
import { JSX } from 'preact'
|
||||||
|
|
||||||
|
export function Input(
|
||||||
|
{ label, name, ...props }:
|
||||||
|
& { label: string; name: string }
|
||||||
|
& JSX.InputHTMLAttributes<HTMLInputElement>,
|
||||||
|
) {
|
||||||
|
if (props.type === 'password') {
|
||||||
|
const password = useSignal('')
|
||||||
|
const hash = useSignal('')
|
||||||
|
const salt = crypto.randomUUID()
|
||||||
|
|
||||||
|
useSignalEffect(() => {
|
||||||
|
crypto.subtle.digest(
|
||||||
|
'SHA-256',
|
||||||
|
new TextEncoder().encode(salt + password.value),
|
||||||
|
).then((digest) => hash.value = new TextDecoder().decode(digest))
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<label>
|
||||||
|
<span>{label}</span>
|
||||||
|
<input
|
||||||
|
{...props}
|
||||||
|
spellcheck={false}
|
||||||
|
onInput={(event) =>
|
||||||
|
password.value = (event.target as HTMLInputElement).value}
|
||||||
|
/>
|
||||||
|
<input type='text' hidden value={hash} name={name} />
|
||||||
|
<input type='text' hidden value={salt} name={`${name}_salt`} />
|
||||||
|
</label>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<label>
|
||||||
|
<span>{label}</span>
|
||||||
|
<input {...props} name={name} />
|
||||||
|
</label>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -48,8 +48,6 @@
|
||||||
"@std/json": "jsr:@std/json@^1.0.1",
|
"@std/json": "jsr:@std/json@^1.0.1",
|
||||||
"@std/streams": "jsr:@std/streams@^0.224.5",
|
"@std/streams": "jsr:@std/streams@^0.224.5",
|
||||||
"preact": "npm:preact@^10.24.2",
|
"preact": "npm:preact@^10.24.2",
|
||||||
"@univoq/": "https://deno.land/x/univoq@0.2.0/",
|
|
||||||
"univoq": "https://deno.land/x/univoq@0.2.0/mod.ts",
|
|
||||||
"web-push": "npm:web-push@^3.6.7"
|
"web-push": "npm:web-push@^3.6.7"
|
||||||
},
|
},
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import { requestApi } from ':src/utils.ts'
|
import { requestApi } from ':src/utils.ts'
|
||||||
import { startAuthentication } from '@simplewebauthn/browser'
|
import { startAuthentication } from '@simplewebauthn/browser'
|
||||||
import { PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types'
|
import { PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types'
|
||||||
import { Button, Input } from 'univoq'
|
|
||||||
import type {
|
import type {
|
||||||
WebAuthnLoginFinishPayload,
|
WebAuthnLoginFinishPayload,
|
||||||
WebAuthnLoginStartPayload,
|
WebAuthnLoginStartPayload,
|
||||||
} from '../routes/api/webauthn/login/[step].ts'
|
} from '../routes/api/webauthn/login/[step].ts'
|
||||||
|
import { Button } from ':components/Button.tsx'
|
||||||
|
import { Input } from ':components/Input.tsx'
|
||||||
|
|
||||||
export default function LoginForm() {
|
export default function LoginForm() {
|
||||||
return (
|
return (
|
||||||
|
|
@ -28,7 +29,7 @@ export default function LoginForm() {
|
||||||
type='checkbox'
|
type='checkbox'
|
||||||
checked
|
checked
|
||||||
/>
|
/>
|
||||||
<Button label='Me connecter' variant='primary'>Me connecter</Button>
|
<Button variant='primary'>Me connecter</Button>
|
||||||
</form>
|
</form>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import { requestApi } from ':src/utils.ts'
|
import { requestApi } from ':src/utils.ts'
|
||||||
import { startRegistration } from '@simplewebauthn/browser'
|
import { startRegistration } from '@simplewebauthn/browser'
|
||||||
import { PublicKeyCredentialCreationOptionsJSON } from '@simplewebauthn/types'
|
import { PublicKeyCredentialCreationOptionsJSON } from '@simplewebauthn/types'
|
||||||
import { Button, Input } from 'univoq'
|
|
||||||
import type {
|
import type {
|
||||||
WebAuthnRegisterFinishPayload,
|
WebAuthnRegisterFinishPayload,
|
||||||
WebAuthnRegisterStartPayload,
|
WebAuthnRegisterStartPayload,
|
||||||
} from '../routes/api/webauthn/register/[step].ts'
|
} from '../routes/api/webauthn/register/[step].ts'
|
||||||
|
import { Button } from ':components/Button.tsx'
|
||||||
|
import { Input } from ':components/Input.tsx'
|
||||||
|
|
||||||
function isWebAuthnSupported(): boolean {
|
function isWebAuthnSupported(): boolean {
|
||||||
return 'credentials' in navigator
|
return 'credentials' in navigator
|
||||||
|
|
@ -16,7 +17,6 @@ function RegisterForm({ disabled }: { disabled?: boolean }) {
|
||||||
<form onSubmit={register} method='POST' action=''>
|
<form onSubmit={register} method='POST' action=''>
|
||||||
<Input label='Nom de la clé' name='name' required></Input>
|
<Input label='Nom de la clé' name='name' required></Input>
|
||||||
<Button
|
<Button
|
||||||
label='Enregistrer une PassKey'
|
|
||||||
variant='primary'
|
variant='primary'
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// import { Suspense } from '@univoq // Error - mismatch in imports version
|
|
||||||
import { JSX } from 'preact'
|
import { JSX } from 'preact'
|
||||||
import { useSignal } from '@preact/signals'
|
import { useSignal } from '@preact/signals'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import LoginForm from ':islands/LoginForm.tsx'
|
||||||
import PassKeyRegister from ':islands/PassKeyRegister.tsx'
|
import PassKeyRegister from ':islands/PassKeyRegister.tsx'
|
||||||
import type { SessionPageProps } from ':src/session/mod.ts'
|
import type { SessionPageProps } from ':src/session/mod.ts'
|
||||||
import type { User } from '@cohabit/resources-manager/models'
|
import type { User } from '@cohabit/resources-manager/models'
|
||||||
import { Button } from 'univoq'
|
import { Button } from ':components/Button.tsx'
|
||||||
|
|
||||||
export default function Profil({ state }: SessionPageProps) {
|
export default function Profil({ state }: SessionPageProps) {
|
||||||
const user = state.session?.get<User>('user')
|
const user = state.session?.get<User>('user')
|
||||||
|
|
@ -16,7 +16,7 @@ export default function Profil({ state }: SessionPageProps) {
|
||||||
</section>
|
</section>
|
||||||
<div>
|
<div>
|
||||||
<PassKeyRegister />
|
<PassKeyRegister />
|
||||||
<Button label='Disconnect' variant='primary'>
|
<Button variant='primary'>
|
||||||
Disconnect
|
Disconnect
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue