Device Authorization
better-auth-ui/device-authorizationFreeComponent
Device authorization plugin: code entry, sign-in continuation, and approve or deny actions for Better Auth device requests.
Live preview
live · rendered by the registry
Rendered by better-auth-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://better-auth-ui.com/r/device-authorization.jsonSource
1"use client"23import type { DeviceAuthorizationLocalization } from "@better-auth-ui/core/plugins"4import {5 type DeviceAuthorizationAuthClient,6 useApproveDevice,7 useAuth,8 useAuthPlugin,9 useDenyDevice,10 useSession,11 useVerifyDeviceCode12} from "@better-auth-ui/react"13import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp"14import { CheckIcon, CircleCheckIcon, CircleXIcon, XIcon } from "lucide-react"15import {16 type FormEvent,17 type ReactNode,18 useCallback,19 useEffect,20 useReducer,21 useRef,22 useState23} from "react"2425import { Button } from "@/components/ui/button"26import {27 Card,28 CardContent,29 CardDescription,30 CardFooter,31 CardHeader,32 CardTitle33} from "@/components/ui/card"34import {35 Field,36 FieldError,37 FieldGroup,38 FieldLabel39} from "@/components/ui/field"40import {41 InputOTP,42 InputOTPGroup,43 InputOTPSeparator,44 InputOTPSlot45} from "@/components/ui/input-otp"46import { Separator } from "@/components/ui/separator"47import { Spinner } from "@/components/ui/spinner"48import { deviceAuthorizationPlugin } from "@/lib/auth/device-authorization-plugin"49import { cn } from "@/lib/utils"5051type DeviceAuthorizationStep = "code" | "approval" | "approved" | "denied"5253type DeviceAuthorizationState = {54 step: DeviceAuthorizationStep55 codeError: string56}5758type DeviceAuthorizationAction =59 | { type: "codeChanged" }60 | { type: "verificationFailed"; message: string }61 | { type: "verificationSucceeded"; status: string }62 | { type: "approved" }63 | { type: "denied" }6465const initialDeviceAuthorizationState: DeviceAuthorizationState = {66 step: "code",67 codeError: ""68}6970function deviceAuthorizationReducer(71 state: DeviceAuthorizationState,72 action: DeviceAuthorizationAction73): DeviceAuthorizationState {74 switch (action.type) {75 case "codeChanged":76 return state.codeError ? { ...state, codeError: "" } : state77 case "verificationFailed":78 return { step: "code", codeError: action.message }79 case "verificationSucceeded":80 if (action.status === "approved") {81 return { step: "approved", codeError: "" }82 }83 if (action.status === "denied") {84 return { step: "denied", codeError: "" }85 }86 return { step: "approval", codeError: "" }87 case "approved":88 return { step: "approved", codeError: "" }89 case "denied":90 return { step: "denied", codeError: "" }91 }92}9394function normalizeDeviceCode(value: string) {95 return value.replace(/-/g, "").trim().toUpperCase()96}9798// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from better-auth-ui
All 49 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Account Settingsaccount-settings | better-auth-ui | Components | Free | 2 deps | |
| Active Sessionsactive-sessions | better-auth-ui | Components | Free | 5 deps · 2 files | |
| Additional Fieldadditional-field | better-auth-ui | Components | Free | 5 deps | |
| Adminadmin | better-auth-ui | Components | Free | 4 deps · 3 files | |
| Anonymousanonymous | better-auth-ui | Components | Free | 4 deps · 3 files | |
| API Keyapi-key | better-auth-ui | Components | Free | 4 deps · 10 files | |
| Authauth | better-auth-ui | Components | Free | 2 deps | |
| Auth Providerauth-provider | better-auth-ui | Components | Free | 4 deps · 2 files |
