Parent sign-in
Sign the parent in to k-ID with an emailed one-time code, using the drop-in widget or your own UI.
Every Family SDK flow acts for a signed-in parent (a trusted adult). The parent signs in with their email and a one-time code. There is no password and no separate k-ID account to create.
Drop-in sign-in
import { KidSignedIn, KidSignedOut, KidTrustedAdultAuth } from '@k-id/family-react'
<KidSignedOut>
<KidTrustedAdultAuth email={user.email} onAuthenticated={() => {}} />
</KidSignedOut>
<KidSignedIn>
<YourFamilyArea />
</KidSignedIn>KidTrustedAdultAuth is the Family Portal's email-and-one-time-code sign-in. It signs the parent up the first time and in after that. It renders nothing once the parent is signed in.
| Prop | Notes |
|---|---|
email | Prefills the email field. The parent still submits it. |
onAuthenticated | Called once the parent is signed in. |
KidSignedIn renders its children only while a parent is signed in. KidSignedOut renders its children when no one is signed in, including when the stored session couldn't be checked.
Reading the session
useKidTrustedAdult() gives you:
| Field | Meaning |
|---|---|
isLoaded | The stored session has been checked. |
isSignedIn | Whether a parent is signed in. |
adult | { email } for the signed-in parent, or null. |
signOut() | Ends the session. |
error | Set when the stored session couldn't be checked on load, for example when k-ID is unreachable. The parent may still be signed in. |
refresh() | Checks the stored session again. Offer it, rather than sign-in, when error is set. |
The parent's k-ID session is separate from your own users' login. Signing out of your app doesn't sign them out of k-ID; call signOut() if you want both.
Test keys
With a test key, the parent's session cookie is set by k-ID's test host, so on your page it's a third-party cookie. If the browser blocks it, the parent signs in again after each page reload. Live keys don't have this limit, because the cookie is on your own subdomain.
Building your own sign-in UI
useKidTrustedAdultAuth() runs the same flow as the widget:
| Field | Meaning |
|---|---|
phase | 'email', 'sending', 'code' or 'verifying'. |
email | The email the code was sent to, or null. |
sendCode(email) | Sends a one-time code and moves to 'code'. |
verifyCode(code) | Checks the code and signs the parent in. |
resendCode() | Sends a new code to the same email. |
back() | Returns to the email step. |
error | The last sign-in failure: invalid_otp for a wrong or expired code, rate_limited when the parent tries too often. |
import { useState } from 'react'
import { useKidStrings, useKidTrustedAdultAuth } from '@k-id/family-react'
function SignIn() {
const auth = useKidTrustedAdultAuth()
const strings = useKidStrings()
const [email, setEmail] = useState('')
const [code, setCode] = useState('')
const busy = auth.phase === 'sending' || auth.phase === 'verifying'
const askingEmail = auth.phase === 'email' || auth.phase === 'sending'
return (
<form
onSubmit={(event) => {
event.preventDefault()
void (askingEmail ? auth.sendCode(email) : auth.verifyCode(code))
}}
>
{askingEmail ? (
<>
<label htmlFor="kid-email">{strings.trustedAdultAuth.emailLabel}</label>
<input
id="kid-email"
type="email"
autoComplete="email"
value={email}
onChange={(event) => setEmail(event.target.value)}
/>
</>
) : (
<>
<label htmlFor="kid-code">{strings.trustedAdultAuth.codeScreenReaderLabel}</label>
<input
id="kid-code"
autoComplete="one-time-code"
value={code}
onChange={(event) => setCode(event.target.value)}
/>
</>
)}
<button disabled={busy}>{askingEmail ? 'Send code' : 'Sign in'}</button>
{auth.error && <p role="alert">{strings.errors[auth.error.code]}</p>}
</form>
)
}Show the parent strings.errors[code] rather than error.message, which is a fixed developer message. See Results and errors.