@sylphx/auth-solid 0.1.0 → 0.1.2
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/README.md +19 -0
- package/dist/browser.js +399 -285
- package/dist/messages.d.ts +75 -0
- package/dist/server.js +175 -52
- package/dist/sign-in-controller.d.ts +11 -1
- package/package.json +2 -2
package/dist/messages.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export type SignInMessages = {
|
|
|
57
57
|
use_existing: string;
|
|
58
58
|
invalid_credentials: string;
|
|
59
59
|
verify_email: string;
|
|
60
|
+
acceptance_required: string;
|
|
60
61
|
verification_failed: string;
|
|
61
62
|
invalid_code: string;
|
|
62
63
|
method_unavailable: string;
|
|
@@ -124,6 +125,7 @@ export declare const catalogs: {
|
|
|
124
125
|
cancelled: string;
|
|
125
126
|
use_existing: string;
|
|
126
127
|
invalid_credentials: string;
|
|
128
|
+
acceptance_required: string;
|
|
127
129
|
verify_email: string;
|
|
128
130
|
verification_failed: string;
|
|
129
131
|
invalid_code: string;
|
|
@@ -191,6 +193,7 @@ export declare const catalogs: {
|
|
|
191
193
|
cancelled: string;
|
|
192
194
|
use_existing: string;
|
|
193
195
|
invalid_credentials: string;
|
|
196
|
+
acceptance_required: string;
|
|
194
197
|
verify_email: string;
|
|
195
198
|
verification_failed: string;
|
|
196
199
|
invalid_code: string;
|
|
@@ -258,6 +261,7 @@ export declare const catalogs: {
|
|
|
258
261
|
cancelled: string;
|
|
259
262
|
use_existing: string;
|
|
260
263
|
invalid_credentials: string;
|
|
264
|
+
acceptance_required: string;
|
|
261
265
|
verify_email: string;
|
|
262
266
|
verification_failed: string;
|
|
263
267
|
invalid_code: string;
|
|
@@ -325,6 +329,7 @@ export declare const catalogs: {
|
|
|
325
329
|
cancelled: string;
|
|
326
330
|
use_existing: string;
|
|
327
331
|
invalid_credentials: string;
|
|
332
|
+
acceptance_required: string;
|
|
328
333
|
verify_email: string;
|
|
329
334
|
verification_failed: string;
|
|
330
335
|
invalid_code: string;
|
|
@@ -392,6 +397,75 @@ export declare const catalogs: {
|
|
|
392
397
|
cancelled: string;
|
|
393
398
|
use_existing: string;
|
|
394
399
|
invalid_credentials: string;
|
|
400
|
+
acceptance_required: string;
|
|
401
|
+
verify_email: string;
|
|
402
|
+
verification_failed: string;
|
|
403
|
+
invalid_code: string;
|
|
404
|
+
method_unavailable: string;
|
|
405
|
+
signup_failed: string;
|
|
406
|
+
invalid_input: string;
|
|
407
|
+
try_later: string;
|
|
408
|
+
unavailable: string;
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
ko: {
|
|
412
|
+
signIn: string;
|
|
413
|
+
enterPassword: string;
|
|
414
|
+
createYourAccount: string;
|
|
415
|
+
checkInbox: string;
|
|
416
|
+
confirmEmail: string;
|
|
417
|
+
verifyIdentity: string;
|
|
418
|
+
chooseMethod: string;
|
|
419
|
+
startWithEmail: string;
|
|
420
|
+
checkEmailDescription: string;
|
|
421
|
+
confirmEmailDescription: string;
|
|
422
|
+
enterEmailCode: (email: string) => string;
|
|
423
|
+
enterRecovery: string;
|
|
424
|
+
enterAuthenticator: string;
|
|
425
|
+
loading: string;
|
|
426
|
+
retry: string;
|
|
427
|
+
openingProvider: (provider: string) => string;
|
|
428
|
+
continueProvider: (provider: string) => string;
|
|
429
|
+
orEmail: string;
|
|
430
|
+
email: string;
|
|
431
|
+
sendingCode: string;
|
|
432
|
+
emailCodeAction: string;
|
|
433
|
+
continueEmail: string;
|
|
434
|
+
waitingPasskey: string;
|
|
435
|
+
usePasskey: string;
|
|
436
|
+
newHere: string;
|
|
437
|
+
createAnAccount: string;
|
|
438
|
+
noMethods: string;
|
|
439
|
+
password: string;
|
|
440
|
+
hidePassword: string;
|
|
441
|
+
showPassword: string;
|
|
442
|
+
hide: string;
|
|
443
|
+
show: string;
|
|
444
|
+
minimumPassword: string;
|
|
445
|
+
working: string;
|
|
446
|
+
createAccount: string;
|
|
447
|
+
confirmAndSignIn: string;
|
|
448
|
+
changeEmailOrMethod: string;
|
|
449
|
+
backToSignIn: string;
|
|
450
|
+
emailCode: string;
|
|
451
|
+
checkingCode: string;
|
|
452
|
+
verifyCode: string;
|
|
453
|
+
resendIn: (duration: string) => string;
|
|
454
|
+
resendCode: string;
|
|
455
|
+
changeEmail: string;
|
|
456
|
+
usePassword: string;
|
|
457
|
+
recoveryCode: string;
|
|
458
|
+
authenticatorCode: string;
|
|
459
|
+
verifyAndSignIn: string;
|
|
460
|
+
useAuthenticator: string;
|
|
461
|
+
useRecovery: string;
|
|
462
|
+
language: string;
|
|
463
|
+
errors: {
|
|
464
|
+
signin: string;
|
|
465
|
+
cancelled: string;
|
|
466
|
+
use_existing: string;
|
|
467
|
+
invalid_credentials: string;
|
|
468
|
+
acceptance_required: string;
|
|
395
469
|
verify_email: string;
|
|
396
470
|
verification_failed: string;
|
|
397
471
|
invalid_code: string;
|
|
@@ -410,4 +484,5 @@ export declare const localeNames: {
|
|
|
410
484
|
'zh-Hant-TW': string;
|
|
411
485
|
'zh-Hans': string;
|
|
412
486
|
ja: string;
|
|
487
|
+
ko: string;
|
|
413
488
|
};
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createComponent, escape, memo, ssr, ssrAttribute, ssrHydrationKey, ssrStyle } from "solid-js/web";
|
|
2
|
-
import { providerDestination, providers, safeReturnTo } from "@sylphx/auth/client";
|
|
3
|
-
import { For, Match, Show, Switch, createMemo, createSignal, createUniqueId, onCleanup, onMount } from "solid-js";
|
|
2
|
+
import { authRoutePrefix, providerDestination, providers, safeReturnTo } from "@sylphx/auth/client";
|
|
3
|
+
import { For, Match, Show, Switch, createEffect, createMemo, createSignal, createUniqueId, onCleanup, onMount } from "solid-js";
|
|
4
4
|
// src/messages.ts
|
|
5
5
|
var catalogs = {
|
|
6
6
|
en: {
|
|
@@ -60,6 +60,7 @@ var catalogs = {
|
|
|
60
60
|
cancelled: "Sign-in was canceled. You can try again whenever you’re ready.",
|
|
61
61
|
use_existing: "Try the method you originally used to sign in. This provider couldn’t confirm your email.",
|
|
62
62
|
invalid_credentials: "That email and password didn’t match. Check both and try again.",
|
|
63
|
+
acceptance_required: "Accept the current terms to continue.",
|
|
63
64
|
verify_email: "Confirm your email from the link in your inbox before signing in.",
|
|
64
65
|
verification_failed: "This confirmation link couldn’t be used. Check that you opened the latest link.",
|
|
65
66
|
invalid_code: "That code didn’t work. Check it and try again.",
|
|
@@ -127,6 +128,7 @@ var catalogs = {
|
|
|
127
128
|
cancelled: "登入已取消。你可以隨時再試。",
|
|
128
129
|
use_existing: "這項登入服務未能確認你的電郵地址。請改用原來的登入方式。",
|
|
129
130
|
invalid_credentials: "電郵地址與密碼不符。請核對後再試。",
|
|
131
|
+
acceptance_required: "請同意現行條款後繼續。",
|
|
130
132
|
verify_email: "請先開啟確認電郵內的連結,確認電郵地址後再登入。",
|
|
131
133
|
verification_failed: "此連結無法使用。請開啟最新一封確認電郵內的連結。",
|
|
132
134
|
invalid_code: "驗證碼無法使用。請核對後再試。",
|
|
@@ -194,6 +196,7 @@ var catalogs = {
|
|
|
194
196
|
cancelled: "登入已取消。你可以隨時再試。",
|
|
195
197
|
use_existing: "這項登入服務無法確認你的電子郵件地址。請改用原本的登入方式。",
|
|
196
198
|
invalid_credentials: "電子郵件地址和密碼不符。請檢查後再試一次。",
|
|
199
|
+
acceptance_required: "請同意目前的條款後繼續。",
|
|
197
200
|
verify_email: "請先開啟確認信中的連結,確認電子郵件地址後再登入。",
|
|
198
201
|
verification_failed: "這個確認連結無法使用。請確認你開啟的是最新一封確認信中的連結。",
|
|
199
202
|
invalid_code: "這組驗證碼無法使用。請檢查後再試一次。",
|
|
@@ -261,6 +264,7 @@ var catalogs = {
|
|
|
261
264
|
cancelled: "登录已取消。你可以随时重试。",
|
|
262
265
|
use_existing: "此登录服务无法确认你的邮箱地址。请改用原来的登录方式。",
|
|
263
266
|
invalid_credentials: "邮箱地址和密码不匹配。请检查后重试。",
|
|
267
|
+
acceptance_required: "请同意当前条款后继续。",
|
|
264
268
|
verify_email: "请先打开确认邮件中的链接,确认邮箱地址后再登录。",
|
|
265
269
|
verification_failed: "此链接无法使用。请打开最新一封确认邮件中的链接。",
|
|
266
270
|
invalid_code: "此验证码无法使用。请检查后重试。",
|
|
@@ -328,6 +332,7 @@ var catalogs = {
|
|
|
328
332
|
cancelled: "ログインがキャンセルされました。いつでもやり直せます。",
|
|
329
333
|
use_existing: "このサービスではメールアドレスを確認できませんでした。最初に使った方法でログインしてください。",
|
|
330
334
|
invalid_credentials: "メールアドレスとパスワードが一致しません。両方を確認して、もう一度お試しください。",
|
|
335
|
+
acceptance_required: "続行するには、現在の利用規約に同意してください。",
|
|
331
336
|
verify_email: "確認メール内のリンクを開き、メールアドレスを確認してからログインしてください。",
|
|
332
337
|
verification_failed: "この確認リンクは使えません。最新の確認メールのリンクをお試しください。",
|
|
333
338
|
invalid_code: "このコードは使えません。入力内容を確認して、もう一度お試しください。",
|
|
@@ -337,6 +342,74 @@ var catalogs = {
|
|
|
337
342
|
try_later: "試行回数が上限に達しました。しばらく待ってからお試しください。",
|
|
338
343
|
unavailable: "接続できませんでした。しばらく待ってからお試しください。"
|
|
339
344
|
}
|
|
345
|
+
},
|
|
346
|
+
ko: {
|
|
347
|
+
signIn: "로그인",
|
|
348
|
+
enterPassword: "비밀번호를 입력하세요",
|
|
349
|
+
createYourAccount: "계정 만들기",
|
|
350
|
+
checkInbox: "이메일을 확인하세요",
|
|
351
|
+
confirmEmail: "이메일 주소 확인",
|
|
352
|
+
verifyIdentity: "본인 확인",
|
|
353
|
+
chooseMethod: "로그인 방법을 선택하세요.",
|
|
354
|
+
startWithEmail: "이메일 주소로 시작하세요.",
|
|
355
|
+
checkEmailDescription: "처음 사용하는 이메일 주소라면 확인 링크를 보내 드립니다. 링크를 열고 방금 설정한 비밀번호를 입력하세요.",
|
|
356
|
+
confirmEmailDescription: "가입할 때 사용한 이메일 주소와 비밀번호를 입력하세요.",
|
|
357
|
+
enterEmailCode: (email) => `${email} 주소로 보낸 6자리 인증 코드를 입력하세요.`,
|
|
358
|
+
enterRecovery: "저장해 둔 복구 코드 중 하나를 입력하세요.",
|
|
359
|
+
enterAuthenticator: "인증 앱에 표시된 코드를 입력하세요.",
|
|
360
|
+
loading: "로그인 방법을 불러오는 중…",
|
|
361
|
+
retry: "다시 시도",
|
|
362
|
+
openingProvider: (provider) => `${provider} 로그인 화면을 여는 중…`,
|
|
363
|
+
continueProvider: (provider) => `${provider} 계정으로 계속`,
|
|
364
|
+
orEmail: "또는 이메일로 계속",
|
|
365
|
+
email: "이메일 주소",
|
|
366
|
+
sendingCode: "인증 코드를 보내는 중…",
|
|
367
|
+
emailCodeAction: "이메일로 인증 코드 받기",
|
|
368
|
+
continueEmail: "이메일로 계속",
|
|
369
|
+
waitingPasskey: "패스키 인증을 기다리는 중…",
|
|
370
|
+
usePasskey: "패스키 사용",
|
|
371
|
+
newHere: "계정이 없으신가요?",
|
|
372
|
+
createAnAccount: "계정 만들기",
|
|
373
|
+
noMethods: "지금은 사용할 수 있는 로그인 방법이 없습니다.",
|
|
374
|
+
password: "비밀번호",
|
|
375
|
+
hidePassword: "비밀번호 숨기기",
|
|
376
|
+
showPassword: "비밀번호 보기",
|
|
377
|
+
hide: "숨기기",
|
|
378
|
+
show: "보기",
|
|
379
|
+
minimumPassword: "12자 이상 입력하세요.",
|
|
380
|
+
working: "처리 중…",
|
|
381
|
+
createAccount: "계정 만들기",
|
|
382
|
+
confirmAndSignIn: "확인하고 로그인",
|
|
383
|
+
changeEmailOrMethod: "이메일 주소 또는 로그인 방법 변경",
|
|
384
|
+
backToSignIn: "로그인으로 돌아가기",
|
|
385
|
+
emailCode: "이메일 인증 코드",
|
|
386
|
+
checkingCode: "인증 코드를 확인하는 중…",
|
|
387
|
+
verifyCode: "인증 코드 확인",
|
|
388
|
+
resendIn: (duration) => `${duration} 후 다시 보낼 수 있습니다.`,
|
|
389
|
+
resendCode: "인증 코드 다시 보내기",
|
|
390
|
+
changeEmail: "이메일 주소 변경",
|
|
391
|
+
usePassword: "비밀번호로 로그인",
|
|
392
|
+
recoveryCode: "복구 코드",
|
|
393
|
+
authenticatorCode: "인증 앱 코드",
|
|
394
|
+
verifyAndSignIn: "인증하고 로그인",
|
|
395
|
+
useAuthenticator: "인증 앱 사용",
|
|
396
|
+
useRecovery: "복구 코드 사용",
|
|
397
|
+
language: "언어",
|
|
398
|
+
errors: {
|
|
399
|
+
signin: "로그인하지 못했습니다. 다시 시도하거나 다른 로그인 방법을 선택하세요.",
|
|
400
|
+
cancelled: "로그인이 취소되었습니다. 언제든지 다시 시도할 수 있습니다.",
|
|
401
|
+
use_existing: "이 로그인 서비스에서 이메일 주소를 확인할 수 없습니다. 처음 사용한 방법으로 로그인하세요.",
|
|
402
|
+
invalid_credentials: "이메일 주소 또는 비밀번호가 올바르지 않습니다. 확인한 뒤 다시 시도하세요.",
|
|
403
|
+
acceptance_required: "계속하려면 현재 약관에 동의하세요.",
|
|
404
|
+
verify_email: "로그인하기 전에 받은 이메일의 링크를 열어 이메일 주소를 확인하세요.",
|
|
405
|
+
verification_failed: "이 확인 링크를 사용할 수 없습니다. 가장 최근에 받은 링크를 열어 보세요.",
|
|
406
|
+
invalid_code: "인증 코드가 올바르지 않습니다. 코드를 확인한 뒤 다시 시도하세요.",
|
|
407
|
+
method_unavailable: "지금은 이 방법으로 로그인할 수 없습니다. 다른 방법을 선택하세요.",
|
|
408
|
+
signup_failed: "계정을 만들지 못했습니다. 입력 내용을 확인한 뒤 다시 시도하세요.",
|
|
409
|
+
invalid_input: "입력 내용을 확인한 뒤 다시 시도하세요.",
|
|
410
|
+
try_later: "시도 횟수가 너무 많습니다. 잠시 후 다시 시도하세요.",
|
|
411
|
+
unavailable: "연결하지 못했습니다. 잠시 후 다시 시도하세요."
|
|
412
|
+
}
|
|
340
413
|
}
|
|
341
414
|
};
|
|
342
415
|
var localeNames = {
|
|
@@ -344,7 +417,8 @@ var localeNames = {
|
|
|
344
417
|
"zh-Hant-HK": "繁體中文(香港)",
|
|
345
418
|
"zh-Hant-TW": "繁體中文(台灣)",
|
|
346
419
|
"zh-Hans": "简体中文",
|
|
347
|
-
ja: "日本語"
|
|
420
|
+
ja: "日本語",
|
|
421
|
+
ko: "한국어"
|
|
348
422
|
};
|
|
349
423
|
/** Select a shipped language without comparing raw locale strings or relying on the host's locale. */
|
|
350
424
|
function resolveAuthLocale(preferences) {
|
|
@@ -356,7 +430,7 @@ function resolveAuthLocale(preferences) {
|
|
|
356
430
|
continue;
|
|
357
431
|
}
|
|
358
432
|
if (Object.hasOwn(catalogs, locale.baseName)) return locale.baseName;
|
|
359
|
-
if (locale.language === "en" || locale.language === "ja") return locale.language;
|
|
433
|
+
if (locale.language === "en" || locale.language === "ja" || locale.language === "ko") return locale.language;
|
|
360
434
|
if (locale.language === "zh") {
|
|
361
435
|
const script = locale.maximize().script;
|
|
362
436
|
if (script === "Hans") return "zh-Hans";
|
|
@@ -417,11 +491,12 @@ function encode(value) {
|
|
|
417
491
|
function createSignInController(options) {
|
|
418
492
|
const search = new URLSearchParams(options.search);
|
|
419
493
|
const next = safeReturnTo(options.next);
|
|
494
|
+
const route = authRoutePrefix(options.routePrefix);
|
|
420
495
|
const loginPath = safeReturnTo(options.loginPath, "/login").split(/[?#]/, 1)[0];
|
|
421
496
|
const challengeId = search.get("challenge_id");
|
|
422
497
|
const verification = search.get("token");
|
|
423
498
|
const hasVerification = !!challengeId && !!verification && search.get("type") === "email_verification";
|
|
424
|
-
const [config, setConfig] = createSignal();
|
|
499
|
+
const [config, setConfig] = createSignal(options.initialConfig);
|
|
425
500
|
const [configFailed, setConfigFailed] = createSignal(false);
|
|
426
501
|
const [step, setStep] = createSignal("choose");
|
|
427
502
|
const [email, setEmail] = createSignal("");
|
|
@@ -434,6 +509,9 @@ function createSignInController(options) {
|
|
|
434
509
|
const [busy, setBusy] = createSignal("");
|
|
435
510
|
const [showPassword, setShowPassword] = createSignal(false);
|
|
436
511
|
const [canPasskey, setCanPasskey] = createSignal(false);
|
|
512
|
+
const [conditionalReady, setConditionalReady] = createSignal(false);
|
|
513
|
+
let conditional;
|
|
514
|
+
let attemptedConditional = false;
|
|
437
515
|
const [code, setCode] = createSignal("");
|
|
438
516
|
const [flow, setFlow] = createSignal("");
|
|
439
517
|
const [challenge, setChallenge] = createSignal("");
|
|
@@ -452,7 +530,7 @@ function createSignInController(options) {
|
|
|
452
530
|
const attempt = new AbortController();
|
|
453
531
|
confController = attempt;
|
|
454
532
|
try {
|
|
455
|
-
const res = await fetch(
|
|
533
|
+
const res = await fetch(`${route}/config`, {
|
|
456
534
|
referrerPolicy: "origin",
|
|
457
535
|
redirect: "error",
|
|
458
536
|
signal: AbortSignal.any([attempt.signal, AbortSignal.timeout(12e3)])
|
|
@@ -476,34 +554,50 @@ function createSignInController(options) {
|
|
|
476
554
|
setStep("confirm");
|
|
477
555
|
window.history.replaceState(window.history.state, "", `${loginPath}?${new URLSearchParams({ next })}`);
|
|
478
556
|
}
|
|
479
|
-
loadConfig();
|
|
557
|
+
if (!config()) loadConfig();
|
|
558
|
+
if (options.conditionalPasskey && canPasskey()) PublicKeyCredential.isConditionalMediationAvailable?.().then((supported) => {
|
|
559
|
+
if (!controller.signal.aborted) setConditionalReady(supported);
|
|
560
|
+
}).catch(() => void 0);
|
|
480
561
|
const timer = window.setInterval(() => setNow(Date.now()), 1e3);
|
|
481
562
|
onCleanup(() => {
|
|
482
563
|
window.clearInterval(timer);
|
|
483
564
|
confController?.abort();
|
|
565
|
+
stopConditional();
|
|
484
566
|
controller.abort();
|
|
485
567
|
});
|
|
486
568
|
});
|
|
569
|
+
function stopConditional() {
|
|
570
|
+
conditional?.abort();
|
|
571
|
+
conditional = void 0;
|
|
572
|
+
}
|
|
487
573
|
function go(to) {
|
|
574
|
+
if (to !== "choose") stopConditional();
|
|
488
575
|
setErrorCode("");
|
|
489
576
|
setShowPassword(false);
|
|
490
577
|
setStep(to);
|
|
491
578
|
}
|
|
492
|
-
async function post(path, body) {
|
|
579
|
+
async function post(path, body, signal = controller.signal) {
|
|
493
580
|
const res = await fetch(path, {
|
|
494
581
|
method: "POST",
|
|
495
582
|
headers: { "Content-Type": "application/json" },
|
|
496
583
|
referrerPolicy: "origin",
|
|
497
584
|
redirect: "error",
|
|
498
|
-
signal: AbortSignal.any([
|
|
499
|
-
|
|
585
|
+
signal: AbortSignal.any([
|
|
586
|
+
controller.signal,
|
|
587
|
+
signal,
|
|
588
|
+
AbortSignal.timeout(45e3)
|
|
589
|
+
]),
|
|
590
|
+
body: JSON.stringify({
|
|
591
|
+
...body,
|
|
592
|
+
acceptance: options.getAcceptance?.()
|
|
593
|
+
})
|
|
500
594
|
});
|
|
501
595
|
const data = await res.json();
|
|
502
596
|
if (!res.ok) throw new SignInError(isErrorCode(data.error) ? data.error : "unavailable");
|
|
503
597
|
return data;
|
|
504
598
|
}
|
|
505
599
|
async function request(action, fields = {}) {
|
|
506
|
-
const data = await post(
|
|
600
|
+
const data = await post(`${route}/email`, {
|
|
507
601
|
action,
|
|
508
602
|
next,
|
|
509
603
|
...fields
|
|
@@ -513,6 +607,8 @@ function createSignInController(options) {
|
|
|
513
607
|
}
|
|
514
608
|
async function run(label, op) {
|
|
515
609
|
if (busy() || controller.signal.aborted) return;
|
|
610
|
+
attemptedConditional = true;
|
|
611
|
+
stopConditional();
|
|
516
612
|
setBusy(label);
|
|
517
613
|
setErrorCode("");
|
|
518
614
|
try {
|
|
@@ -526,7 +622,7 @@ function createSignInController(options) {
|
|
|
526
622
|
function social(provider) {
|
|
527
623
|
if (!config()?.providers.includes(provider)) return;
|
|
528
624
|
return run(providers[provider][0], async () => {
|
|
529
|
-
const { authorize } = await post(
|
|
625
|
+
const { authorize } = await post(`${route}/start/${provider}`, { next });
|
|
530
626
|
const target = providerDestination(provider, authorize);
|
|
531
627
|
if (!target) throw new Error();
|
|
532
628
|
if (!controller.signal.aborted) window.location.assign(target);
|
|
@@ -559,39 +655,63 @@ function createSignInController(options) {
|
|
|
559
655
|
}
|
|
560
656
|
});
|
|
561
657
|
}
|
|
658
|
+
async function getPasskey(signal, autofill) {
|
|
659
|
+
const { challenge, challengeId, rpId, credentials } = await post(`${route}/email`, {
|
|
660
|
+
action: "passkey_start",
|
|
661
|
+
next
|
|
662
|
+
}, signal);
|
|
663
|
+
if (signal.aborted || !challenge || !challengeId || !rpId || !credentials) return;
|
|
664
|
+
if (autofill && credentials.length) return;
|
|
665
|
+
const assertion = await navigator.credentials.get({
|
|
666
|
+
signal,
|
|
667
|
+
...autofill && { mediation: "conditional" },
|
|
668
|
+
publicKey: {
|
|
669
|
+
challenge: decode(challenge),
|
|
670
|
+
rpId,
|
|
671
|
+
...autofill ? {} : { timeout: 6e4 },
|
|
672
|
+
userVerification: "required",
|
|
673
|
+
allowCredentials: credentials.map((id) => ({
|
|
674
|
+
id: decode(id),
|
|
675
|
+
type: "public-key"
|
|
676
|
+
}))
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
if (signal.aborted || !(assertion instanceof PublicKeyCredential) || !(assertion.response instanceof AuthenticatorAssertionResponse)) return;
|
|
680
|
+
const response = assertion.response;
|
|
681
|
+
return {
|
|
682
|
+
challenge_id: challengeId,
|
|
683
|
+
credential_id: encode(assertion.rawId),
|
|
684
|
+
client_data_json: encode(response.clientDataJSON),
|
|
685
|
+
authenticator_data: encode(response.authenticatorData),
|
|
686
|
+
signature: encode(response.signature),
|
|
687
|
+
user_handle: response.userHandle ? encode(response.userHandle) : ""
|
|
688
|
+
};
|
|
689
|
+
}
|
|
562
690
|
function passkey() {
|
|
563
691
|
if (!canPasskey() || !config()?.passkey) return;
|
|
564
692
|
return run("passkey", async () => {
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
const assertion = await navigator.credentials.get({
|
|
568
|
-
signal: controller.signal,
|
|
569
|
-
publicKey: {
|
|
570
|
-
challenge: decode(challenge),
|
|
571
|
-
rpId,
|
|
572
|
-
timeout: 6e4,
|
|
573
|
-
userVerification: "required",
|
|
574
|
-
allowCredentials: credentials.map((id) => ({
|
|
575
|
-
id: decode(id),
|
|
576
|
-
type: "public-key"
|
|
577
|
-
}))
|
|
578
|
-
}
|
|
579
|
-
}).catch((error) => {
|
|
580
|
-
if (error instanceof DOMException && error.name === "NotAllowedError") return null;
|
|
693
|
+
const fields = await getPasskey(controller.signal, false).catch((error) => {
|
|
694
|
+
if (error instanceof DOMException && error.name === "NotAllowedError") return;
|
|
581
695
|
throw error;
|
|
582
696
|
});
|
|
583
|
-
if (!
|
|
584
|
-
|
|
585
|
-
await request("passkey_verify", {
|
|
586
|
-
challenge_id: challengeId,
|
|
587
|
-
credential_id: encode(assertion.rawId),
|
|
588
|
-
client_data_json: encode(response.clientDataJSON),
|
|
589
|
-
authenticator_data: encode(response.authenticatorData),
|
|
590
|
-
signature: encode(response.signature),
|
|
591
|
-
user_handle: response.userHandle ? encode(response.userHandle) : ""
|
|
592
|
-
});
|
|
697
|
+
if (!fields) throw new SignInError("method_unavailable");
|
|
698
|
+
await request("passkey_verify", fields);
|
|
593
699
|
});
|
|
594
700
|
}
|
|
701
|
+
createEffect(() => {
|
|
702
|
+
if (attemptedConditional || !conditionalReady() || step() !== "choose" || !config()?.passkey) return;
|
|
703
|
+
if (options.getAcceptance && !options.getAcceptance()) return;
|
|
704
|
+
attemptedConditional = true;
|
|
705
|
+
const attempt = new AbortController();
|
|
706
|
+
conditional = attempt;
|
|
707
|
+
getPasskey(attempt.signal, true).then((fields) => {
|
|
708
|
+
if (fields && !attempt.signal.aborted && !controller.signal.aborted) return run("passkey", async () => {
|
|
709
|
+
await request("passkey_verify", fields);
|
|
710
|
+
});
|
|
711
|
+
}).catch(() => void 0).finally(() => {
|
|
712
|
+
if (conditional === attempt) conditional = void 0;
|
|
713
|
+
});
|
|
714
|
+
});
|
|
595
715
|
function continueWithEmail() {
|
|
596
716
|
if (config()?.otp) return sendCode();
|
|
597
717
|
if (config()?.password && !busy()) go("password");
|
|
@@ -641,6 +761,7 @@ function createSignInController(options) {
|
|
|
641
761
|
});
|
|
642
762
|
}
|
|
643
763
|
return {
|
|
764
|
+
emailRoute: `${route}/email`,
|
|
644
765
|
config,
|
|
645
766
|
configFailed,
|
|
646
767
|
loadConfig,
|
|
@@ -687,12 +808,13 @@ var _tmpl$3 = [
|
|
|
687
808
|
];
|
|
688
809
|
var _tmpl$4 = [
|
|
689
810
|
"<input",
|
|
690
|
-
" type=\"email\" name=\"username\"
|
|
811
|
+
" type=\"email\" name=\"username\"",
|
|
812
|
+
" required maxlength=\"254\"",
|
|
691
813
|
">"
|
|
692
814
|
];
|
|
693
815
|
var _tmpl$5 = [
|
|
694
816
|
"<form",
|
|
695
|
-
" method=\"post\"
|
|
817
|
+
" method=\"post\"",
|
|
696
818
|
"><!--$-->",
|
|
697
819
|
"<!--/--><label",
|
|
698
820
|
">",
|
|
@@ -723,7 +845,7 @@ var _tmpl$7 = [
|
|
|
723
845
|
];
|
|
724
846
|
var _tmpl$8 = [
|
|
725
847
|
"<form",
|
|
726
|
-
" method=\"post\"
|
|
848
|
+
" method=\"post\"",
|
|
727
849
|
"><label",
|
|
728
850
|
">",
|
|
729
851
|
"</label><div",
|
|
@@ -750,7 +872,7 @@ var _tmpl$9 = [
|
|
|
750
872
|
];
|
|
751
873
|
var _tmpl$0 = [
|
|
752
874
|
"<form",
|
|
753
|
-
" method=\"post\"
|
|
875
|
+
" method=\"post\"",
|
|
754
876
|
"><label",
|
|
755
877
|
">",
|
|
756
878
|
"</label><input",
|
|
@@ -805,11 +927,12 @@ var _tmpl$13 = [
|
|
|
805
927
|
];
|
|
806
928
|
var _tmpl$14 = [
|
|
807
929
|
"<form",
|
|
808
|
-
" method=\"post\"
|
|
930
|
+
" method=\"post\"",
|
|
809
931
|
"><label",
|
|
810
932
|
">",
|
|
811
933
|
"</label><input",
|
|
812
|
-
" type=\"email\" name=\"email\"
|
|
934
|
+
" type=\"email\" name=\"email\"",
|
|
935
|
+
" required maxlength=\"254\"",
|
|
813
936
|
"><button type=\"submit\"",
|
|
814
937
|
"",
|
|
815
938
|
">",
|
|
@@ -834,7 +957,7 @@ var _tmpl$16 = [
|
|
|
834
957
|
var _tmpl$17 = [
|
|
835
958
|
"<input",
|
|
836
959
|
" tabindex=\"-1\" hidden name=\"username\"",
|
|
837
|
-
"
|
|
960
|
+
" readonly>"
|
|
838
961
|
];
|
|
839
962
|
var _tmpl$18 = [
|
|
840
963
|
"<span",
|
|
@@ -856,7 +979,7 @@ var icons = {
|
|
|
856
979
|
microsoft: MicrosoftIcon
|
|
857
980
|
};
|
|
858
981
|
function SylphxSignIn(props) {
|
|
859
|
-
const { config, configFailed, loadConfig, step, email, setEmail, errorCode, busy, showPassword, setShowPassword, canPasskey, code, setCode, recovery, setRecovery, wait, continueWithEmail, social, sendCode, verifyCode, passkey, submitPassword, submitMfa } = createSignInController(props);
|
|
982
|
+
const { emailRoute, config, configFailed, loadConfig, step, email, setEmail, errorCode, busy, showPassword, setShowPassword, canPasskey, code, setCode, recovery, setRecovery, wait, continueWithEmail, social, sendCode, verifyCode, passkey, submitPassword, submitMfa } = createSignInController(props);
|
|
860
983
|
const [detected, setDetected] = createSignal();
|
|
861
984
|
const [selected, setSelected] = createSignal();
|
|
862
985
|
const locale = createMemo(() => props.locale === void 0 ? selected() ?? detected() ?? resolveAuthLocale(props.localePreferences ?? []) : resolveAuthLocale([props.locale, ...props.localePreferences ?? []]));
|
|
@@ -952,7 +1075,7 @@ function SylphxSignIn(props) {
|
|
|
952
1075
|
get children() {
|
|
953
1076
|
return ssr(_tmpl$13, ssrHydrationKey() + ssrAttribute("class", escape(className("divider"), true), false), escape(text().orEmail));
|
|
954
1077
|
}
|
|
955
|
-
}), ssr(_tmpl$14, ssrHydrationKey(), ssrAttribute("class", escape(className("form"), true), false), ssrAttribute("for", escape(id("email"), true), false), escape(text().email), ssrAttribute("id", escape(id("email"), true), false), ssrAttribute("value", escape(email(), true), false), ssrAttribute("class", escape(className("primary"), true), false), ssrAttribute("disabled", !!busy(), true), busy() === "email" ? escape(text().sendingCode) : methods().otp ? escape(text().emailCodeAction) : escape(text().continueEmail))];
|
|
1078
|
+
}), ssr(_tmpl$14, ssrHydrationKey(), ssrAttribute("action", escape(emailRoute, true), false) + ssrAttribute("class", escape(className("form"), true), false), ssrAttribute("for", escape(id("email"), true), false), escape(text().email), ssrAttribute("id", escape(id("email"), true), false), ssrAttribute("autocomplete", config()?.passkey ? "username webauthn" : "username", false), ssrAttribute("value", escape(email(), true), false), ssrAttribute("class", escape(className("primary"), true), false), ssrAttribute("disabled", !!busy(), true), busy() === "email" ? escape(text().sendingCode) : methods().otp ? escape(text().emailCodeAction) : escape(text().continueEmail))];
|
|
956
1079
|
}
|
|
957
1080
|
}),
|
|
958
1081
|
createComponent(Show, {
|
|
@@ -988,15 +1111,15 @@ function SylphxSignIn(props) {
|
|
|
988
1111
|
return step() === "password" || step() === "signup" || step() === "confirm";
|
|
989
1112
|
},
|
|
990
1113
|
get children() {
|
|
991
|
-
return [ssr(_tmpl$5, ssrHydrationKey(), ssrAttribute("class", escape(className("form"), true), false), escape(createComponent(Show, {
|
|
1114
|
+
return [ssr(_tmpl$5, ssrHydrationKey(), ssrAttribute("action", escape(emailRoute, true), false) + ssrAttribute("class", escape(className("form"), true), false), escape(createComponent(Show, {
|
|
992
1115
|
get when() {
|
|
993
1116
|
return step() !== "password";
|
|
994
1117
|
},
|
|
995
1118
|
get fallback() {
|
|
996
|
-
return ssr(_tmpl$17, ssrHydrationKey(), ssrAttribute("value", escape(email(), true), false));
|
|
1119
|
+
return ssr(_tmpl$17, ssrHydrationKey(), ssrAttribute("value", escape(email(), true), false) + ssrAttribute("autocomplete", config()?.passkey ? "username webauthn" : "username", false));
|
|
997
1120
|
},
|
|
998
1121
|
get children() {
|
|
999
|
-
return [ssr(_tmpl$3, ssrHydrationKey() + ssrAttribute("for", escape(id("account-email"), true), false), escape(text().email)), ssr(_tmpl$4, ssrHydrationKey() + ssrAttribute("id", escape(id("account-email"), true), false), ssrAttribute("value", escape(email(), true), false))];
|
|
1122
|
+
return [ssr(_tmpl$3, ssrHydrationKey() + ssrAttribute("for", escape(id("account-email"), true), false), escape(text().email)), ssr(_tmpl$4, ssrHydrationKey() + ssrAttribute("id", escape(id("account-email"), true), false), ssrAttribute("autocomplete", config()?.passkey ? "username webauthn" : "username", false), ssrAttribute("value", escape(email(), true), false))];
|
|
1000
1123
|
}
|
|
1001
1124
|
})), ssrAttribute("for", escape(id("password"), true), false), escape(text().password), ssrAttribute("class", escape(className("password"), true), false), ssrAttribute("id", escape(id("password"), true), false) + ssrAttribute("type", showPassword() ? "text" : "password", false) + ssrAttribute("autocomplete", step() === "signup" ? "new-password" : "current-password", false), ssrAttribute("minlength", step() === "signup" ? 12 : escape(void 0, true), false), ssrAttribute("aria-describedby", step() === "signup" ? escape(id("password-hint"), true) : escape(void 0, true), false), ssrAttribute("class", escape(className("link"), true), false) + ssrAttribute("aria-label", showPassword() ? escape(text().hidePassword, true) : escape(text().showPassword, true), false), showPassword() ? escape(text().hide) : escape(text().show), escape(createComponent(Show, {
|
|
1002
1125
|
get when() {
|
|
@@ -1021,7 +1144,7 @@ function SylphxSignIn(props) {
|
|
|
1021
1144
|
return step() === "otp";
|
|
1022
1145
|
},
|
|
1023
1146
|
get children() {
|
|
1024
|
-
return [ssr(_tmpl$8, ssrHydrationKey(), ssrAttribute("class", escape(className("form"), true), false), ssrAttribute("for", escape(id("code"), true), false), escape(text().emailCode), ssrAttribute("class", escape(className("otp"), true), false), ssrAttribute("id", escape(id("code"), true), false), ssrAttribute("value", escape(code(), true), false), ssrAttribute("readonly", !!busy(), true), ssrAttribute("class", escape(className("cells"), true), false), escape(createComponent(For, {
|
|
1147
|
+
return [ssr(_tmpl$8, ssrHydrationKey(), ssrAttribute("action", escape(emailRoute, true), false) + ssrAttribute("class", escape(className("form"), true), false), ssrAttribute("for", escape(id("code"), true), false), escape(text().emailCode), ssrAttribute("class", escape(className("otp"), true), false), ssrAttribute("id", escape(id("code"), true), false), ssrAttribute("value", escape(code(), true), false), ssrAttribute("readonly", !!busy(), true), ssrAttribute("class", escape(className("cells"), true), false), escape(createComponent(For, {
|
|
1025
1148
|
each: [
|
|
1026
1149
|
0,
|
|
1027
1150
|
1,
|
|
@@ -1046,7 +1169,7 @@ function SylphxSignIn(props) {
|
|
|
1046
1169
|
return step() === "mfa";
|
|
1047
1170
|
},
|
|
1048
1171
|
get children() {
|
|
1049
|
-
return [ssr(_tmpl$0, ssrHydrationKey(), ssrAttribute("class", escape(className("form"), true), false), ssrAttribute("for", escape(id("mfa"), true), false), recovery() ? escape(text().recoveryCode) : escape(text().authenticatorCode), ssrAttribute("id", escape(id("mfa"), true), false), ssrAttribute("inputmode", recovery() ? "text" : "numeric", false), ssrAttribute("maxlength", recovery() ? 128 : 6, false), ssrAttribute("class", escape(className("primary"), true), false), ssrAttribute("disabled", !!busy(), true), busy() ? escape(text().checkingCode) : escape(text().verifyAndSignIn)), ssr(_tmpl$1, ssrHydrationKey() + ssrAttribute("class", escape(className("actions"), true), false), ssrAttribute("disabled", !!busy(), true) + ssrAttribute("class", escape(className("link"), true), false), recovery() ? escape(text().useAuthenticator) : escape(text().useRecovery), ssrAttribute("disabled", !!busy(), true) + ssrAttribute("class", escape(className("link"), true), false), escape(text().backToSignIn))];
|
|
1172
|
+
return [ssr(_tmpl$0, ssrHydrationKey(), ssrAttribute("action", escape(emailRoute, true), false) + ssrAttribute("class", escape(className("form"), true), false), ssrAttribute("for", escape(id("mfa"), true), false), recovery() ? escape(text().recoveryCode) : escape(text().authenticatorCode), ssrAttribute("id", escape(id("mfa"), true), false), ssrAttribute("inputmode", recovery() ? "text" : "numeric", false), ssrAttribute("maxlength", recovery() ? 128 : 6, false), ssrAttribute("class", escape(className("primary"), true), false), ssrAttribute("disabled", !!busy(), true), busy() ? escape(text().checkingCode) : escape(text().verifyAndSignIn)), ssr(_tmpl$1, ssrHydrationKey() + ssrAttribute("class", escape(className("actions"), true), false), ssrAttribute("disabled", !!busy(), true) + ssrAttribute("class", escape(className("link"), true), false), recovery() ? escape(text().useAuthenticator) : escape(text().useRecovery), ssrAttribute("disabled", !!busy(), true) + ssrAttribute("class", escape(className("link"), true), false), escape(text().backToSignIn))];
|
|
1050
1173
|
}
|
|
1051
1174
|
})
|
|
1052
1175
|
];
|
|
@@ -4,6 +4,7 @@ declare const errors: {
|
|
|
4
4
|
cancelled: string;
|
|
5
5
|
use_existing: string;
|
|
6
6
|
invalid_credentials: string;
|
|
7
|
+
acceptance_required: string;
|
|
7
8
|
verify_email: string;
|
|
8
9
|
verification_failed: string;
|
|
9
10
|
invalid_code: string;
|
|
@@ -23,9 +24,18 @@ export type SignInControllerOptions = {
|
|
|
23
24
|
search: string;
|
|
24
25
|
/** The same-origin login pathname, used to scrub a confirmation link. */
|
|
25
26
|
loginPath?: string;
|
|
27
|
+
/** Public methods loaded by the host on the server, reused on hydration. */
|
|
28
|
+
initialConfig?: EntryConfig;
|
|
29
|
+
/** Same-origin pathname, defaults to /auth. */
|
|
30
|
+
routePrefix?: string;
|
|
31
|
+
/** Start a discoverable WebAuthn request once on the sign-in screen. */
|
|
32
|
+
conditionalPasskey?: boolean;
|
|
33
|
+
/** Return only versions the user has accepted; undefined means no acceptance. */
|
|
34
|
+
getAcceptance?: () => Readonly<Record<string, string>> | undefined;
|
|
26
35
|
};
|
|
27
36
|
/** Create under a Solid owner. Requests start on mount and abort on cleanup. */
|
|
28
37
|
export declare function createSignInController(options: SignInControllerOptions): {
|
|
38
|
+
emailRoute: string;
|
|
29
39
|
config: import("solid-js").Accessor<EntryConfig | undefined>;
|
|
30
40
|
configFailed: import("solid-js").Accessor<boolean>;
|
|
31
41
|
loadConfig: () => Promise<void>;
|
|
@@ -34,7 +44,7 @@ export declare function createSignInController(options: SignInControllerOptions)
|
|
|
34
44
|
email: import("solid-js").Accessor<string>;
|
|
35
45
|
setEmail: import("solid-js").Setter<string>;
|
|
36
46
|
error: () => string;
|
|
37
|
-
errorCode: import("solid-js").Accessor<"" | "signin" | "cancelled" | "use_existing" | "invalid_credentials" | "verify_email" | "verification_failed" | "invalid_code" | "method_unavailable" | "signup_failed" | "invalid_input" | "try_later" | "unavailable">;
|
|
47
|
+
errorCode: import("solid-js").Accessor<"" | "signin" | "cancelled" | "use_existing" | "invalid_credentials" | "acceptance_required" | "verify_email" | "verification_failed" | "invalid_code" | "method_unavailable" | "signup_failed" | "invalid_input" | "try_later" | "unavailable">;
|
|
38
48
|
busy: import("solid-js").Accessor<string>;
|
|
39
49
|
showPassword: import("solid-js").Accessor<boolean>;
|
|
40
50
|
setShowPassword: import("solid-js").Setter<boolean>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sylphx/auth-solid",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"build": "tsc -p tsconfig.build.json && node build.mjs"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@sylphx/auth": "0.1.
|
|
23
|
+
"@sylphx/auth": "0.1.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"solid-js": "^1.9.20"
|