@sneekin/ui 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component.d.ts +2 -0
- package/dist/index.js +107 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/component.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export type SneekTheme = 'auto' | 'light' | 'dark';
|
|
|
4
4
|
export interface SneekOtpLoginProps<TResult = unknown> extends SneekOtpHandlers<TResult> {
|
|
5
5
|
/** Heading above the form. @default 'Sign in' */
|
|
6
6
|
title?: string;
|
|
7
|
+
/** Heading once the code has been sent. @default 'Enter the code' */
|
|
8
|
+
verifyTitle?: string;
|
|
7
9
|
/** Sub-heading. Pass `null` to remove it. */
|
|
8
10
|
subtitle?: ReactNode;
|
|
9
11
|
/** Label for the identifier input. */
|
package/dist/index.js
CHANGED
|
@@ -237,6 +237,8 @@ function buildStyles(accent) {
|
|
|
237
237
|
|
|
238
238
|
// src/component.tsx
|
|
239
239
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
240
|
+
var CODE_LENGTH = 6;
|
|
241
|
+
var RESEND_SECONDS = 30;
|
|
240
242
|
function SneekMark() {
|
|
241
243
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
242
244
|
"svg",
|
|
@@ -257,7 +259,8 @@ function SneekMark() {
|
|
|
257
259
|
function SneekOtpLogin(props) {
|
|
258
260
|
const {
|
|
259
261
|
title = "Sign in",
|
|
260
|
-
|
|
262
|
+
verifyTitle = "Enter the code",
|
|
263
|
+
subtitle = "Enter your email or phone. We will send you a code.",
|
|
261
264
|
identifierLabel = "Email or mobile",
|
|
262
265
|
identifierPlaceholder = "you@company.com or +91\u2026",
|
|
263
266
|
theme = "auto",
|
|
@@ -270,6 +273,7 @@ function SneekOtpLogin(props) {
|
|
|
270
273
|
} = props;
|
|
271
274
|
const otp = useSneekOtp(handlers);
|
|
272
275
|
const uid = (0, import_react2.useId)();
|
|
276
|
+
const [resendIn, setResendIn] = (0, import_react2.useState)(0);
|
|
273
277
|
const identifierId = `${uid}-identifier`;
|
|
274
278
|
const codeId = `${uid}-code`;
|
|
275
279
|
const statusId = `${uid}-status`;
|
|
@@ -291,6 +295,19 @@ function SneekOtpLogin(props) {
|
|
|
291
295
|
event.preventDefault();
|
|
292
296
|
void otp.verify();
|
|
293
297
|
};
|
|
298
|
+
(0, import_react2.useEffect)(() => {
|
|
299
|
+
if (otp.step === "verify") setResendIn(RESEND_SECONDS);
|
|
300
|
+
}, [otp.step]);
|
|
301
|
+
(0, import_react2.useEffect)(() => {
|
|
302
|
+
if (resendIn <= 0) return;
|
|
303
|
+
const timer = setTimeout(() => setResendIn((n) => n - 1), 1e3);
|
|
304
|
+
return () => clearTimeout(timer);
|
|
305
|
+
}, [resendIn]);
|
|
306
|
+
(0, import_react2.useEffect)(() => {
|
|
307
|
+
if (otp.step === "verify" && otp.code.length === CODE_LENGTH && !otp.isBusy) {
|
|
308
|
+
void otp.verify();
|
|
309
|
+
}
|
|
310
|
+
}, [otp.code, otp.step]);
|
|
294
311
|
const label = {
|
|
295
312
|
display: "flex",
|
|
296
313
|
flexDirection: "column",
|
|
@@ -370,10 +387,37 @@ function SneekOtpLogin(props) {
|
|
|
370
387
|
letterSpacing: "-0.01em",
|
|
371
388
|
margin: "16px 0 0"
|
|
372
389
|
},
|
|
373
|
-
children: title
|
|
390
|
+
children: otp.step === "verify" ? verifyTitle : title
|
|
374
391
|
}
|
|
375
392
|
),
|
|
376
|
-
|
|
393
|
+
otp.step === "verify" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
394
|
+
"p",
|
|
395
|
+
{
|
|
396
|
+
style: {
|
|
397
|
+
fontSize: 14,
|
|
398
|
+
lineHeight: "20px",
|
|
399
|
+
color: "var(--sneek-text-muted)",
|
|
400
|
+
margin: "8px 0 0"
|
|
401
|
+
},
|
|
402
|
+
children: [
|
|
403
|
+
"Sent to",
|
|
404
|
+
" ",
|
|
405
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { color: "var(--sneek-text)" }, children: otp.identifier }),
|
|
406
|
+
" \xB7 ",
|
|
407
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
408
|
+
"button",
|
|
409
|
+
{
|
|
410
|
+
type: "button",
|
|
411
|
+
className: "sneek-otp-link",
|
|
412
|
+
onClick: otp.back,
|
|
413
|
+
disabled: otp.isBusy,
|
|
414
|
+
style: { ...link, fontSize: 14 },
|
|
415
|
+
children: "Change"
|
|
416
|
+
}
|
|
417
|
+
)
|
|
418
|
+
]
|
|
419
|
+
}
|
|
420
|
+
) : subtitle ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
377
421
|
"p",
|
|
378
422
|
{
|
|
379
423
|
style: {
|
|
@@ -396,10 +440,7 @@ function SneekOtpLogin(props) {
|
|
|
396
440
|
},
|
|
397
441
|
children: otp.error
|
|
398
442
|
}
|
|
399
|
-
) :
|
|
400
|
-
otp.channels.length > 0 ? `Code sent by ${formatChannels(otp.channels)}.` : "We sent you a code.",
|
|
401
|
-
otp.expiresInSeconds > 0 ? ` It expires in ${Math.max(1, Math.floor(otp.expiresInSeconds / 60))} min.` : ""
|
|
402
|
-
] }) : null }),
|
|
443
|
+
) : null }),
|
|
403
444
|
otp.step === "identify" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
404
445
|
"form",
|
|
405
446
|
{
|
|
@@ -443,60 +484,73 @@ function SneekOtpLogin(props) {
|
|
|
443
484
|
onSubmit: onVerifySubmit,
|
|
444
485
|
style: { display: "flex", flexDirection: "column", gap: 16, marginTop: 16 },
|
|
445
486
|
children: [
|
|
446
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { style: label, htmlFor: codeId, children: [
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
"input",
|
|
450
|
-
{
|
|
451
|
-
id: codeId,
|
|
452
|
-
className: "sneek-otp-input",
|
|
453
|
-
type: "text",
|
|
454
|
-
inputMode: "numeric",
|
|
455
|
-
autoComplete: "one-time-code",
|
|
456
|
-
value: otp.code,
|
|
457
|
-
onChange: (e) => otp.setCode(e.target.value),
|
|
458
|
-
placeholder: "6-digit code",
|
|
459
|
-
autoFocus: true,
|
|
460
|
-
required: true,
|
|
461
|
-
"aria-describedby": statusId,
|
|
462
|
-
style: { ...input, letterSpacing: "0.3em" }
|
|
463
|
-
}
|
|
464
|
-
)
|
|
487
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { style: { ...label, marginBottom: -8 }, htmlFor: codeId, children: [
|
|
488
|
+
CODE_LENGTH,
|
|
489
|
+
"-digit code"
|
|
465
490
|
] }),
|
|
491
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
492
|
+
"input",
|
|
493
|
+
{
|
|
494
|
+
id: codeId,
|
|
495
|
+
className: "sneek-otp-input",
|
|
496
|
+
type: "text",
|
|
497
|
+
inputMode: "numeric",
|
|
498
|
+
pattern: "[0-9]*",
|
|
499
|
+
autoComplete: "one-time-code",
|
|
500
|
+
maxLength: CODE_LENGTH,
|
|
501
|
+
value: otp.code,
|
|
502
|
+
onChange: (e) => otp.setCode(e.target.value.replace(/\D/g, "").slice(0, CODE_LENGTH)),
|
|
503
|
+
autoFocus: true,
|
|
504
|
+
required: true,
|
|
505
|
+
"aria-describedby": statusId,
|
|
506
|
+
style: {
|
|
507
|
+
...input,
|
|
508
|
+
fontSize: 24,
|
|
509
|
+
lineHeight: "32px",
|
|
510
|
+
textAlign: "center",
|
|
511
|
+
letterSpacing: "0.4em",
|
|
512
|
+
textIndent: "0.4em",
|
|
513
|
+
padding: "14px"
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
),
|
|
466
517
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
467
518
|
"button",
|
|
468
519
|
{
|
|
469
520
|
type: "submit",
|
|
470
521
|
className: "sneek-otp-button",
|
|
471
|
-
disabled: otp.isBusy,
|
|
472
|
-
style:
|
|
473
|
-
|
|
522
|
+
disabled: otp.isBusy || otp.code.length < CODE_LENGTH,
|
|
523
|
+
style: {
|
|
524
|
+
...button,
|
|
525
|
+
opacity: otp.isBusy || otp.code.length < CODE_LENGTH ? 0.6 : 1
|
|
526
|
+
},
|
|
527
|
+
children: otp.isVerifying ? "Verifying\u2026" : "Verify"
|
|
474
528
|
}
|
|
475
529
|
),
|
|
476
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
{
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
530
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { textAlign: "center" }, children: resendIn > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
531
|
+
"span",
|
|
532
|
+
{
|
|
533
|
+
style: {
|
|
534
|
+
fontSize: 14,
|
|
535
|
+
color: "var(--sneek-text-muted)"
|
|
536
|
+
},
|
|
537
|
+
children: [
|
|
538
|
+
"Resend code in ",
|
|
539
|
+
resendIn,
|
|
540
|
+
"s"
|
|
541
|
+
]
|
|
542
|
+
}
|
|
543
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
544
|
+
"button",
|
|
545
|
+
{
|
|
546
|
+
type: "button",
|
|
547
|
+
className: "sneek-otp-link",
|
|
548
|
+
onClick: () => void otp.resend(),
|
|
549
|
+
disabled: otp.isBusy,
|
|
550
|
+
style: link,
|
|
551
|
+
children: "Resend code"
|
|
552
|
+
}
|
|
553
|
+
) })
|
|
500
554
|
]
|
|
501
555
|
}
|
|
502
556
|
),
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/use-sneek-otp.ts","../src/state.ts","../src/component.tsx","../src/theme.ts","../src/fetch-handlers.ts"],"sourcesContent":["export {\n useSneekOtp,\n type SneekOtpHandlers,\n type UseSneekOtp,\n} from './use-sneek-otp';\n\nexport {\n SneekOtpLogin,\n type SneekOtpLoginProps,\n type SneekTheme,\n} from './component';\n\nexport {\n SNEEK_ACCENT_DARK,\n SNEEK_ACCENT_LIGHT,\n} from './theme';\n\nexport {\n createFetchHandlers,\n type FetchHandlerOptions,\n} from './fetch-handlers';\n\nexport {\n otpReducer,\n initialOtpState,\n formatChannels,\n type SneekChannel,\n type SneekOtpStep,\n type SneekOtpStatus,\n type SneekOtpState,\n type SneekOtpAction,\n type RequestOtpResult,\n} from './state';\n","import { useCallback, useReducer } from 'react';\nimport {\n initialOtpState,\n otpReducer,\n toMessage,\n type RequestOtpResult,\n type SneekOtpState,\n} from './state';\n\n/**\n * Partner-supplied transport. These call the *partner's own backend*, which in\n * turn talks to the Sneek API with the secret server-side key. The browser\n * never sees a Sneek API key — that is the whole security model of this package.\n */\nexport interface SneekOtpHandlers<TResult = unknown> {\n /** Ask the partner backend to send an OTP to `identifier`. */\n requestOtp: (identifier: string) => Promise<RequestOtpResult>;\n /** Verify the code with the partner backend; resolve with the auth result. */\n verifyOtp: (input: { requestId: string; code: string }) => Promise<TResult>;\n /** Called after a successful verification with the partner's result. */\n onSuccess?: (result: TResult) => void;\n /** Called on any error (request or verify). */\n onError?: (error: unknown) => void;\n}\n\nexport interface UseSneekOtp extends SneekOtpState {\n setIdentifier: (value: string) => void;\n setCode: (value: string) => void;\n /** Submit the identify step — triggers `requestOtp`. */\n sendOtp: () => Promise<void>;\n /** Submit the verify step — triggers `verifyOtp`. */\n verify: () => Promise<void>;\n /** Go back to the identify screen (e.g. \"use a different email\"). */\n back: () => void;\n /** Re-send the OTP to the same identifier. */\n resend: () => Promise<void>;\n /** Convenience booleans. */\n isSending: boolean;\n isVerifying: boolean;\n isBusy: boolean;\n}\n\nconst DEFAULT_REQUEST_ERROR = 'Could not send the code. Please try again.';\nconst DEFAULT_VERIFY_ERROR = 'That code was not correct. Please try again.';\n\n/**\n * Headless hook implementing the passwordless OTP login flow. Bring your own\n * markup, or use the {@link SneekOtpLogin} component for a styled default.\n */\nexport function useSneekOtp<TResult = unknown>(\n handlers: SneekOtpHandlers<TResult>,\n): UseSneekOtp {\n const [state, dispatch] = useReducer(otpReducer, initialOtpState);\n\n const { requestOtp, verifyOtp, onSuccess, onError } = handlers;\n\n const setIdentifier = useCallback((value: string) => {\n dispatch({ type: 'set_identifier', value });\n }, []);\n\n const setCode = useCallback((value: string) => {\n dispatch({ type: 'set_code', value });\n }, []);\n\n const runRequest = useCallback(\n async (identifier: string) => {\n const trimmed = identifier.trim();\n if (!trimmed) {\n dispatch({ type: 'request_error', message: 'Enter your email or mobile number.' });\n return;\n }\n dispatch({ type: 'request_start' });\n try {\n const result = await requestOtp(trimmed);\n dispatch({ type: 'request_success', result });\n } catch (error) {\n dispatch({ type: 'request_error', message: toMessage(error, DEFAULT_REQUEST_ERROR) });\n onError?.(error);\n }\n },\n [requestOtp, onError],\n );\n\n const sendOtp = useCallback(() => runRequest(state.identifier), [runRequest, state.identifier]);\n\n const resend = useCallback(() => runRequest(state.identifier), [runRequest, state.identifier]);\n\n const verify = useCallback(async () => {\n const code = state.code.trim();\n if (!code) {\n dispatch({ type: 'verify_error', message: 'Enter the code you received.' });\n return;\n }\n dispatch({ type: 'verify_start' });\n try {\n const result = await verifyOtp({ requestId: state.requestId, code });\n onSuccess?.(result);\n } catch (error) {\n dispatch({ type: 'verify_error', message: toMessage(error, DEFAULT_VERIFY_ERROR) });\n onError?.(error);\n }\n }, [verifyOtp, state.code, state.requestId, onSuccess, onError]);\n\n const back = useCallback(() => {\n dispatch({ type: 'back_to_identify' });\n }, []);\n\n return {\n ...state,\n setIdentifier,\n setCode,\n sendOtp,\n verify,\n back,\n resend,\n isSending: state.status === 'sending',\n isVerifying: state.status === 'verifying',\n isBusy: state.status !== 'idle',\n };\n}\n","/**\n * Framework-agnostic state machine for the Sneek passwordless OTP flow.\n *\n * Kept free of React so it can be unit-tested in isolation and reused by other\n * front-end bindings later (Vue/Svelte). The hook in `use-sneek-otp.ts` is a\n * thin wrapper around this reducer.\n */\n\nexport type SneekChannel = 'sms' | 'whatsapp' | 'email';\n\n/** Which screen of the two-step flow is showing. */\nexport type SneekOtpStep = 'identify' | 'verify';\n\n/** Async lifecycle for the in-flight request. */\nexport type SneekOtpStatus = 'idle' | 'sending' | 'verifying';\n\nexport interface SneekOtpState {\n step: SneekOtpStep;\n status: SneekOtpStatus;\n /** The email / mobile / username the user typed. */\n identifier: string;\n /** The OTP code the user typed on the verify screen. */\n code: string;\n /** Opaque id returned by the partner backend, replayed on verify. */\n requestId: string;\n /** Channels the OTP was actually delivered over. */\n channels: SneekChannel[];\n /** Seconds until the OTP expires (from the request response). */\n expiresInSeconds: number;\n /** User-facing error message, or null. */\n error: string | null;\n}\n\nexport const initialOtpState: SneekOtpState = {\n step: 'identify',\n status: 'idle',\n identifier: '',\n code: '',\n requestId: '',\n channels: [],\n expiresInSeconds: 0,\n error: null,\n};\n\nexport interface RequestOtpResult {\n requestId: string;\n channels?: SneekChannel[];\n expiresInSeconds?: number;\n}\n\nexport type SneekOtpAction =\n | { type: 'set_identifier'; value: string }\n | { type: 'set_code'; value: string }\n | { type: 'request_start' }\n | { type: 'request_success'; result: RequestOtpResult }\n | { type: 'request_error'; message: string }\n | { type: 'verify_start' }\n | { type: 'verify_error'; message: string }\n | { type: 'reset' }\n | { type: 'back_to_identify' };\n\nconst isBusy = (status: SneekOtpStatus): boolean => status !== 'idle';\n\nexport function otpReducer(\n state: SneekOtpState,\n action: SneekOtpAction,\n): SneekOtpState {\n switch (action.type) {\n case 'set_identifier':\n return { ...state, identifier: action.value, error: null };\n\n case 'set_code':\n return { ...state, code: action.value, error: null };\n\n case 'request_start':\n // Guard against double submits while a request is already in flight.\n if (isBusy(state.status)) return state;\n return { ...state, status: 'sending', error: null };\n\n case 'request_success':\n return {\n ...state,\n step: 'verify',\n status: 'idle',\n code: '',\n requestId: action.result.requestId,\n channels: action.result.channels ?? [],\n expiresInSeconds: action.result.expiresInSeconds ?? 0,\n error: null,\n };\n\n case 'request_error':\n return { ...state, status: 'idle', error: action.message };\n\n case 'verify_start':\n if (isBusy(state.status)) return state;\n return { ...state, status: 'verifying', error: null };\n\n case 'verify_error':\n return { ...state, status: 'idle', error: action.message };\n\n case 'back_to_identify':\n return {\n ...state,\n step: 'identify',\n status: 'idle',\n code: '',\n requestId: '',\n channels: [],\n expiresInSeconds: 0,\n error: null,\n };\n\n case 'reset':\n return { ...initialOtpState };\n\n default:\n return state;\n }\n}\n\nconst CHANNEL_LABELS: Record<SneekChannel, string> = {\n sms: 'SMS',\n whatsapp: 'WhatsApp',\n email: 'email',\n};\n\n/** \"SMS, WhatsApp\" — human label for the channels an OTP was sent over. */\nexport function formatChannels(channels: SneekChannel[]): string {\n return channels.map((c) => CHANNEL_LABELS[c] ?? c).join(', ');\n}\n\n/** Normalize any thrown value into a user-facing message. */\nexport function toMessage(error: unknown, fallback: string): string {\n if (error instanceof Error && error.message) return error.message;\n if (typeof error === 'string' && error) return error;\n return fallback;\n}\n","import {\n useEffect,\n useId,\n type CSSProperties,\n type FormEvent,\n type ReactNode,\n} from 'react';\nimport { formatChannels } from './state';\nimport { buildStyles, SNEEK_STYLE_ID } from './theme';\nimport { useSneekOtp, type SneekOtpHandlers } from './use-sneek-otp';\n\nexport type SneekTheme = 'auto' | 'light' | 'dark';\n\nexport interface SneekOtpLoginProps<TResult = unknown>\n extends SneekOtpHandlers<TResult> {\n /** Heading above the form. @default 'Sign in' */\n title?: string;\n /** Sub-heading. Pass `null` to remove it. */\n subtitle?: ReactNode;\n /** Label for the identifier input. */\n identifierLabel?: string;\n /** Placeholder for the identifier input. */\n identifierPlaceholder?: string;\n /**\n * Colour scheme. `auto` follows the visitor's system setting.\n * @default 'auto'\n */\n theme?: SneekTheme;\n /**\n * Override the single accent colour. Leave unset to use Sneek orange,\n * which is tuned per mode for contrast.\n */\n accentColor?: string;\n /** Replaces the Sneek mark above the title. Pass `null` to remove it. */\n logo?: ReactNode;\n /** Show the \"Secured by Sneek\" line under the form. @default true */\n showBranding?: boolean;\n /** Style overrides for the outer card. */\n style?: CSSProperties;\n /** Extra class on the outer card. */\n className?: string;\n}\n\n/**\n * Sneek mark: two triangles offset on a diagonal — one pointing up on the\n * right, one pointing down on the left. Traced from the brand asset so the\n * package needs no image file and no CDN.\n */\nfunction SneekMark() {\n return (\n <svg\n width=\"36\"\n height=\"36\"\n viewBox=\"0 0 32 32\"\n fill=\"none\"\n role=\"img\"\n aria-label=\"Sneek\"\n >\n <path d=\"M21.3 1 29.3 16H13.3L21.3 1Z\" fill=\"var(--sneek-accent)\" />\n <path d=\"M2.7 17.5H18.7L10.7 31 2.7 17.5Z\" fill=\"var(--sneek-accent)\" />\n </svg>\n );\n}\n\n/**\n * Drop-in passwordless login card.\n *\n * The component never receives a Sneek API key — it calls the handlers you\n * supply, which talk to your own backend. See `createFetchHandlers` for the\n * common case.\n *\n * @example\n * ```tsx\n * <SneekOtpLogin\n * {...createFetchHandlers({ baseUrl: '/api/auth' })}\n * onSuccess={(session) => router.push('/app')}\n * />\n * ```\n */\nexport function SneekOtpLogin<TResult = unknown>(\n props: SneekOtpLoginProps<TResult>,\n): ReactNode {\n const {\n title = 'Sign in',\n subtitle = 'We will send you a one-time code.',\n identifierLabel = 'Email or mobile',\n identifierPlaceholder = 'you@company.com or +91…',\n theme = 'auto',\n accentColor,\n logo,\n showBranding = true,\n style,\n className,\n ...handlers\n } = props;\n\n const otp = useSneekOtp<TResult>(handlers);\n const uid = useId();\n const identifierId = `${uid}-identifier`;\n const codeId = `${uid}-code`;\n const statusId = `${uid}-status`;\n\n // One <style> element for the whole page, regardless of how many cards\n // render. Injected on mount so the package stays SSR-safe.\n useEffect(() => {\n if (typeof document === 'undefined') return;\n let el = document.getElementById(SNEEK_STYLE_ID);\n if (!el) {\n el = document.createElement('style');\n el.id = SNEEK_STYLE_ID;\n document.head.appendChild(el);\n }\n el.textContent = buildStyles(accentColor);\n }, [accentColor]);\n\n const onIdentifySubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n void otp.sendOtp();\n };\n\n const onVerifySubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n void otp.verify();\n };\n\n const label: CSSProperties = {\n display: 'flex',\n flexDirection: 'column',\n gap: 8,\n fontSize: 14,\n lineHeight: '20px',\n color: 'var(--sneek-text-muted)',\n };\n\n const input: CSSProperties = {\n padding: '12px 14px',\n border: '1px solid var(--sneek-border)',\n borderRadius: 12,\n background: 'var(--sneek-surface-2)',\n color: 'var(--sneek-text)',\n fontSize: 15,\n width: '100%',\n outline: 'none',\n transition: 'border-color 200ms var(--sneek-ease)',\n };\n\n const button: CSSProperties = {\n padding: '12px 18px',\n border: 'none',\n borderRadius: 9999,\n background: 'var(--sneek-accent)',\n color: 'var(--sneek-accent-contrast)',\n fontSize: 15,\n fontWeight: 500,\n cursor: otp.isBusy ? 'not-allowed' : 'pointer',\n opacity: otp.isBusy ? 0.6 : 1,\n width: '100%',\n transition: 'filter 200ms var(--sneek-ease), opacity 200ms var(--sneek-ease)',\n };\n\n const link: CSSProperties = {\n border: 'none',\n background: 'transparent',\n color: 'var(--sneek-accent)',\n cursor: otp.isBusy ? 'not-allowed' : 'pointer',\n font: 'inherit',\n fontSize: 14,\n padding: 0,\n };\n\n const notice: CSSProperties = {\n padding: '10px 12px',\n borderRadius: 12,\n background: 'var(--sneek-surface-2)',\n border: '1px solid var(--sneek-border)',\n fontSize: 14,\n color: 'var(--sneek-text-muted)',\n };\n\n return (\n <div\n className={className ? `sneek-otp ${className}` : 'sneek-otp'}\n data-theme={theme === 'auto' ? undefined : theme}\n style={{\n maxWidth: 400,\n margin: '0 auto',\n padding: 24,\n border: '1px solid var(--sneek-border)',\n borderRadius: 16,\n background: 'var(--sneek-surface)',\n boxShadow: 'var(--sneek-shadow)',\n color: 'var(--sneek-text)',\n fontFamily:\n 'Inter, ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif',\n lineHeight: 1.5,\n ...style,\n }}\n >\n {logo === null ? null : (logo ?? <SneekMark />)}\n <h1\n style={{\n fontSize: 21,\n lineHeight: '28px',\n fontWeight: 500,\n letterSpacing: '-0.01em',\n margin: '16px 0 0',\n }}\n >\n {title}\n </h1>\n {subtitle ? (\n <p\n style={{\n fontSize: 14,\n lineHeight: '20px',\n color: 'var(--sneek-text-muted)',\n margin: '8px 0 0',\n }}\n >\n {subtitle}\n </p>\n ) : null}\n\n {/* Errors and channel notices are announced, not just shown. */}\n <div role=\"status\" aria-live=\"polite\" id={statusId} style={{ marginTop: 32 }}>\n {otp.error ? (\n <div\n role=\"alert\"\n style={{\n ...notice,\n color: 'var(--sneek-danger)',\n borderColor: 'var(--sneek-danger)',\n }}\n >\n {otp.error}\n </div>\n ) : otp.step === 'verify' ? (\n <div style={notice}>\n {otp.channels.length > 0\n ? `Code sent by ${formatChannels(otp.channels)}.`\n : 'We sent you a code.'}\n {otp.expiresInSeconds > 0\n ? ` It expires in ${Math.max(1, Math.floor(otp.expiresInSeconds / 60))} min.`\n : ''}\n </div>\n ) : null}\n </div>\n\n {otp.step === 'identify' ? (\n <form\n onSubmit={onIdentifySubmit}\n style={{ display: 'flex', flexDirection: 'column', gap: 16, marginTop: 16 }}\n >\n <label style={label} htmlFor={identifierId}>\n {identifierLabel}\n <input\n id={identifierId}\n className=\"sneek-otp-input\"\n type=\"text\"\n value={otp.identifier}\n onChange={(e) => otp.setIdentifier(e.target.value)}\n placeholder={identifierPlaceholder}\n autoComplete=\"username\"\n autoFocus\n required\n aria-describedby={statusId}\n style={input}\n />\n </label>\n <button\n type=\"submit\"\n className=\"sneek-otp-button\"\n disabled={otp.isBusy}\n style={button}\n >\n {otp.isSending ? 'Sending code…' : 'Send code'}\n </button>\n </form>\n ) : (\n <form\n onSubmit={onVerifySubmit}\n style={{ display: 'flex', flexDirection: 'column', gap: 16, marginTop: 16 }}\n >\n <label style={label} htmlFor={codeId}>\n Verification code\n <input\n id={codeId}\n className=\"sneek-otp-input\"\n type=\"text\"\n inputMode=\"numeric\"\n autoComplete=\"one-time-code\"\n value={otp.code}\n onChange={(e) => otp.setCode(e.target.value)}\n placeholder=\"6-digit code\"\n autoFocus\n required\n aria-describedby={statusId}\n style={{ ...input, letterSpacing: '0.3em' }}\n />\n </label>\n <button\n type=\"submit\"\n className=\"sneek-otp-button\"\n disabled={otp.isBusy}\n style={button}\n >\n {otp.isVerifying ? 'Verifying…' : 'Verify and sign in'}\n </button>\n <div style={{ display: 'flex', justifyContent: 'space-between', gap: 12 }}>\n <button\n type=\"button\"\n className=\"sneek-otp-link\"\n onClick={otp.back}\n disabled={otp.isBusy}\n style={link}\n >\n Use a different contact\n </button>\n <button\n type=\"button\"\n className=\"sneek-otp-link\"\n onClick={() => void otp.resend()}\n disabled={otp.isBusy}\n style={link}\n >\n Resend code\n </button>\n </div>\n </form>\n )}\n\n {showBranding ? (\n <p\n style={{\n margin: '32px 0 0',\n textAlign: 'center',\n fontSize: 12,\n lineHeight: '16px',\n color: 'var(--sneek-text-muted)',\n }}\n >\n Secured by Sneek\n </p>\n ) : null}\n </div>\n );\n}\n","/**\n * Theme for the drop-in login card.\n *\n * The package ships zero dependencies and no stylesheet, so the tokens are\n * injected once as CSS custom properties scoped to `.sneek-otp`. That buys two\n * things inline styles cannot: a `prefers-color-scheme` media query, and real\n * `:focus-visible` / `:hover` states.\n *\n * Light and dark are authored independently rather than one being an inversion\n * of the other. In dark, the page-to-card lightness delta carries depth and the\n * card needs no shadow; in light both are near-white, so the card takes a\n * visible border and a real shadow.\n */\nexport const SNEEK_STYLE_ID = 'sneek-otp-styles';\n\n/** Brand orange. The single accent — nothing else on the card is coloured. */\nexport const SNEEK_ACCENT_DARK = '#f86513';\n/** Darkened for light mode so it clears WCAG AA as text and as a button fill. */\nexport const SNEEK_ACCENT_LIGHT = '#b83f06';\n\nexport function buildStyles(accent?: string): string {\n const darkAccent = accent ?? SNEEK_ACCENT_DARK;\n const lightAccent = accent ?? SNEEK_ACCENT_LIGHT;\n\n const light = `\n --sneek-surface: #ffffff;\n --sneek-surface-2: #f4f1ed;\n --sneek-border: #e3ddd5;\n --sneek-text: #1c1917;\n --sneek-text-muted: #57534e;\n --sneek-accent: ${lightAccent};\n --sneek-accent-soft: color-mix(in srgb, ${lightAccent} 12%, transparent);\n --sneek-accent-contrast: #ffffff;\n --sneek-danger: #b0242a;\n --sneek-shadow: 0 3px 3px -2px rgb(0 0 0 / 0.10), 0 3px 4px rgb(0 0 0 / 0.07),\n 0 1px 8px rgb(0 0 0 / 0.06);`;\n\n const dark = `\n --sneek-surface: #17150f;\n --sneek-surface-2: #201d16;\n --sneek-border: rgba(255, 255, 255, 0.08);\n --sneek-text: #faf8f6;\n --sneek-text-muted: #a8a29b;\n --sneek-accent: ${darkAccent};\n --sneek-accent-soft: color-mix(in srgb, ${darkAccent} 16%, transparent);\n --sneek-accent-contrast: #1a0d04;\n --sneek-danger: #d43a3c;\n --sneek-shadow: none;`;\n\n return `\n.sneek-otp {${light}\n --sneek-ease: cubic-bezier(0, 0, 0.2, 1);\n}\n@media (prefers-color-scheme: dark) {\n .sneek-otp:not([data-theme=\"light\"]) {${dark}\n }\n}\n.sneek-otp[data-theme=\"dark\"] {${dark}\n}\n.sneek-otp[data-theme=\"light\"] {${light}\n}\n.sneek-otp *, .sneek-otp *::before, .sneek-otp *::after { box-sizing: border-box; }\n.sneek-otp-input:focus-visible,\n.sneek-otp-button:focus-visible,\n.sneek-otp-link:focus-visible {\n outline: 2px solid var(--sneek-accent);\n outline-offset: 2px;\n}\n.sneek-otp-input:focus {\n border-color: var(--sneek-accent);\n}\n.sneek-otp-button:not(:disabled):hover {\n filter: brightness(1.08);\n}\n.sneek-otp-link:not(:disabled):hover {\n text-decoration: underline;\n}\n@media (prefers-reduced-motion: reduce) {\n .sneek-otp * { transition-duration: 0.01ms !important; }\n}\n`;\n}\n","import type { RequestOtpResult } from './state';\n\nexport interface FetchHandlerOptions {\n /**\n * Partner backend endpoint that sends an OTP. Receives `{ identifier }`,\n * must return `{ requestId, channels?, expiresInSeconds? }`.\n * @default '/api/auth/request-otp'\n */\n requestUrl?: string;\n /**\n * Partner backend endpoint that verifies an OTP. Receives\n * `{ requestId, code }`, returns whatever your app needs (session, token…).\n * @default '/api/auth/verify-otp'\n */\n verifyUrl?: string;\n /** Extra headers (e.g. CSRF token) to send on both requests. */\n headers?: Record<string, string>;\n /** Forwarded to fetch — set to 'include' if you use cookie sessions. */\n credentials?: RequestCredentials;\n}\n\nasync function postJson<T>(\n url: string,\n body: unknown,\n options: FetchHandlerOptions,\n): Promise<T> {\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', ...(options.headers ?? {}) },\n credentials: options.credentials,\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n let message = `Request failed (${response.status})`;\n try {\n const data = (await response.json()) as { message?: string; error?: string };\n message = data.message || data.error || message;\n } catch {\n // non-JSON error body — keep the status-based message\n }\n throw new Error(message);\n }\n\n return (await response.json()) as T;\n}\n\n/**\n * Build {@link SneekOtpHandlers} that POST to your own backend endpoints.\n * Those endpoints call the Sneek API server-side with your secret key.\n */\nexport function createFetchHandlers<TResult = unknown>(\n options: FetchHandlerOptions = {},\n): {\n requestOtp: (identifier: string) => Promise<RequestOtpResult>;\n verifyOtp: (input: { requestId: string; code: string }) => Promise<TResult>;\n} {\n const requestUrl = options.requestUrl ?? '/api/auth/request-otp';\n const verifyUrl = options.verifyUrl ?? '/api/auth/verify-otp';\n\n return {\n requestOtp: (identifier: string) =>\n postJson<RequestOtpResult>(requestUrl, { identifier }, options),\n verifyOtp: (input: {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rB,MAAM,KAAK,UAAU,IAAI;AAAA,EAC3B,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,QAAI,UAAU,mBAAmB,SAAS,MAAM;AAChD,QAAI;AACF,YAAM,OAAQ,MAAM,SAAS,KAAK;AAClC,gBAAU,KAAK,WAAW,KAAK,SAAS;AAAA,IAC1C,QAAQ;AAAA,IAER;AACA,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AAEA,SAAQ,MAAM,SAAS,KAAK;AAC9B;AAMO,SAAS,oBACd,UAA+B,CAAC,GAIhC;AACA,QAAM,aAAa,QAAQ,cAAc;AACzC,QAAM,YAAY,QAAQ,aAAa;AAEvC,SAAO;AAAA,IACL,YAAY,CAAC,eACX,SAA2B,YAAY,EAAE,WAAW,GAAG,OAAO;AAAA,IAChE,WAAW,CAAC,UACV,SAAkB,WAAW,OAAO,OAAO;AAAA,EAC/C;AACF;","names":["import_react"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/use-sneek-otp.ts","../src/state.ts","../src/component.tsx","../src/theme.ts","../src/fetch-handlers.ts"],"sourcesContent":["export {\n useSneekOtp,\n type SneekOtpHandlers,\n type UseSneekOtp,\n} from './use-sneek-otp';\n\nexport {\n SneekOtpLogin,\n type SneekOtpLoginProps,\n type SneekTheme,\n} from './component';\n\nexport {\n SNEEK_ACCENT_DARK,\n SNEEK_ACCENT_LIGHT,\n} from './theme';\n\nexport {\n createFetchHandlers,\n type FetchHandlerOptions,\n} from './fetch-handlers';\n\nexport {\n otpReducer,\n initialOtpState,\n formatChannels,\n type SneekChannel,\n type SneekOtpStep,\n type SneekOtpStatus,\n type SneekOtpState,\n type SneekOtpAction,\n type RequestOtpResult,\n} from './state';\n","import { useCallback, useReducer } from 'react';\nimport {\n initialOtpState,\n otpReducer,\n toMessage,\n type RequestOtpResult,\n type SneekOtpState,\n} from './state';\n\n/**\n * Partner-supplied transport. These call the *partner's own backend*, which in\n * turn talks to the Sneek API with the secret server-side key. The browser\n * never sees a Sneek API key — that is the whole security model of this package.\n */\nexport interface SneekOtpHandlers<TResult = unknown> {\n /** Ask the partner backend to send an OTP to `identifier`. */\n requestOtp: (identifier: string) => Promise<RequestOtpResult>;\n /** Verify the code with the partner backend; resolve with the auth result. */\n verifyOtp: (input: { requestId: string; code: string }) => Promise<TResult>;\n /** Called after a successful verification with the partner's result. */\n onSuccess?: (result: TResult) => void;\n /** Called on any error (request or verify). */\n onError?: (error: unknown) => void;\n}\n\nexport interface UseSneekOtp extends SneekOtpState {\n setIdentifier: (value: string) => void;\n setCode: (value: string) => void;\n /** Submit the identify step — triggers `requestOtp`. */\n sendOtp: () => Promise<void>;\n /** Submit the verify step — triggers `verifyOtp`. */\n verify: () => Promise<void>;\n /** Go back to the identify screen (e.g. \"use a different email\"). */\n back: () => void;\n /** Re-send the OTP to the same identifier. */\n resend: () => Promise<void>;\n /** Convenience booleans. */\n isSending: boolean;\n isVerifying: boolean;\n isBusy: boolean;\n}\n\nconst DEFAULT_REQUEST_ERROR = 'Could not send the code. Please try again.';\nconst DEFAULT_VERIFY_ERROR = 'That code was not correct. Please try again.';\n\n/**\n * Headless hook implementing the passwordless OTP login flow. Bring your own\n * markup, or use the {@link SneekOtpLogin} component for a styled default.\n */\nexport function useSneekOtp<TResult = unknown>(\n handlers: SneekOtpHandlers<TResult>,\n): UseSneekOtp {\n const [state, dispatch] = useReducer(otpReducer, initialOtpState);\n\n const { requestOtp, verifyOtp, onSuccess, onError } = handlers;\n\n const setIdentifier = useCallback((value: string) => {\n dispatch({ type: 'set_identifier', value });\n }, []);\n\n const setCode = useCallback((value: string) => {\n dispatch({ type: 'set_code', value });\n }, []);\n\n const runRequest = useCallback(\n async (identifier: string) => {\n const trimmed = identifier.trim();\n if (!trimmed) {\n dispatch({ type: 'request_error', message: 'Enter your email or mobile number.' });\n return;\n }\n dispatch({ type: 'request_start' });\n try {\n const result = await requestOtp(trimmed);\n dispatch({ type: 'request_success', result });\n } catch (error) {\n dispatch({ type: 'request_error', message: toMessage(error, DEFAULT_REQUEST_ERROR) });\n onError?.(error);\n }\n },\n [requestOtp, onError],\n );\n\n const sendOtp = useCallback(() => runRequest(state.identifier), [runRequest, state.identifier]);\n\n const resend = useCallback(() => runRequest(state.identifier), [runRequest, state.identifier]);\n\n const verify = useCallback(async () => {\n const code = state.code.trim();\n if (!code) {\n dispatch({ type: 'verify_error', message: 'Enter the code you received.' });\n return;\n }\n dispatch({ type: 'verify_start' });\n try {\n const result = await verifyOtp({ requestId: state.requestId, code });\n onSuccess?.(result);\n } catch (error) {\n dispatch({ type: 'verify_error', message: toMessage(error, DEFAULT_VERIFY_ERROR) });\n onError?.(error);\n }\n }, [verifyOtp, state.code, state.requestId, onSuccess, onError]);\n\n const back = useCallback(() => {\n dispatch({ type: 'back_to_identify' });\n }, []);\n\n return {\n ...state,\n setIdentifier,\n setCode,\n sendOtp,\n verify,\n back,\n resend,\n isSending: state.status === 'sending',\n isVerifying: state.status === 'verifying',\n isBusy: state.status !== 'idle',\n };\n}\n","/**\n * Framework-agnostic state machine for the Sneek passwordless OTP flow.\n *\n * Kept free of React so it can be unit-tested in isolation and reused by other\n * front-end bindings later (Vue/Svelte). The hook in `use-sneek-otp.ts` is a\n * thin wrapper around this reducer.\n */\n\nexport type SneekChannel = 'sms' | 'whatsapp' | 'email';\n\n/** Which screen of the two-step flow is showing. */\nexport type SneekOtpStep = 'identify' | 'verify';\n\n/** Async lifecycle for the in-flight request. */\nexport type SneekOtpStatus = 'idle' | 'sending' | 'verifying';\n\nexport interface SneekOtpState {\n step: SneekOtpStep;\n status: SneekOtpStatus;\n /** The email / mobile / username the user typed. */\n identifier: string;\n /** The OTP code the user typed on the verify screen. */\n code: string;\n /** Opaque id returned by the partner backend, replayed on verify. */\n requestId: string;\n /** Channels the OTP was actually delivered over. */\n channels: SneekChannel[];\n /** Seconds until the OTP expires (from the request response). */\n expiresInSeconds: number;\n /** User-facing error message, or null. */\n error: string | null;\n}\n\nexport const initialOtpState: SneekOtpState = {\n step: 'identify',\n status: 'idle',\n identifier: '',\n code: '',\n requestId: '',\n channels: [],\n expiresInSeconds: 0,\n error: null,\n};\n\nexport interface RequestOtpResult {\n requestId: string;\n channels?: SneekChannel[];\n expiresInSeconds?: number;\n}\n\nexport type SneekOtpAction =\n | { type: 'set_identifier'; value: string }\n | { type: 'set_code'; value: string }\n | { type: 'request_start' }\n | { type: 'request_success'; result: RequestOtpResult }\n | { type: 'request_error'; message: string }\n | { type: 'verify_start' }\n | { type: 'verify_error'; message: string }\n | { type: 'reset' }\n | { type: 'back_to_identify' };\n\nconst isBusy = (status: SneekOtpStatus): boolean => status !== 'idle';\n\nexport function otpReducer(\n state: SneekOtpState,\n action: SneekOtpAction,\n): SneekOtpState {\n switch (action.type) {\n case 'set_identifier':\n return { ...state, identifier: action.value, error: null };\n\n case 'set_code':\n return { ...state, code: action.value, error: null };\n\n case 'request_start':\n // Guard against double submits while a request is already in flight.\n if (isBusy(state.status)) return state;\n return { ...state, status: 'sending', error: null };\n\n case 'request_success':\n return {\n ...state,\n step: 'verify',\n status: 'idle',\n code: '',\n requestId: action.result.requestId,\n channels: action.result.channels ?? [],\n expiresInSeconds: action.result.expiresInSeconds ?? 0,\n error: null,\n };\n\n case 'request_error':\n return { ...state, status: 'idle', error: action.message };\n\n case 'verify_start':\n if (isBusy(state.status)) return state;\n return { ...state, status: 'verifying', error: null };\n\n case 'verify_error':\n return { ...state, status: 'idle', error: action.message };\n\n case 'back_to_identify':\n return {\n ...state,\n step: 'identify',\n status: 'idle',\n code: '',\n requestId: '',\n channels: [],\n expiresInSeconds: 0,\n error: null,\n };\n\n case 'reset':\n return { ...initialOtpState };\n\n default:\n return state;\n }\n}\n\nconst CHANNEL_LABELS: Record<SneekChannel, string> = {\n sms: 'SMS',\n whatsapp: 'WhatsApp',\n email: 'email',\n};\n\n/** \"SMS, WhatsApp\" — human label for the channels an OTP was sent over. */\nexport function formatChannels(channels: SneekChannel[]): string {\n return channels.map((c) => CHANNEL_LABELS[c] ?? c).join(', ');\n}\n\n/** Normalize any thrown value into a user-facing message. */\nexport function toMessage(error: unknown, fallback: string): string {\n if (error instanceof Error && error.message) return error.message;\n if (typeof error === 'string' && error) return error;\n return fallback;\n}\n","import {\n useEffect,\n useId,\n useState,\n type CSSProperties,\n type FormEvent,\n type ReactNode,\n} from 'react';\n\nimport { buildStyles, SNEEK_STYLE_ID } from './theme';\nimport { useSneekOtp, type SneekOtpHandlers } from './use-sneek-otp';\n\nexport type SneekTheme = 'auto' | 'light' | 'dark';\n\n/** Digits in a Sneek code. */\nconst CODE_LENGTH = 6;\n/** Seconds before \"Resend code\" becomes tappable again. */\nconst RESEND_SECONDS = 30;\n\nexport interface SneekOtpLoginProps<TResult = unknown>\n extends SneekOtpHandlers<TResult> {\n /** Heading above the form. @default 'Sign in' */\n title?: string;\n /** Heading once the code has been sent. @default 'Enter the code' */\n verifyTitle?: string;\n /** Sub-heading. Pass `null` to remove it. */\n subtitle?: ReactNode;\n /** Label for the identifier input. */\n identifierLabel?: string;\n /** Placeholder for the identifier input. */\n identifierPlaceholder?: string;\n /**\n * Colour scheme. `auto` follows the visitor's system setting.\n * @default 'auto'\n */\n theme?: SneekTheme;\n /**\n * Override the single accent colour. Leave unset to use Sneek orange,\n * which is tuned per mode for contrast.\n */\n accentColor?: string;\n /** Replaces the Sneek mark above the title. Pass `null` to remove it. */\n logo?: ReactNode;\n /** Show the \"Secured by Sneek\" line under the form. @default true */\n showBranding?: boolean;\n /** Style overrides for the outer card. */\n style?: CSSProperties;\n /** Extra class on the outer card. */\n className?: string;\n}\n\n/**\n * Sneek mark: two triangles offset on a diagonal — one pointing up on the\n * right, one pointing down on the left. Traced from the brand asset so the\n * package needs no image file and no CDN.\n */\nfunction SneekMark() {\n return (\n <svg\n width=\"36\"\n height=\"36\"\n viewBox=\"0 0 32 32\"\n fill=\"none\"\n role=\"img\"\n aria-label=\"Sneek\"\n >\n <path d=\"M21.3 1 29.3 16H13.3L21.3 1Z\" fill=\"var(--sneek-accent)\" />\n <path d=\"M2.7 17.5H18.7L10.7 31 2.7 17.5Z\" fill=\"var(--sneek-accent)\" />\n </svg>\n );\n}\n\n/**\n * Drop-in passwordless login card.\n *\n * The component never receives a Sneek API key — it calls the handlers you\n * supply, which talk to your own backend. See `createFetchHandlers` for the\n * common case.\n *\n * @example\n * ```tsx\n * <SneekOtpLogin\n * {...createFetchHandlers({ baseUrl: '/api/auth' })}\n * onSuccess={(session) => router.push('/app')}\n * />\n * ```\n */\nexport function SneekOtpLogin<TResult = unknown>(\n props: SneekOtpLoginProps<TResult>,\n): ReactNode {\n const {\n title = 'Sign in',\n verifyTitle = 'Enter the code',\n subtitle = 'Enter your email or phone. We will send you a code.',\n identifierLabel = 'Email or mobile',\n identifierPlaceholder = 'you@company.com or +91…',\n theme = 'auto',\n accentColor,\n logo,\n showBranding = true,\n style,\n className,\n ...handlers\n } = props;\n\n const otp = useSneekOtp<TResult>(handlers);\n const uid = useId();\n // Countdown before resend re-enables. Instant resend is both poor feedback\n // and an easy way to burn someone's SMS quota.\n const [resendIn, setResendIn] = useState(0);\n const identifierId = `${uid}-identifier`;\n const codeId = `${uid}-code`;\n const statusId = `${uid}-status`;\n\n // One <style> element for the whole page, regardless of how many cards\n // render. Injected on mount so the package stays SSR-safe.\n useEffect(() => {\n if (typeof document === 'undefined') return;\n let el = document.getElementById(SNEEK_STYLE_ID);\n if (!el) {\n el = document.createElement('style');\n el.id = SNEEK_STYLE_ID;\n document.head.appendChild(el);\n }\n el.textContent = buildStyles(accentColor);\n }, [accentColor]);\n\n const onIdentifySubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n void otp.sendOtp();\n };\n\n const onVerifySubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n void otp.verify();\n };\n\n // Start the cooldown whenever a code goes out.\n useEffect(() => {\n if (otp.step === 'verify') setResendIn(RESEND_SECONDS);\n }, [otp.step]);\n\n useEffect(() => {\n if (resendIn <= 0) return;\n const timer = setTimeout(() => setResendIn((n) => n - 1), 1000);\n return () => clearTimeout(timer);\n }, [resendIn]);\n\n // Submit as soon as the code looks complete — nobody should have to reach\n // for a button after typing the last digit.\n useEffect(() => {\n if (otp.step === 'verify' && otp.code.length === CODE_LENGTH && !otp.isBusy) {\n void otp.verify();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [otp.code, otp.step]);\n\n const label: CSSProperties = {\n display: 'flex',\n flexDirection: 'column',\n gap: 8,\n fontSize: 14,\n lineHeight: '20px',\n color: 'var(--sneek-text-muted)',\n };\n\n const input: CSSProperties = {\n padding: '12px 14px',\n border: '1px solid var(--sneek-border)',\n borderRadius: 12,\n background: 'var(--sneek-surface-2)',\n color: 'var(--sneek-text)',\n fontSize: 15,\n width: '100%',\n outline: 'none',\n transition: 'border-color 200ms var(--sneek-ease)',\n };\n\n const button: CSSProperties = {\n padding: '12px 18px',\n border: 'none',\n borderRadius: 9999,\n background: 'var(--sneek-accent)',\n color: 'var(--sneek-accent-contrast)',\n fontSize: 15,\n fontWeight: 500,\n cursor: otp.isBusy ? 'not-allowed' : 'pointer',\n opacity: otp.isBusy ? 0.6 : 1,\n width: '100%',\n transition: 'filter 200ms var(--sneek-ease), opacity 200ms var(--sneek-ease)',\n };\n\n const link: CSSProperties = {\n border: 'none',\n background: 'transparent',\n color: 'var(--sneek-accent)',\n cursor: otp.isBusy ? 'not-allowed' : 'pointer',\n font: 'inherit',\n fontSize: 14,\n padding: 0,\n };\n\n const notice: CSSProperties = {\n padding: '10px 12px',\n borderRadius: 12,\n background: 'var(--sneek-surface-2)',\n border: '1px solid var(--sneek-border)',\n fontSize: 14,\n color: 'var(--sneek-text-muted)',\n };\n\n return (\n <div\n className={className ? `sneek-otp ${className}` : 'sneek-otp'}\n data-theme={theme === 'auto' ? undefined : theme}\n style={{\n maxWidth: 400,\n margin: '0 auto',\n padding: 24,\n border: '1px solid var(--sneek-border)',\n borderRadius: 16,\n background: 'var(--sneek-surface)',\n boxShadow: 'var(--sneek-shadow)',\n color: 'var(--sneek-text)',\n fontFamily:\n 'Inter, ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif',\n lineHeight: 1.5,\n ...style,\n }}\n >\n {logo === null ? null : (logo ?? <SneekMark />)}\n <h1\n style={{\n fontSize: 21,\n lineHeight: '28px',\n fontWeight: 500,\n letterSpacing: '-0.01em',\n margin: '16px 0 0',\n }}\n >\n {otp.step === 'verify' ? verifyTitle : title}\n </h1>\n {otp.step === 'verify' ? (\n <p\n style={{\n fontSize: 14,\n lineHeight: '20px',\n color: 'var(--sneek-text-muted)',\n margin: '8px 0 0',\n }}\n >\n Sent to{' '}\n <span style={{ color: 'var(--sneek-text)' }}>{otp.identifier}</span>\n {' · '}\n <button\n type=\"button\"\n className=\"sneek-otp-link\"\n onClick={otp.back}\n disabled={otp.isBusy}\n style={{ ...link, fontSize: 14 }}\n >\n Change\n </button>\n </p>\n ) : subtitle ? (\n <p\n style={{\n fontSize: 14,\n lineHeight: '20px',\n color: 'var(--sneek-text-muted)',\n margin: '8px 0 0',\n }}\n >\n {subtitle}\n </p>\n ) : null}\n\n {/* Errors and channel notices are announced, not just shown. */}\n <div role=\"status\" aria-live=\"polite\" id={statusId} style={{ marginTop: 32 }}>\n {otp.error ? (\n <div\n role=\"alert\"\n style={{\n ...notice,\n color: 'var(--sneek-danger)',\n borderColor: 'var(--sneek-danger)',\n }}\n >\n {otp.error}\n </div>\n ) : null}\n </div>\n\n {otp.step === 'identify' ? (\n <form\n onSubmit={onIdentifySubmit}\n style={{ display: 'flex', flexDirection: 'column', gap: 16, marginTop: 16 }}\n >\n <label style={label} htmlFor={identifierId}>\n {identifierLabel}\n <input\n id={identifierId}\n className=\"sneek-otp-input\"\n type=\"text\"\n value={otp.identifier}\n onChange={(e) => otp.setIdentifier(e.target.value)}\n placeholder={identifierPlaceholder}\n autoComplete=\"username\"\n autoFocus\n required\n aria-describedby={statusId}\n style={input}\n />\n </label>\n <button\n type=\"submit\"\n className=\"sneek-otp-button\"\n disabled={otp.isBusy}\n style={button}\n >\n {otp.isSending ? 'Sending code…' : 'Send code'}\n </button>\n </form>\n ) : (\n <form\n onSubmit={onVerifySubmit}\n style={{ display: 'flex', flexDirection: 'column', gap: 16, marginTop: 16 }}\n >\n <label style={{ ...label, marginBottom: -8 }} htmlFor={codeId}>\n {CODE_LENGTH}-digit code\n </label>\n <input\n id={codeId}\n className=\"sneek-otp-input\"\n type=\"text\"\n inputMode=\"numeric\"\n pattern=\"[0-9]*\"\n autoComplete=\"one-time-code\"\n maxLength={CODE_LENGTH}\n value={otp.code}\n onChange={(e) =>\n otp.setCode(e.target.value.replace(/\\D/g, '').slice(0, CODE_LENGTH))\n }\n autoFocus\n required\n aria-describedby={statusId}\n style={{\n ...input,\n fontSize: 24,\n lineHeight: '32px',\n textAlign: 'center',\n letterSpacing: '0.4em',\n textIndent: '0.4em',\n padding: '14px',\n }}\n />\n <button\n type=\"submit\"\n className=\"sneek-otp-button\"\n disabled={otp.isBusy || otp.code.length < CODE_LENGTH}\n style={{\n ...button,\n opacity:\n otp.isBusy || otp.code.length < CODE_LENGTH ? 0.6 : 1,\n }}\n >\n {otp.isVerifying ? 'Verifying…' : 'Verify'}\n </button>\n <div style={{ textAlign: 'center' }}>\n {resendIn > 0 ? (\n <span\n style={{\n fontSize: 14,\n color: 'var(--sneek-text-muted)',\n }}\n >\n Resend code in {resendIn}s\n </span>\n ) : (\n <button\n type=\"button\"\n className=\"sneek-otp-link\"\n onClick={() => void otp.resend()}\n disabled={otp.isBusy}\n style={link}\n >\n Resend code\n </button>\n )}\n </div>\n </form>\n )}\n\n {showBranding ? (\n <p\n style={{\n margin: '32px 0 0',\n textAlign: 'center',\n fontSize: 12,\n lineHeight: '16px',\n color: 'var(--sneek-text-muted)',\n }}\n >\n Secured by Sneek\n </p>\n ) : null}\n </div>\n );\n}\n","/**\n * Theme for the drop-in login card.\n *\n * The package ships zero dependencies and no stylesheet, so the tokens are\n * injected once as CSS custom properties scoped to `.sneek-otp`. That buys two\n * things inline styles cannot: a `prefers-color-scheme` media query, and real\n * `:focus-visible` / `:hover` states.\n *\n * Light and dark are authored independently rather than one being an inversion\n * of the other. In dark, the page-to-card lightness delta carries depth and the\n * card needs no shadow; in light both are near-white, so the card takes a\n * visible border and a real shadow.\n */\nexport const SNEEK_STYLE_ID = 'sneek-otp-styles';\n\n/** Brand orange. The single accent — nothing else on the card is coloured. */\nexport const SNEEK_ACCENT_DARK = '#f86513';\n/** Darkened for light mode so it clears WCAG AA as text and as a button fill. */\nexport const SNEEK_ACCENT_LIGHT = '#b83f06';\n\nexport function buildStyles(accent?: string): string {\n const darkAccent = accent ?? SNEEK_ACCENT_DARK;\n const lightAccent = accent ?? SNEEK_ACCENT_LIGHT;\n\n const light = `\n --sneek-surface: #ffffff;\n --sneek-surface-2: #f4f1ed;\n --sneek-border: #e3ddd5;\n --sneek-text: #1c1917;\n --sneek-text-muted: #57534e;\n --sneek-accent: ${lightAccent};\n --sneek-accent-soft: color-mix(in srgb, ${lightAccent} 12%, transparent);\n --sneek-accent-contrast: #ffffff;\n --sneek-danger: #b0242a;\n --sneek-shadow: 0 3px 3px -2px rgb(0 0 0 / 0.10), 0 3px 4px rgb(0 0 0 / 0.07),\n 0 1px 8px rgb(0 0 0 / 0.06);`;\n\n const dark = `\n --sneek-surface: #17150f;\n --sneek-surface-2: #201d16;\n --sneek-border: rgba(255, 255, 255, 0.08);\n --sneek-text: #faf8f6;\n --sneek-text-muted: #a8a29b;\n --sneek-accent: ${darkAccent};\n --sneek-accent-soft: color-mix(in srgb, ${darkAccent} 16%, transparent);\n --sneek-accent-contrast: #1a0d04;\n --sneek-danger: #d43a3c;\n --sneek-shadow: none;`;\n\n return `\n.sneek-otp {${light}\n --sneek-ease: cubic-bezier(0, 0, 0.2, 1);\n}\n@media (prefers-color-scheme: dark) {\n .sneek-otp:not([data-theme=\"light\"]) {${dark}\n }\n}\n.sneek-otp[data-theme=\"dark\"] {${dark}\n}\n.sneek-otp[data-theme=\"light\"] {${light}\n}\n.sneek-otp *, .sneek-otp *::before, .sneek-otp *::after { box-sizing: border-box; }\n.sneek-otp-input:focus-visible,\n.sneek-otp-button:focus-visible,\n.sneek-otp-link:focus-visible {\n outline: 2px solid var(--sneek-accent);\n outline-offset: 2px;\n}\n.sneek-otp-input:focus {\n border-color: var(--sneek-accent);\n}\n.sneek-otp-button:not(:disabled):hover {\n filter: brightness(1.08);\n}\n.sneek-otp-link:not(:disabled):hover {\n text-decoration: underline;\n}\n@media (prefers-reduced-motion: reduce) {\n .sneek-otp * { transition-duration: 0.01ms !important; }\n}\n`;\n}\n","import type { RequestOtpResult } from './state';\n\nexport interface FetchHandlerOptions {\n /**\n * Partner backend endpoint that sends an OTP. Receives `{ identifier }`,\n * must return `{ requestId, channels?, expiresInSeconds? }`.\n * @default '/api/auth/request-otp'\n */\n requestUrl?: string;\n /**\n * Partner backend endpoint that verifies an OTP. Receives\n * `{ requestId, code }`, returns whatever your app needs (session, token…).\n * @default '/api/auth/verify-otp'\n */\n verifyUrl?: string;\n /** Extra headers (e.g. CSRF token) to send on both requests. */\n headers?: Record<string, string>;\n /** Forwarded to fetch — set to 'include' if you use cookie sessions. */\n credentials?: RequestCredentials;\n}\n\nasync function postJson<T>(\n url: string,\n body: unknown,\n options: FetchHandlerOptions,\n): Promise<T> {\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', ...(options.headers ?? {}) },\n credentials: options.credentials,\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n let message = `Request failed (${response.status})`;\n try {\n const data = (await response.json()) as { message?: string; error?: string };\n message = data.message || data.error || message;\n } catch {\n // non-JSON error body — keep the status-based message\n }\n throw new Error(message);\n }\n\n return (await response.json()) as T;\n}\n\n/**\n * Build {@link SneekOtpHandlers} that POST to your own backend endpoints.\n * Those endpoints call the Sneek API server-side with your secret key.\n */\nexport function createFetchHandlers<TResult = unknown>(\n options: FetchHandlerOptions = {},\n): {\n requestOtp: (identifier: string) => Promise<RequestOtpResult>;\n verifyOtp: (input: { requestId: string; code: string }) => Promise<TResult>;\n} {\n const requestUrl = options.requestUrl ?? '/api/auth/request-otp';\n const verifyUrl = options.verifyUrl ?? '/api/auth/verify-otp';\n\n return {\n requestOtp: (identifier: string) =>\n postJson<RequestOtpResult>(requestUrl, { identifier }, options),\n verifyOtp: (input: { requestId: string; code: string }) =>\n postJson<TResult>(verifyUrl, input, options),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAwC;;;ACiCjC,IAAM,kBAAiC;AAAA,EAC5C,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,WAAW;AAAA,EACX,UAAU,CAAC;AAAA,EACX,kBAAkB;AAAA,EAClB,OAAO;AACT;AAmBA,IAAM,SAAS,CAAC,WAAoC,WAAW;AAExD,SAAS,WACd,OACA,QACe;AACf,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,YAAY,OAAO,OAAO,OAAO,KAAK;AAAA,IAE3D,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,MAAM,OAAO,OAAO,OAAO,KAAK;AAAA,IAErD,KAAK;AAEH,UAAI,OAAO,MAAM,MAAM,EAAG,QAAO;AACjC,aAAO,EAAE,GAAG,OAAO,QAAQ,WAAW,OAAO,KAAK;AAAA,IAEpD,KAAK;AACH,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,WAAW,OAAO,OAAO;AAAA,QACzB,UAAU,OAAO,OAAO,YAAY,CAAC;AAAA,QACrC,kBAAkB,OAAO,OAAO,oBAAoB;AAAA,QACpD,OAAO;AAAA,MACT;AAAA,IAEF,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,QAAQ,QAAQ,OAAO,OAAO,Q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AAQ;AAAA,IACR,SAAS,EAAE,gBAAgB,oBAAoB,GAAI,QAAQ,WAAW,CAAC,EAAG;AAAA,IAC1E,aAAa,QAAQ;AAAA,IACrB,MAAM,KAAK,UAAU,IAAI;AAAA,EAC3B,CAAC;AAED,MAAI,CAAC,SAAS,IAAI;AAChB,QAAI,UAAU,mBAAmB,SAAS,MAAM;AAChD,QAAI;AACF,YAAM,OAAQ,MAAM,SAAS,KAAK;AAClC,gBAAU,KAAK,WAAW,KAAK,SAAS;AAAA,IAC1C,QAAQ;AAAA,IAER;AACA,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AAEA,SAAQ,MAAM,SAAS,KAAK;AAC9B;AAMO,SAAS,oBACd,UAA+B,CAAC,GAIhC;AACA,QAAM,aAAa,QAAQ,cAAc;AACzC,QAAM,YAAY,QAAQ,aAAa;AAEvC,SAAO;AAAA,IACL,YAAY,CAAC,eACX,SAA2B,YAAY,EAAE,WAAW,GAAG,OAAO;AAAA,IAChE,WAAW,CAAC,UACV,SAAkB,WAAW,OAAO,OAAO;AAAA,EAC/C;AACF;","names":["import_react"]}
|
package/dist/index.mjs
CHANGED
|
@@ -138,7 +138,8 @@ function useSneekOtp(handlers) {
|
|
|
138
138
|
// src/component.tsx
|
|
139
139
|
import {
|
|
140
140
|
useEffect,
|
|
141
|
-
useId
|
|
141
|
+
useId,
|
|
142
|
+
useState
|
|
142
143
|
} from "react";
|
|
143
144
|
|
|
144
145
|
// src/theme.ts
|
|
@@ -207,6 +208,8 @@ function buildStyles(accent) {
|
|
|
207
208
|
|
|
208
209
|
// src/component.tsx
|
|
209
210
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
211
|
+
var CODE_LENGTH = 6;
|
|
212
|
+
var RESEND_SECONDS = 30;
|
|
210
213
|
function SneekMark() {
|
|
211
214
|
return /* @__PURE__ */ jsxs(
|
|
212
215
|
"svg",
|
|
@@ -227,7 +230,8 @@ function SneekMark() {
|
|
|
227
230
|
function SneekOtpLogin(props) {
|
|
228
231
|
const {
|
|
229
232
|
title = "Sign in",
|
|
230
|
-
|
|
233
|
+
verifyTitle = "Enter the code",
|
|
234
|
+
subtitle = "Enter your email or phone. We will send you a code.",
|
|
231
235
|
identifierLabel = "Email or mobile",
|
|
232
236
|
identifierPlaceholder = "you@company.com or +91\u2026",
|
|
233
237
|
theme = "auto",
|
|
@@ -240,6 +244,7 @@ function SneekOtpLogin(props) {
|
|
|
240
244
|
} = props;
|
|
241
245
|
const otp = useSneekOtp(handlers);
|
|
242
246
|
const uid = useId();
|
|
247
|
+
const [resendIn, setResendIn] = useState(0);
|
|
243
248
|
const identifierId = `${uid}-identifier`;
|
|
244
249
|
const codeId = `${uid}-code`;
|
|
245
250
|
const statusId = `${uid}-status`;
|
|
@@ -261,6 +266,19 @@ function SneekOtpLogin(props) {
|
|
|
261
266
|
event.preventDefault();
|
|
262
267
|
void otp.verify();
|
|
263
268
|
};
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
if (otp.step === "verify") setResendIn(RESEND_SECONDS);
|
|
271
|
+
}, [otp.step]);
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
if (resendIn <= 0) return;
|
|
274
|
+
const timer = setTimeout(() => setResendIn((n) => n - 1), 1e3);
|
|
275
|
+
return () => clearTimeout(timer);
|
|
276
|
+
}, [resendIn]);
|
|
277
|
+
useEffect(() => {
|
|
278
|
+
if (otp.step === "verify" && otp.code.length === CODE_LENGTH && !otp.isBusy) {
|
|
279
|
+
void otp.verify();
|
|
280
|
+
}
|
|
281
|
+
}, [otp.code, otp.step]);
|
|
264
282
|
const label = {
|
|
265
283
|
display: "flex",
|
|
266
284
|
flexDirection: "column",
|
|
@@ -340,10 +358,37 @@ function SneekOtpLogin(props) {
|
|
|
340
358
|
letterSpacing: "-0.01em",
|
|
341
359
|
margin: "16px 0 0"
|
|
342
360
|
},
|
|
343
|
-
children: title
|
|
361
|
+
children: otp.step === "verify" ? verifyTitle : title
|
|
344
362
|
}
|
|
345
363
|
),
|
|
346
|
-
|
|
364
|
+
otp.step === "verify" ? /* @__PURE__ */ jsxs(
|
|
365
|
+
"p",
|
|
366
|
+
{
|
|
367
|
+
style: {
|
|
368
|
+
fontSize: 14,
|
|
369
|
+
lineHeight: "20px",
|
|
370
|
+
color: "var(--sneek-text-muted)",
|
|
371
|
+
margin: "8px 0 0"
|
|
372
|
+
},
|
|
373
|
+
children: [
|
|
374
|
+
"Sent to",
|
|
375
|
+
" ",
|
|
376
|
+
/* @__PURE__ */ jsx("span", { style: { color: "var(--sneek-text)" }, children: otp.identifier }),
|
|
377
|
+
" \xB7 ",
|
|
378
|
+
/* @__PURE__ */ jsx(
|
|
379
|
+
"button",
|
|
380
|
+
{
|
|
381
|
+
type: "button",
|
|
382
|
+
className: "sneek-otp-link",
|
|
383
|
+
onClick: otp.back,
|
|
384
|
+
disabled: otp.isBusy,
|
|
385
|
+
style: { ...link, fontSize: 14 },
|
|
386
|
+
children: "Change"
|
|
387
|
+
}
|
|
388
|
+
)
|
|
389
|
+
]
|
|
390
|
+
}
|
|
391
|
+
) : subtitle ? /* @__PURE__ */ jsx(
|
|
347
392
|
"p",
|
|
348
393
|
{
|
|
349
394
|
style: {
|
|
@@ -366,10 +411,7 @@ function SneekOtpLogin(props) {
|
|
|
366
411
|
},
|
|
367
412
|
children: otp.error
|
|
368
413
|
}
|
|
369
|
-
) :
|
|
370
|
-
otp.channels.length > 0 ? `Code sent by ${formatChannels(otp.channels)}.` : "We sent you a code.",
|
|
371
|
-
otp.expiresInSeconds > 0 ? ` It expires in ${Math.max(1, Math.floor(otp.expiresInSeconds / 60))} min.` : ""
|
|
372
|
-
] }) : null }),
|
|
414
|
+
) : null }),
|
|
373
415
|
otp.step === "identify" ? /* @__PURE__ */ jsxs(
|
|
374
416
|
"form",
|
|
375
417
|
{
|
|
@@ -413,60 +455,73 @@ function SneekOtpLogin(props) {
|
|
|
413
455
|
onSubmit: onVerifySubmit,
|
|
414
456
|
style: { display: "flex", flexDirection: "column", gap: 16, marginTop: 16 },
|
|
415
457
|
children: [
|
|
416
|
-
/* @__PURE__ */ jsxs("label", { style: label, htmlFor: codeId, children: [
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
"input",
|
|
420
|
-
{
|
|
421
|
-
id: codeId,
|
|
422
|
-
className: "sneek-otp-input",
|
|
423
|
-
type: "text",
|
|
424
|
-
inputMode: "numeric",
|
|
425
|
-
autoComplete: "one-time-code",
|
|
426
|
-
value: otp.code,
|
|
427
|
-
onChange: (e) => otp.setCode(e.target.value),
|
|
428
|
-
placeholder: "6-digit code",
|
|
429
|
-
autoFocus: true,
|
|
430
|
-
required: true,
|
|
431
|
-
"aria-describedby": statusId,
|
|
432
|
-
style: { ...input, letterSpacing: "0.3em" }
|
|
433
|
-
}
|
|
434
|
-
)
|
|
458
|
+
/* @__PURE__ */ jsxs("label", { style: { ...label, marginBottom: -8 }, htmlFor: codeId, children: [
|
|
459
|
+
CODE_LENGTH,
|
|
460
|
+
"-digit code"
|
|
435
461
|
] }),
|
|
462
|
+
/* @__PURE__ */ jsx(
|
|
463
|
+
"input",
|
|
464
|
+
{
|
|
465
|
+
id: codeId,
|
|
466
|
+
className: "sneek-otp-input",
|
|
467
|
+
type: "text",
|
|
468
|
+
inputMode: "numeric",
|
|
469
|
+
pattern: "[0-9]*",
|
|
470
|
+
autoComplete: "one-time-code",
|
|
471
|
+
maxLength: CODE_LENGTH,
|
|
472
|
+
value: otp.code,
|
|
473
|
+
onChange: (e) => otp.setCode(e.target.value.replace(/\D/g, "").slice(0, CODE_LENGTH)),
|
|
474
|
+
autoFocus: true,
|
|
475
|
+
required: true,
|
|
476
|
+
"aria-describedby": statusId,
|
|
477
|
+
style: {
|
|
478
|
+
...input,
|
|
479
|
+
fontSize: 24,
|
|
480
|
+
lineHeight: "32px",
|
|
481
|
+
textAlign: "center",
|
|
482
|
+
letterSpacing: "0.4em",
|
|
483
|
+
textIndent: "0.4em",
|
|
484
|
+
padding: "14px"
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
),
|
|
436
488
|
/* @__PURE__ */ jsx(
|
|
437
489
|
"button",
|
|
438
490
|
{
|
|
439
491
|
type: "submit",
|
|
440
492
|
className: "sneek-otp-button",
|
|
441
|
-
disabled: otp.isBusy,
|
|
442
|
-
style:
|
|
443
|
-
|
|
493
|
+
disabled: otp.isBusy || otp.code.length < CODE_LENGTH,
|
|
494
|
+
style: {
|
|
495
|
+
...button,
|
|
496
|
+
opacity: otp.isBusy || otp.code.length < CODE_LENGTH ? 0.6 : 1
|
|
497
|
+
},
|
|
498
|
+
children: otp.isVerifying ? "Verifying\u2026" : "Verify"
|
|
444
499
|
}
|
|
445
500
|
),
|
|
446
|
-
/* @__PURE__ */
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
{
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
501
|
+
/* @__PURE__ */ jsx("div", { style: { textAlign: "center" }, children: resendIn > 0 ? /* @__PURE__ */ jsxs(
|
|
502
|
+
"span",
|
|
503
|
+
{
|
|
504
|
+
style: {
|
|
505
|
+
fontSize: 14,
|
|
506
|
+
color: "var(--sneek-text-muted)"
|
|
507
|
+
},
|
|
508
|
+
children: [
|
|
509
|
+
"Resend code in ",
|
|
510
|
+
resendIn,
|
|
511
|
+
"s"
|
|
512
|
+
]
|
|
513
|
+
}
|
|
514
|
+
) : /* @__PURE__ */ jsx(
|
|
515
|
+
"button",
|
|
516
|
+
{
|
|
517
|
+
type: "button",
|
|
518
|
+
className: "sneek-otp-link",
|
|
519
|
+
onClick: () => void otp.resend(),
|
|
520
|
+
disabled: otp.isBusy,
|
|
521
|
+
style: link,
|
|
522
|
+
children: "Resend code"
|
|
523
|
+
}
|
|
524
|
+
) })
|
|
470
525
|
]
|
|
471
526
|
}
|
|
472
527
|
),
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/use-sneek-otp.ts","../src/state.ts","../src/component.tsx","../src/theme.ts","../src/fetch-handlers.ts"],"sourcesContent":["import { useCallback, useReducer } from 'react';\nimport {\n initialOtpState,\n otpReducer,\n toMessage,\n type RequestOtpResult,\n type SneekOtpState,\n} from './state';\n\n/**\n * Partner-supplied transport. These call the *partner's own backend*, which in\n * turn talks to the Sneek API with the secret server-side key. The browser\n * never sees a Sneek API key — that is the whole security model of this package.\n */\nexport interface SneekOtpHandlers<TResult = unknown> {\n /** Ask the partner backend to send an OTP to `identifier`. */\n requestOtp: (identifier: string) => Promise<RequestOtpResult>;\n /** Verify the code with the partner backend; resolve with the auth result. */\n verifyOtp: (input: { requestId: string; code: string }) => Promise<TResult>;\n /** Called after a successful verification with the partner's result. */\n onSuccess?: (result: TResult) => void;\n /** Called on any error (request or verify). */\n onError?: (error: unknown) => void;\n}\n\nexport interface UseSneekOtp extends SneekOtpState {\n setIdentifier: (value: string) => void;\n setCode: (value: string) => void;\n /** Submit the identify step — triggers `requestOtp`. */\n sendOtp: () => Promise<void>;\n /** Submit the verify step — triggers `verifyOtp`. */\n verify: () => Promise<void>;\n /** Go back to the identify screen (e.g. \"use a different email\"). */\n back: () => void;\n /** Re-send the OTP to the same identifier. */\n resend: () => Promise<void>;\n /** Convenience booleans. */\n isSending: boolean;\n isVerifying: boolean;\n isBusy: boolean;\n}\n\nconst DEFAULT_REQUEST_ERROR = 'Could not send the code. Please try again.';\nconst DEFAULT_VERIFY_ERROR = 'That code was not correct. Please try again.';\n\n/**\n * Headless hook implementing the passwordless OTP login flow. Bring your own\n * markup, or use the {@link SneekOtpLogin} component for a styled default.\n */\nexport function useSneekOtp<TResult = unknown>(\n handlers: SneekOtpHandlers<TResult>,\n): UseSneekOtp {\n const [state, dispatch] = useReducer(otpReducer, initialOtpState);\n\n const { requestOtp, verifyOtp, onSuccess, onError } = handlers;\n\n const setIdentifier = useCallback((value: string) => {\n dispatch({ type: 'set_identifier', value });\n }, []);\n\n const setCode = useCallback((value: string) => {\n dispatch({ type: 'set_code', value });\n }, []);\n\n const runRequest = useCallback(\n async (identifier: string) => {\n const trimmed = identifier.trim();\n if (!trimmed) {\n dispatch({ type: 'request_error', message: 'Enter your email or mobile number.' });\n return;\n }\n dispatch({ type: 'request_start' });\n try {\n const result = await requestOtp(trimmed);\n dispatch({ type: 'request_success', result });\n } catch (error) {\n dispatch({ type: 'request_error', message: toMessage(error, DEFAULT_REQUEST_ERROR) });\n onError?.(error);\n }\n },\n [requestOtp, onError],\n );\n\n const sendOtp = useCallback(() => runRequest(state.identifier), [runRequest, state.identifier]);\n\n const resend = useCallback(() => runRequest(state.identifier), [runRequest, state.identifier]);\n\n const verify = useCallback(async () => {\n const code = state.code.trim();\n if (!code) {\n dispatch({ type: 'verify_error', message: 'Enter the code you received.' });\n return;\n }\n dispatch({ type: 'verify_start' });\n try {\n const result = await verifyOtp({ requestId: state.requestId, code });\n onSuccess?.(result);\n } catch (error) {\n dispatch({ type: 'verify_error', message: toMessage(error, DEFAULT_VERIFY_ERROR) });\n onError?.(error);\n }\n }, [verifyOtp, state.code, state.requestId, onSuccess, onError]);\n\n const back = useCallback(() => {\n dispatch({ type: 'back_to_identify' });\n }, []);\n\n return {\n ...state,\n setIdentifier,\n setCode,\n sendOtp,\n verify,\n back,\n resend,\n isSending: state.status === 'sending',\n isVerifying: state.status === 'verifying',\n isBusy: state.status !== 'idle',\n };\n}\n","/**\n * Framework-agnostic state machine for the Sneek passwordless OTP flow.\n *\n * Kept free of React so it can be unit-tested in isolation and reused by other\n * front-end bindings later (Vue/Svelte). The hook in `use-sneek-otp.ts` is a\n * thin wrapper around this reducer.\n */\n\nexport type SneekChannel = 'sms' | 'whatsapp' | 'email';\n\n/** Which screen of the two-step flow is showing. */\nexport type SneekOtpStep = 'identify' | 'verify';\n\n/** Async lifecycle for the in-flight request. */\nexport type SneekOtpStatus = 'idle' | 'sending' | 'verifying';\n\nexport interface SneekOtpState {\n step: SneekOtpStep;\n status: SneekOtpStatus;\n /** The email / mobile / username the user typed. */\n identifier: string;\n /** The OTP code the user typed on the verify screen. */\n code: string;\n /** Opaque id returned by the partner backend, replayed on verify. */\n requestId: string;\n /** Channels the OTP was actually delivered over. */\n channels: SneekChannel[];\n /** Seconds until the OTP expires (from the request response). */\n expiresInSeconds: number;\n /** User-facing error message, or null. */\n error: string | null;\n}\n\nexport const initialOtpState: SneekOtpState = {\n step: 'identify',\n status: 'idle',\n identifier: '',\n code: '',\n requestId: '',\n channels: [],\n expiresInSeconds: 0,\n error: null,\n};\n\nexport interface RequestOtpResult {\n requestId: string;\n channels?: SneekChannel[];\n expiresInSeconds?: number;\n}\n\nexport type SneekOtpAction =\n | { type: 'set_identifier'; value: string }\n | { type: 'set_code'; value: string }\n | { type: 'request_start' }\n | { type: 'request_success'; result: RequestOtpResult }\n | { type: 'request_error'; message: string }\n | { type: 'verify_start' }\n | { type: 'verify_error'; message: string }\n | { type: 'reset' }\n | { type: 'back_to_identify' };\n\nconst isBusy = (status: SneekOtpStatus): boolean => status !== 'idle';\n\nexport function otpReducer(\n state: SneekOtpState,\n action: SneekOtpAction,\n): SneekOtpState {\n switch (action.type) {\n case 'set_identifier':\n return { ...state, identifier: action.value, error: null };\n\n case 'set_code':\n return { ...state, code: action.value, error: null };\n\n case 'request_start':\n // Guard against double submits while a request is already in flight.\n if (isBusy(state.status)) return state;\n return { ...state, status: 'sending', error: null };\n\n case 'request_success':\n return {\n ...state,\n step: 'verify',\n status: 'idle',\n code: '',\n requestId: action.result.requestId,\n channels: action.result.channels ?? [],\n expiresInSeconds: action.result.expiresInSeconds ?? 0,\n error: null,\n };\n\n case 'request_error':\n return { ...state, status: 'idle', error: action.message };\n\n case 'verify_start':\n if (isBusy(state.status)) return state;\n return { ...state, status: 'verifying', error: null };\n\n case 'verify_error':\n return { ...state, status: 'idle', error: action.message };\n\n case 'back_to_identify':\n return {\n ...state,\n step: 'identify',\n status: 'idle',\n code: '',\n requestId: '',\n channels: [],\n expiresInSeconds: 0,\n error: null,\n };\n\n case 'reset':\n return { ...initialOtpState };\n\n default:\n return state;\n }\n}\n\nconst CHANNEL_LABELS: Record<SneekChannel, string> = {\n sms: 'SMS',\n whatsapp: 'WhatsApp',\n email: 'email',\n};\n\n/** \"SMS, WhatsApp\" — human label for the channels an OTP was sent over. */\nexport function formatChannels(channels: SneekChannel[]): string {\n return channels.map((c) => CHANNEL_LABELS[c] ?? c).join(', ');\n}\n\n/** Normalize any thrown value into a user-facing message. */\nexport function toMessage(error: unknown, fallback: string): string {\n if (error instanceof Error && error.message) return error.message;\n if (typeof error === 'string' && error) return error;\n return fallback;\n}\n","import {\n useEffect,\n useId,\n type CSSProperties,\n type FormEvent,\n type ReactNode,\n} from 'react';\nimport { formatChannels } from './state';\nimport { buildStyles, SNEEK_STYLE_ID } from './theme';\nimport { useSneekOtp, type SneekOtpHandlers } from './use-sneek-otp';\n\nexport type SneekTheme = 'auto' | 'light' | 'dark';\n\nexport interface SneekOtpLoginProps<TResult = unknown>\n extends SneekOtpHandlers<TResult> {\n /** Heading above the form. @default 'Sign in' */\n title?: string;\n /** Sub-heading. Pass `null` to remove it. */\n subtitle?: ReactNode;\n /** Label for the identifier input. */\n identifierLabel?: string;\n /** Placeholder for the identifier input. */\n identifierPlaceholder?: string;\n /**\n * Colour scheme. `auto` follows the visitor's system setting.\n * @default 'auto'\n */\n theme?: SneekTheme;\n /**\n * Override the single accent colour. Leave unset to use Sneek orange,\n * which is tuned per mode for contrast.\n */\n accentColor?: string;\n /** Replaces the Sneek mark above the title. Pass `null` to remove it. */\n logo?: ReactNode;\n /** Show the \"Secured by Sneek\" line under the form. @default true */\n showBranding?: boolean;\n /** Style overrides for the outer card. */\n style?: CSSProperties;\n /** Extra class on the outer card. */\n className?: string;\n}\n\n/**\n * Sneek mark: two triangles offset on a diagonal — one pointing up on the\n * right, one pointing down on the left. Traced from the brand asset so the\n * package needs no image file and no CDN.\n */\nfunction SneekMark() {\n return (\n <svg\n width=\"36\"\n height=\"36\"\n viewBox=\"0 0 32 32\"\n fill=\"none\"\n role=\"img\"\n aria-label=\"Sneek\"\n >\n <path d=\"M21.3 1 29.3 16H13.3L21.3 1Z\" fill=\"var(--sneek-accent)\" />\n <path d=\"M2.7 17.5H18.7L10.7 31 2.7 17.5Z\" fill=\"var(--sneek-accent)\" />\n </svg>\n );\n}\n\n/**\n * Drop-in passwordless login card.\n *\n * The component never receives a Sneek API key — it calls the handlers you\n * supply, which talk to your own backend. See `createFetchHandlers` for the\n * common case.\n *\n * @example\n * ```tsx\n * <SneekOtpLogin\n * {...createFetchHandlers({ baseUrl: '/api/auth' })}\n * onSuccess={(session) => router.push('/app')}\n * />\n * ```\n */\nexport function SneekOtpLogin<TResult = unknown>(\n props: SneekOtpLoginProps<TResult>,\n): ReactNode {\n const {\n title = 'Sign in',\n subtitle = 'We will send you a one-time code.',\n identifierLabel = 'Email or mobile',\n identifierPlaceholder = 'you@company.com or +91…',\n theme = 'auto',\n accentColor,\n logo,\n showBranding = true,\n style,\n className,\n ...handlers\n } = props;\n\n const otp = useSneekOtp<TResult>(handlers);\n const uid = useId();\n const identifierId = `${uid}-identifier`;\n const codeId = `${uid}-code`;\n const statusId = `${uid}-status`;\n\n // One <style> element for the whole page, regardless of how many cards\n // render. Injected on mount so the package stays SSR-safe.\n useEffect(() => {\n if (typeof document === 'undefined') return;\n let el = document.getElementById(SNEEK_STYLE_ID);\n if (!el) {\n el = document.createElement('style');\n el.id = SNEEK_STYLE_ID;\n document.head.appendChild(el);\n }\n el.textContent = buildStyles(accentColor);\n }, [accentColor]);\n\n const onIdentifySubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n void otp.sendOtp();\n };\n\n const onVerifySubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n void otp.verify();\n };\n\n const label: CSSProperties = {\n display: 'flex',\n flexDirection: 'column',\n gap: 8,\n fontSize: 14,\n lineHeight: '20px',\n color: 'var(--sneek-text-muted)',\n };\n\n const input: CSSProperties = {\n padding: '12px 14px',\n border: '1px solid var(--sneek-border)',\n borderRadius: 12,\n background: 'var(--sneek-surface-2)',\n color: 'var(--sneek-text)',\n fontSize: 15,\n width: '100%',\n outline: 'none',\n transition: 'border-color 200ms var(--sneek-ease)',\n };\n\n const button: CSSProperties = {\n padding: '12px 18px',\n border: 'none',\n borderRadius: 9999,\n background: 'var(--sneek-accent)',\n color: 'var(--sneek-accent-contrast)',\n fontSize: 15,\n fontWeight: 500,\n cursor: otp.isBusy ? 'not-allowed' : 'pointer',\n opacity: otp.isBusy ? 0.6 : 1,\n width: '100%',\n transition: 'filter 200ms var(--sneek-ease), opacity 200ms var(--sneek-ease)',\n };\n\n const link: CSSProperties = {\n border: 'none',\n background: 'transparent',\n color: 'var(--sneek-accent)',\n cursor: otp.isBusy ? 'not-allowed' : 'pointer',\n font: 'inherit',\n fontSize: 14,\n padding: 0,\n };\n\n const notice: CSSProperties = {\n padding: '10px 12px',\n borderRadius: 12,\n background: 'var(--sneek-surface-2)',\n border: '1px solid var(--sneek-border)',\n fontSize: 14,\n color: 'var(--sneek-text-muted)',\n };\n\n return (\n <div\n className={className ? `sneek-otp ${className}` : 'sneek-otp'}\n data-theme={theme === 'auto' ? undefined : theme}\n style={{\n maxWidth: 400,\n margin: '0 auto',\n padding: 24,\n border: '1px solid var(--sneek-border)',\n borderRadius: 16,\n background: 'var(--sneek-surface)',\n boxShadow: 'var(--sneek-shadow)',\n color: 'var(--sneek-text)',\n fontFamily:\n 'Inter, ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif',\n lineHeight: 1.5,\n ...style,\n }}\n >\n {logo === null ? null : (logo ?? <SneekMark />)}\n <h1\n style={{\n fontSize: 21,\n lineHeight: '28px',\n fontWeight: 500,\n letterSpacing: '-0.01em',\n margin: '16px 0 0',\n }}\n >\n {title}\n </h1>\n {subtitle ? (\n <p\n style={{\n fontSize: 14,\n lineHeight: '20px',\n color: 'var(--sneek-text-muted)',\n margin: '8px 0 0',\n }}\n >\n {subtitle}\n </p>\n ) : null}\n\n {/* Errors and channel notices are announced, not just shown. */}\n <div role=\"status\" aria-live=\"polite\" id={statusId} style={{ marginTop: 32 }}>\n {otp.error ? (\n <div\n role=\"alert\"\n style={{\n ...notice,\n color: 'var(--sneek-danger)',\n borderColor: 'var(--sneek-danger)',\n }}\n >\n {otp.error}\n </div>\n ) : otp.step === 'verify' ? (\n <div style={notice}>\n {otp.channels.length > 0\n ? `Code sent by ${formatChannels(otp.channels)}.`\n : 'We sent you a code.'}\n {otp.expiresInSeconds > 0\n ? ` It expires in ${Math.max(1, Math.floor(otp.expiresInSeconds / 60))} min.`\n : ''}\n </div>\n ) : null}\n </div>\n\n {otp.step === 'identify' ? (\n <form\n onSubmit={onIdentifySubmit}\n style={{ display: 'flex', flexDirection: 'column', gap: 16, marginTop: 16 }}\n >\n <label style={label} htmlFor={identifierId}>\n {identifierLabel}\n <input\n id={identifierId}\n className=\"sneek-otp-input\"\n type=\"text\"\n value={otp.identifier}\n onChange={(e) => otp.setIdentifier(e.target.value)}\n placeholder={identifierPlaceholder}\n autoComplete=\"username\"\n autoFocus\n required\n aria-describedby={statusId}\n style={input}\n />\n </label>\n <button\n type=\"submit\"\n className=\"sneek-otp-button\"\n disabled={otp.isBusy}\n style={button}\n >\n {otp.isSending ? 'Sending code…' : 'Send code'}\n </button>\n </form>\n ) : (\n <form\n onSubmit={onVerifySubmit}\n style={{ display: 'flex', flexDirection: 'column', gap: 16, marginTop: 16 }}\n >\n <label style={label} htmlFor={codeId}>\n Verification code\n <input\n id={codeId}\n className=\"sneek-otp-input\"\n type=\"text\"\n inputMode=\"numeric\"\n autoComplete=\"one-time-code\"\n value={otp.code}\n onChange={(e) => otp.setCode(e.target.value)}\n placeholder=\"6-digit code\"\n autoFocus\n required\n aria-describedby={statusId}\n style={{ ...input, letterSpacing: '0.3em' }}\n />\n </label>\n <button\n type=\"submit\"\n className=\"sneek-otp-button\"\n disabled={otp.isBusy}\n style={button}\n >\n {otp.isVerifying ? 'Verifying…' : 'Verify and sign in'}\n </button>\n <div style={{ display: 'flex', justifyContent: 'space-between', gap: 12 }}>\n <button\n type=\"button\"\n className=\"sneek-otp-link\"\n onClick={otp.back}\n disabled={otp.isBusy}\n style={link}\n >\n Use a different contact\n </button>\n <button\n type=\"button\"\n className=\"sneek-otp-link\"\n onClick={() => void otp.resend()}\n disabled={otp.isBusy}\n style={link}\n >\n Resend code\n </button>\n </div>\n </form>\n )}\n\n {showBranding ? (\n <p\n style={{\n margin: '32px 0 0',\n textAlign: 'center',\n fontSize: 12,\n lineHeight: '16px',\n color: 'var(--sneek-text-muted)',\n }}\n >\n Secured by Sneek\n </p>\n ) : null}\n </div>\n );\n}\n","/**\n * Theme for the drop-in login card.\n *\n * The package ships zero dependencies and no stylesheet, so the tokens are\n * injected once as CSS custom properties scoped to `.sneek-otp`. That buys two\n * things inline styles cannot: a `prefers-color-scheme` media query, and real\n * `:focus-visible` / `:hover` states.\n *\n * Light and dark are authored independently rather than one being an inversion\n * of the other. In dark, the page-to-card lightness delta carries depth and the\n * card needs no shadow; in light both are near-white, so the card takes a\n * visible border and a real shadow.\n */\nexport const SNEEK_STYLE_ID = 'sneek-otp-styles';\n\n/** Brand orange. The single accent — nothing else on the card is coloured. */\nexport const SNEEK_ACCENT_DARK = '#f86513';\n/** Darkened for light mode so it clears WCAG AA as text and as a button fill. */\nexport const SNEEK_ACCENT_LIGHT = '#b83f06';\n\nexport function buildStyles(accent?: string): string {\n const darkAccent = accent ?? SNEEK_ACCENT_DARK;\n const lightAccent = accent ?? SNEEK_ACCENT_LIGHT;\n\n const light = `\n --sneek-surface: #ffffff;\n --sneek-surface-2: #f4f1ed;\n --sneek-border: #e3ddd5;\n --sneek-text: #1c1917;\n --sneek-text-muted: #57534e;\n --sneek-accent: ${lightAccent};\n --sneek-accent-soft: color-mix(in srgb, ${lightAccent} 12%, transparent);\n --sneek-accent-contrast: #ffffff;\n --sneek-danger: #b0242a;\n --sneek-shadow: 0 3px 3px -2px rgb(0 0 0 / 0.10), 0 3px 4px rgb(0 0 0 / 0.07),\n 0 1px 8px rgb(0 0 0 / 0.06);`;\n\n const dark = `\n --sneek-surface: #17150f;\n --sneek-surface-2: #201d16;\n --sneek-border: rgba(255, 255, 255, 0.08);\n --sneek-text: #faf8f6;\n --sneek-text-muted: #a8a29b;\n --sneek-accent: ${darkAccent};\n --sneek-accent-soft: color-mix(in srgb, ${darkAccent} 16%, transparent);\n --sneek-accent-contrast: #1a0d04;\n --sneek-danger: #d43a3c;\n --sneek-shadow: none;`;\n\n return `\n.sneek-otp {${light}\n --sneek-ease: cubic-bezier(0, 0, 0.2, 1);\n}\n@media (prefers-color-scheme: dark) {\n .sneek-otp:not([data-theme=\"light\"]) {${dark}\n }\n}\n.sneek-otp[data-theme=\"dark\"] {${dark}\n}\n.sneek-otp[data-theme=\"light\"] {${light}\n}\n.sneek-otp *, .sneek-otp *::before, .sneek-otp *::after { box-sizing: border-box; }\n.sneek-otp-input:focus-visible,\n.sneek-otp-button:focus-visible,\n.sneek-otp-link:focus-visible {\n outline: 2px solid var(--sneek-accent);\n outline-offset: 2px;\n}\n.sneek-otp-input:focus {\n border-color: var(--sneek-accent);\n}\n.sneek-otp-button:not(:disabled):hover {\n filter: brightness(1.08);\n}\n.sneek-otp-link:not(:disabled):hover {\n text-decoration: underline;\n}\n@media (prefers-reduced-motion: reduce) {\n .sneek-otp * { transition-duration: 0.01ms !important; }\n}\n`;\n}\n","import type { RequestOtpResult } from './state';\n\nexport interface FetchHandlerOptions {\n /**\n * Partner backend endpoint that sends an OTP. Receives `{ identifier }`,\n * must return `{ requestId, channels?, expiresInSeconds? }`.\n * @default '/api/auth/request-otp'\n */\n requestUrl?: string;\n /**\n * Partner backend endpoint that verifies an OTP. Receives\n * `{ requestId, code }`, returns whatever your app needs (session, token…).\n * @default '/api/auth/verify-otp'\n */\n verifyUrl?: string;\n /** Extra headers (e.g. CSRF token) to send on both requests. */\n headers?: Record<string, string>;\n /** Forwarded to fetch — set to 'include' if you use cookie sessions. */\n credentials?: RequestCredentials;\n}\n\nasync function postJson<T>(\n url: string,\n body: unknown,\n options: FetchHandlerOptions,\n): Promise<T> {\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', ...(options.headers ?? {}) },\n credentials: options.credentials,\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n let message = `Request failed (${response.status})`;\n try {\n const data = (await response.json()) as { message?: string; error?: string };\n message = data.message || data.error || message;\n } catch {\n // non-JSON error body — keep the status-based message\n }\n throw new Error(message);\n }\n\n return (await response.json()) as T;\n}\n\n/**\n * Build {@link SneekOtpHandlers} that POST to your own backend endpoints.\n * Those endpoints call the Sneek API server-side with your secret key.\n */\nexport function createFetchHandlers<TResult = unknown>(\n options: FetchHandlerOptions = {},\n): {\n requestOtp: (identifier: string) => Promise<RequestOtpResult>;\n verifyOtp: (input: { requestId: string; code: string }) => Promise<TResult>;\n} {\n const requestUrl = options.requestUrl ?? '/api/auth/request-otp';\n const verifyUrl = options.verifyUrl ?? '/api/auth/verify-otp';\n\n return {\n requestOtp: (identifier: string) =>\n postJson<RequestOtpResult>(requestUrl, { identifier }, options),\n verifyOtp: (input: { requestId: string; code: string }) =>\n postJson<TResult>(verifyUrl, input, options),\n };\n}\n"],"mappings":";AAAA,SAAS,aAAa,kBAAkB;;;ACiCjC,IAAM,kBAAiC;AAAA,EAC5C,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,WAAW;AAAA,EACX,UAAU,CAAC;AAAA,EACX,kBAAkB;AAAA,EAClB,OAAO;AACT;AAmBA,IAAM,SAAS,CAAC,WAAoC,WAAW;AAExD,SAAS,WACd,OACA,QACe;AACf,UAAQ,OAAO,MAAM;AAAA,IACn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L,YAAY,CAAC,eACX,SAA2B,YAAY,EAAE,WAAW,GAAG,OAAO;AAAA,IAChE,WAAW,CAAC,UACV,SAAkB,WAAW,OAAO,OAAO;AAAA,EAC/C;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/use-sneek-otp.ts","../src/state.ts","../src/component.tsx","../src/theme.ts","../src/fetch-handlers.ts"],"sourcesContent":["import { useCallback, useReducer } from 'react';\nimport {\n initialOtpState,\n otpReducer,\n toMessage,\n type RequestOtpResult,\n type SneekOtpState,\n} from './state';\n\n/**\n * Partner-supplied transport. These call the *partner's own backend*, which in\n * turn talks to the Sneek API with the secret server-side key. The browser\n * never sees a Sneek API key — that is the whole security model of this package.\n */\nexport interface SneekOtpHandlers<TResult = unknown> {\n /** Ask the partner backend to send an OTP to `identifier`. */\n requestOtp: (identifier: string) => Promise<RequestOtpResult>;\n /** Verify the code with the partner backend; resolve with the auth result. */\n verifyOtp: (input: { requestId: string; code: string }) => Promise<TResult>;\n /** Called after a successful verification with the partner's result. */\n onSuccess?: (result: TResult) => void;\n /** Called on any error (request or verify). */\n onError?: (error: unknown) => void;\n}\n\nexport interface UseSneekOtp extends SneekOtpState {\n setIdentifier: (value: string) => void;\n setCode: (value: string) => void;\n /** Submit the identify step — triggers `requestOtp`. */\n sendOtp: () => Promise<void>;\n /** Submit the verify step — triggers `verifyOtp`. */\n verify: () => Promise<void>;\n /** Go back to the identify screen (e.g. \"use a different email\"). */\n back: () => void;\n /** Re-send the OTP to the same identifier. */\n resend: () => Promise<void>;\n /** Convenience booleans. */\n isSending: boolean;\n isVerifying: boolean;\n isBusy: boolean;\n}\n\nconst DEFAULT_REQUEST_ERROR = 'Could not send the code. Please try again.';\nconst DEFAULT_VERIFY_ERROR = 'That code was not correct. Please try again.';\n\n/**\n * Headless hook implementing the passwordless OTP login flow. Bring your own\n * markup, or use the {@link SneekOtpLogin} component for a styled default.\n */\nexport function useSneekOtp<TResult = unknown>(\n handlers: SneekOtpHandlers<TResult>,\n): UseSneekOtp {\n const [state, dispatch] = useReducer(otpReducer, initialOtpState);\n\n const { requestOtp, verifyOtp, onSuccess, onError } = handlers;\n\n const setIdentifier = useCallback((value: string) => {\n dispatch({ type: 'set_identifier', value });\n }, []);\n\n const setCode = useCallback((value: string) => {\n dispatch({ type: 'set_code', value });\n }, []);\n\n const runRequest = useCallback(\n async (identifier: string) => {\n const trimmed = identifier.trim();\n if (!trimmed) {\n dispatch({ type: 'request_error', message: 'Enter your email or mobile number.' });\n return;\n }\n dispatch({ type: 'request_start' });\n try {\n const result = await requestOtp(trimmed);\n dispatch({ type: 'request_success', result });\n } catch (error) {\n dispatch({ type: 'request_error', message: toMessage(error, DEFAULT_REQUEST_ERROR) });\n onError?.(error);\n }\n },\n [requestOtp, onError],\n );\n\n const sendOtp = useCallback(() => runRequest(state.identifier), [runRequest, state.identifier]);\n\n const resend = useCallback(() => runRequest(state.identifier), [runRequest, state.identifier]);\n\n const verify = useCallback(async () => {\n const code = state.code.trim();\n if (!code) {\n dispatch({ type: 'verify_error', message: 'Enter the code you received.' });\n return;\n }\n dispatch({ type: 'verify_start' });\n try {\n const result = await verifyOtp({ requestId: state.requestId, code });\n onSuccess?.(result);\n } catch (error) {\n dispatch({ type: 'verify_error', message: toMessage(error, DEFAULT_VERIFY_ERROR) });\n onError?.(error);\n }\n }, [verifyOtp, state.code, state.requestId, onSuccess, onError]);\n\n const back = useCallback(() => {\n dispatch({ type: 'back_to_identify' });\n }, []);\n\n return {\n ...state,\n setIdentifier,\n setCode,\n sendOtp,\n verify,\n back,\n resend,\n isSending: state.status === 'sending',\n isVerifying: state.status === 'verifying',\n isBusy: state.status !== 'idle',\n };\n}\n","/**\n * Framework-agnostic state machine for the Sneek passwordless OTP flow.\n *\n * Kept free of React so it can be unit-tested in isolation and reused by other\n * front-end bindings later (Vue/Svelte). The hook in `use-sneek-otp.ts` is a\n * thin wrapper around this reducer.\n */\n\nexport type SneekChannel = 'sms' | 'whatsapp' | 'email';\n\n/** Which screen of the two-step flow is showing. */\nexport type SneekOtpStep = 'identify' | 'verify';\n\n/** Async lifecycle for the in-flight request. */\nexport type SneekOtpStatus = 'idle' | 'sending' | 'verifying';\n\nexport interface SneekOtpState {\n step: SneekOtpStep;\n status: SneekOtpStatus;\n /** The email / mobile / username the user typed. */\n identifier: string;\n /** The OTP code the user typed on the verify screen. */\n code: string;\n /** Opaque id returned by the partner backend, replayed on verify. */\n requestId: string;\n /** Channels the OTP was actually delivered over. */\n channels: SneekChannel[];\n /** Seconds until the OTP expires (from the request response). */\n expiresInSeconds: number;\n /** User-facing error message, or null. */\n error: string | null;\n}\n\nexport const initialOtpState: SneekOtpState = {\n step: 'identify',\n status: 'idle',\n identifier: '',\n code: '',\n requestId: '',\n channels: [],\n expiresInSeconds: 0,\n error: null,\n};\n\nexport interface RequestOtpResult {\n requestId: string;\n channels?: SneekChannel[];\n expiresInSeconds?: number;\n}\n\nexport type SneekOtpAction =\n | { type: 'set_identifier'; value: string }\n | { type: 'set_code'; value: string }\n | { type: 'request_start' }\n | { type: 'request_success'; result: RequestOtpResult }\n | { type: 'request_error'; message: string }\n | { type: 'verify_start' }\n | { type: 'verify_error'; message: string }\n | { type: 'reset' }\n | { type: 'back_to_identify' };\n\nconst isBusy = (status: SneekOtpStatus): boolean => status !== 'idle';\n\nexport function otpReducer(\n state: SneekOtpState,\n action: SneekOtpAction,\n): SneekOtpState {\n switch (action.type) {\n case 'set_identifier':\n return { ...state, identifier: action.value, error: null };\n\n case 'set_code':\n return { ...state, code: action.value, error: null };\n\n case 'request_start':\n // Guard against double submits while a request is already in flight.\n if (isBusy(state.status)) return state;\n return { ...state, status: 'sending', error: null };\n\n case 'request_success':\n return {\n ...state,\n step: 'verify',\n status: 'idle',\n code: '',\n requestId: action.result.requestId,\n channels: action.result.channels ?? [],\n expiresInSeconds: action.result.expiresInSeconds ?? 0,\n error: null,\n };\n\n case 'request_error':\n return { ...state, status: 'idle', error: action.message };\n\n case 'verify_start':\n if (isBusy(state.status)) return state;\n return { ...state, status: 'verifying', error: null };\n\n case 'verify_error':\n return { ...state, status: 'idle', error: action.message };\n\n case 'back_to_identify':\n return {\n ...state,\n step: 'identify',\n status: 'idle',\n code: '',\n requestId: '',\n channels: [],\n expiresInSeconds: 0,\n error: null,\n };\n\n case 'reset':\n return { ...initialOtpState };\n\n default:\n return state;\n }\n}\n\nconst CHANNEL_LABELS: Record<SneekChannel, string> = {\n sms: 'SMS',\n whatsapp: 'WhatsApp',\n email: 'email',\n};\n\n/** \"SMS, WhatsApp\" — human label for the channels an OTP was sent over. */\nexport function formatChannels(channels: SneekChannel[]): string {\n return channels.map((c) => CHANNEL_LABELS[c] ?? c).join(', ');\n}\n\n/** Normalize any thrown value into a user-facing message. */\nexport function toMessage(error: unknown, fallback: string): string {\n if (error instanceof Error && error.message) return error.message;\n if (typeof error === 'string' && error) return error;\n return fallback;\n}\n","import {\n useEffect,\n useId,\n useState,\n type CSSProperties,\n type FormEvent,\n type ReactNode,\n} from 'react';\n\nimport { buildStyles, SNEEK_STYLE_ID } from './theme';\nimport { useSneekOtp, type SneekOtpHandlers } from './use-sneek-otp';\n\nexport type SneekTheme = 'auto' | 'light' | 'dark';\n\n/** Digits in a Sneek code. */\nconst CODE_LENGTH = 6;\n/** Seconds before \"Resend code\" becomes tappable again. */\nconst RESEND_SECONDS = 30;\n\nexport interface SneekOtpLoginProps<TResult = unknown>\n extends SneekOtpHandlers<TResult> {\n /** Heading above the form. @default 'Sign in' */\n title?: string;\n /** Heading once the code has been sent. @default 'Enter the code' */\n verifyTitle?: string;\n /** Sub-heading. Pass `null` to remove it. */\n subtitle?: ReactNode;\n /** Label for the identifier input. */\n identifierLabel?: string;\n /** Placeholder for the identifier input. */\n identifierPlaceholder?: string;\n /**\n * Colour scheme. `auto` follows the visitor's system setting.\n * @default 'auto'\n */\n theme?: SneekTheme;\n /**\n * Override the single accent colour. Leave unset to use Sneek orange,\n * which is tuned per mode for contrast.\n */\n accentColor?: string;\n /** Replaces the Sneek mark above the title. Pass `null` to remove it. */\n logo?: ReactNode;\n /** Show the \"Secured by Sneek\" line under the form. @default true */\n showBranding?: boolean;\n /** Style overrides for the outer card. */\n style?: CSSProperties;\n /** Extra class on the outer card. */\n className?: string;\n}\n\n/**\n * Sneek mark: two triangles offset on a diagonal — one pointing up on the\n * right, one pointing down on the left. Traced from the brand asset so the\n * package needs no image file and no CDN.\n */\nfunction SneekMark() {\n return (\n <svg\n width=\"36\"\n height=\"36\"\n viewBox=\"0 0 32 32\"\n fill=\"none\"\n role=\"img\"\n aria-label=\"Sneek\"\n >\n <path d=\"M21.3 1 29.3 16H13.3L21.3 1Z\" fill=\"var(--sneek-accent)\" />\n <path d=\"M2.7 17.5H18.7L10.7 31 2.7 17.5Z\" fill=\"var(--sneek-accent)\" />\n </svg>\n );\n}\n\n/**\n * Drop-in passwordless login card.\n *\n * The component never receives a Sneek API key — it calls the handlers you\n * supply, which talk to your own backend. See `createFetchHandlers` for the\n * common case.\n *\n * @example\n * ```tsx\n * <SneekOtpLogin\n * {...createFetchHandlers({ baseUrl: '/api/auth' })}\n * onSuccess={(session) => router.push('/app')}\n * />\n * ```\n */\nexport function SneekOtpLogin<TResult = unknown>(\n props: SneekOtpLoginProps<TResult>,\n): ReactNode {\n const {\n title = 'Sign in',\n verifyTitle = 'Enter the code',\n subtitle = 'Enter your email or phone. We will send you a code.',\n identifierLabel = 'Email or mobile',\n identifierPlaceholder = 'you@company.com or +91…',\n theme = 'auto',\n accentColor,\n logo,\n showBranding = true,\n style,\n className,\n ...handlers\n } = props;\n\n const otp = useSneekOtp<TResult>(handlers);\n const uid = useId();\n // Countdown before resend re-enables. Instant resend is both poor feedback\n // and an easy way to burn someone's SMS quota.\n const [resendIn, setResendIn] = useState(0);\n const identifierId = `${uid}-identifier`;\n const codeId = `${uid}-code`;\n const statusId = `${uid}-status`;\n\n // One <style> element for the whole page, regardless of how many cards\n // render. Injected on mount so the package stays SSR-safe.\n useEffect(() => {\n if (typeof document === 'undefined') return;\n let el = document.getElementById(SNEEK_STYLE_ID);\n if (!el) {\n el = document.createElement('style');\n el.id = SNEEK_STYLE_ID;\n document.head.appendChild(el);\n }\n el.textContent = buildStyles(accentColor);\n }, [accentColor]);\n\n const onIdentifySubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n void otp.sendOtp();\n };\n\n const onVerifySubmit = (event: FormEvent<HTMLFormElement>) => {\n event.preventDefault();\n void otp.verify();\n };\n\n // Start the cooldown whenever a code goes out.\n useEffect(() => {\n if (otp.step === 'verify') setResendIn(RESEND_SECONDS);\n }, [otp.step]);\n\n useEffect(() => {\n if (resendIn <= 0) return;\n const timer = setTimeout(() => setResendIn((n) => n - 1), 1000);\n return () => clearTimeout(timer);\n }, [resendIn]);\n\n // Submit as soon as the code looks complete — nobody should have to reach\n // for a button after typing the last digit.\n useEffect(() => {\n if (otp.step === 'verify' && otp.code.length === CODE_LENGTH && !otp.isBusy) {\n void otp.verify();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [otp.code, otp.step]);\n\n const label: CSSProperties = {\n display: 'flex',\n flexDirection: 'column',\n gap: 8,\n fontSize: 14,\n lineHeight: '20px',\n color: 'var(--sneek-text-muted)',\n };\n\n const input: CSSProperties = {\n padding: '12px 14px',\n border: '1px solid var(--sneek-border)',\n borderRadius: 12,\n background: 'var(--sneek-surface-2)',\n color: 'var(--sneek-text)',\n fontSize: 15,\n width: '100%',\n outline: 'none',\n transition: 'border-color 200ms var(--sneek-ease)',\n };\n\n const button: CSSProperties = {\n padding: '12px 18px',\n border: 'none',\n borderRadius: 9999,\n background: 'var(--sneek-accent)',\n color: 'var(--sneek-accent-contrast)',\n fontSize: 15,\n fontWeight: 500,\n cursor: otp.isBusy ? 'not-allowed' : 'pointer',\n opacity: otp.isBusy ? 0.6 : 1,\n width: '100%',\n transition: 'filter 200ms var(--sneek-ease), opacity 200ms var(--sneek-ease)',\n };\n\n const link: CSSProperties = {\n border: 'none',\n background: 'transparent',\n color: 'var(--sneek-accent)',\n cursor: otp.isBusy ? 'not-allowed' : 'pointer',\n font: 'inherit',\n fontSize: 14,\n padding: 0,\n };\n\n const notice: CSSProperties = {\n padding: '10px 12px',\n borderRadius: 12,\n background: 'var(--sneek-surface-2)',\n border: '1px solid var(--sneek-border)',\n fontSize: 14,\n color: 'var(--sneek-text-muted)',\n };\n\n return (\n <div\n className={className ? `sneek-otp ${className}` : 'sneek-otp'}\n data-theme={theme === 'auto' ? undefined : theme}\n style={{\n maxWidth: 400,\n margin: '0 auto',\n padding: 24,\n border: '1px solid var(--sneek-border)',\n borderRadius: 16,\n background: 'var(--sneek-surface)',\n boxShadow: 'var(--sneek-shadow)',\n color: 'var(--sneek-text)',\n fontFamily:\n 'Inter, ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif',\n lineHeight: 1.5,\n ...style,\n }}\n >\n {logo === null ? null : (logo ?? <SneekMark />)}\n <h1\n style={{\n fontSize: 21,\n lineHeight: '28px',\n fontWeight: 500,\n letterSpacing: '-0.01em',\n margin: '16px 0 0',\n }}\n >\n {otp.step === 'verify' ? verifyTitle : title}\n </h1>\n {otp.step === 'verify' ? (\n <p\n style={{\n fontSize: 14,\n lineHeight: '20px',\n color: 'var(--sneek-text-muted)',\n margin: '8px 0 0',\n }}\n >\n Sent to{' '}\n <span style={{ color: 'var(--sneek-text)' }}>{otp.identifier}</span>\n {' · '}\n <button\n type=\"button\"\n className=\"sneek-otp-link\"\n onClick={otp.back}\n disabled={otp.isBusy}\n style={{ ...link, fontSize: 14 }}\n >\n Change\n </button>\n </p>\n ) : subtitle ? (\n <p\n style={{\n fontSize: 14,\n lineHeight: '20px',\n color: 'var(--sneek-text-muted)',\n margin: '8px 0 0',\n }}\n >\n {subtitle}\n </p>\n ) : null}\n\n {/* Errors and channel notices are announced, not just shown. */}\n <div role=\"status\" aria-live=\"polite\" id={statusId} style={{ marginTop: 32 }}>\n {otp.error ? (\n <div\n role=\"alert\"\n style={{\n ...notice,\n color: 'var(--sneek-danger)',\n borderColor: 'var(--sneek-danger)',\n }}\n >\n {otp.error}\n </div>\n ) : null}\n </div>\n\n {otp.step === 'identify' ? (\n <form\n onSubmit={onIdentifySubmit}\n style={{ display: 'flex', flexDirection: 'column', gap: 16, marginTop: 16 }}\n >\n <label style={label} htmlFor={identifierId}>\n {identifierLabel}\n <input\n id={identifierId}\n className=\"sneek-otp-input\"\n type=\"text\"\n value={otp.identifier}\n onChange={(e) => otp.setIdentifier(e.target.value)}\n placeholder={identifierPlaceholder}\n autoComplete=\"username\"\n autoFocus\n required\n aria-describedby={statusId}\n style={input}\n />\n </label>\n <button\n type=\"submit\"\n className=\"sneek-otp-button\"\n disabled={otp.isBusy}\n style={button}\n >\n {otp.isSending ? 'Sending code…' : 'Send code'}\n </button>\n </form>\n ) : (\n <form\n onSubmit={onVerifySubmit}\n style={{ display: 'flex', flexDirection: 'column', gap: 16, marginTop: 16 }}\n >\n <label style={{ ...label, marginBottom: -8 }} htmlFor={codeId}>\n {CODE_LENGTH}-digit code\n </label>\n <input\n id={codeId}\n className=\"sneek-otp-input\"\n type=\"text\"\n inputMode=\"numeric\"\n pattern=\"[0-9]*\"\n autoComplete=\"one-time-code\"\n maxLength={CODE_LENGTH}\n value={otp.code}\n onChange={(e) =>\n otp.setCode(e.target.value.replace(/\\D/g, '').slice(0, CODE_LENGTH))\n }\n autoFocus\n required\n aria-describedby={statusId}\n style={{\n ...input,\n fontSize: 24,\n lineHeight: '32px',\n textAlign: 'center',\n letterSpacing: '0.4em',\n textIndent: '0.4em',\n padding: '14px',\n }}\n />\n <button\n type=\"submit\"\n className=\"sneek-otp-button\"\n disabled={otp.isBusy || otp.code.length < CODE_LENGTH}\n style={{\n ...button,\n opacity:\n otp.isBusy || otp.code.length < CODE_LENGTH ? 0.6 : 1,\n }}\n >\n {otp.isVerifying ? 'Verifying…' : 'Verify'}\n </button>\n <div style={{ textAlign: 'center' }}>\n {resendIn > 0 ? (\n <span\n style={{\n fontSize: 14,\n color: 'var(--sneek-text-muted)',\n }}\n >\n Resend code in {resendIn}s\n </span>\n ) : (\n <button\n type=\"button\"\n className=\"sneek-otp-link\"\n onClick={() => void otp.resend()}\n disabled={otp.isBusy}\n style={link}\n >\n Resend code\n </button>\n )}\n </div>\n </form>\n )}\n\n {showBranding ? (\n <p\n style={{\n margin: '32px 0 0',\n textAlign: 'center',\n fontSize: 12,\n lineHeight: '16px',\n color: 'var(--sneek-text-muted)',\n }}\n >\n Secured by Sneek\n </p>\n ) : null}\n </div>\n );\n}\n","/**\n * Theme for the drop-in login card.\n *\n * The package ships zero dependencies and no stylesheet, so the tokens are\n * injected once as CSS custom properties scoped to `.sneek-otp`. That buys two\n * things inline styles cannot: a `prefers-color-scheme` media query, and real\n * `:focus-visible` / `:hover` states.\n *\n * Light and dark are authored independently rather than one being an inversion\n * of the other. In dark, the page-to-card lightness delta carries depth and the\n * card needs no shadow; in light both are near-white, so the card takes a\n * visible border and a real shadow.\n */\nexport const SNEEK_STYLE_ID = 'sneek-otp-styles';\n\n/** Brand orange. The single accent — nothing else on the card is coloured. */\nexport const SNEEK_ACCENT_DARK = '#f86513';\n/** Darkened for light mode so it clears WCAG AA as text and as a button fill. */\nexport const SNEEK_ACCENT_LIGHT = '#b83f06';\n\nexport function buildStyles(accent?: string): string {\n const darkAccent = accent ?? SNEEK_ACCENT_DARK;\n const lightAccent = accent ?? SNEEK_ACCENT_LIGHT;\n\n const light = `\n --sneek-surface: #ffffff;\n --sneek-surface-2: #f4f1ed;\n --sneek-border: #e3ddd5;\n --sneek-text: #1c1917;\n --sneek-text-muted: #57534e;\n --sneek-accent: ${lightAccent};\n --sneek-accent-soft: color-mix(in srgb, ${lightAccent} 12%, transparent);\n --sneek-accent-contrast: #ffffff;\n --sneek-danger: #b0242a;\n --sneek-shadow: 0 3px 3px -2px rgb(0 0 0 / 0.10), 0 3px 4px rgb(0 0 0 / 0.07),\n 0 1px 8px rgb(0 0 0 / 0.06);`;\n\n const dark = `\n --sneek-surface: #17150f;\n --sneek-surface-2: #201d16;\n --sneek-border: rgba(255, 255, 255, 0.08);\n --sneek-text: #faf8f6;\n --sneek-text-muted: #a8a29b;\n --sneek-accent: ${darkAccent};\n --sneek-accent-soft: color-mix(in srgb, ${darkAccent} 16%, transparent);\n --sneek-accent-contrast: #1a0d04;\n --sneek-danger: #d43a3c;\n --sneek-shadow: none;`;\n\n return `\n.sneek-otp {${light}\n --sneek-ease: cubic-bezier(0, 0, 0.2, 1);\n}\n@media (prefers-color-scheme: dark) {\n .sneek-otp:not([data-theme=\"light\"]) {${dark}\n }\n}\n.sneek-otp[data-theme=\"dark\"] {${dark}\n}\n.sneek-otp[data-theme=\"light\"] {${light}\n}\n.sneek-otp *, .sneek-otp *::before, .sneek-otp *::after { box-sizing: border-box; }\n.sneek-otp-input:focus-visible,\n.sneek-otp-button:focus-visible,\n.sneek-otp-link:focus-visible {\n outline: 2px solid var(--sneek-accent);\n outline-offset: 2px;\n}\n.sneek-otp-input:focus {\n border-color: var(--sneek-accent);\n}\n.sneek-otp-button:not(:disabled):hover {\n filter: brightness(1.08);\n}\n.sneek-otp-link:not(:disabled):hover {\n text-decoration: underline;\n}\n@media (prefers-reduced-motion: reduce) {\n .sneek-otp * { transition-duration: 0.01ms !important; }\n}\n`;\n}\n","import type { RequestOtpResult } from './state';\n\nexport interface FetchHandlerOptions {\n /**\n * Partner backend endpoint that sends an OTP. Receives `{ identifier }`,\n * must return `{ requestId, channels?, expiresInSeconds? }`.\n * @default '/api/auth/request-otp'\n */\n requestUrl?: string;\n /**\n * Partner backend endpoint that verifies an OTP. Receives\n * `{ requestId, code }`, returns whatever your app needs (session, token…).\n * @default '/api/auth/verify-otp'\n */\n verifyUrl?: string;\n /** Extra headers (e.g. CSRF token) to send on both requests. */\n headers?: Record<string, string>;\n /** Forwarded to fetch — set to 'include' if you use cookie sessions. */\n credentials?: RequestCredentials;\n}\n\nasync function postJson<T>(\n url: string,\n body: unknown,\n options: FetchHandlerOptions,\n): Promise<T> {\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', ...(options.headers ?? {}) },\n credentials: options.credentials,\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n let message = `Request failed (${response.status})`;\n try {\n const data = (await response.json()) as { message?: string; error?: string };\n message = data.message || data.error || message;\n } catch {\n // non-JSON error body — keep the status-based message\n }\n throw new Error(message);\n }\n\n return (await response.json()) as T;\n}\n\n/**\n * Build {@link SneekOtpHandlers} that POST to your own backend endpoints.\n * Those endpoints call the Sneek API server-side with your secret key.\n */\nexport function createFetchHandlers<TResult = unknown>(\n options: FetchHandlerOptions = {},\n): {\n requestOtp: (identifier: string) => Promise<RequestOtpResult>;\n verifyOtp: (input: { requestId: string; code: string }) => Promise<TResult>;\n} {\n const requestUrl = options.requestUrl ?? '/api/auth/request-otp';\n const verifyUrl = options.verifyUrl ?? '/api/auth/verify-otp';\n\n return {\n requestOtp: (identifier: string) =>\n postJson<RequestOtpResult>(requestUrl, { identifier }, options),\n verifyOtp: (input: { requestId: string; code: string }) =>\n postJson<TResult>(verifyUrl, input, options),\n };\n}\n"],"mappings":";AAAA,SAAS,aAAa,kBAAkB;;;ACiCjC,IAAM,kBAAiC;AAAA,EAC5C,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,MAAM;AAAA,EACN,WAAW;AAAA,EACX,UAAU,CAAC;AAAA,EACX,kBAAkB;AAAA,EAClB,OAAO;AACT;AAmBA,IAAM,SAAS,CAAC,WAAoC,WAAW;AAExD,SAAS,WACd,OACA,QACe;AACf,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,YAAY,OAAO,OAAO,OAAO,KAAK;AAAA,IAE3D,KAAK;AACH,aAAO,EAAE,GAAG,OAAO,MAAM,OAAO,OAAO,OAAO,KAAK;AAAA,IAErD,KAAK;AAEH,UAAI,OAAO,MAAM,MAAM,EAAG,QAAO;AACjC,aAAO,EAAE,GAAG,OAAO,QAAQ,WAAW,OA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