@krak-stack/auth 0.2.22 → 0.2.24
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/CHANGELOG.md +20 -0
- package/README.md +54 -0
- package/dist/api.d.ts +1364 -1364
- package/dist/components/admin-organizations.js +8 -3
- package/dist/components/admin-users.js +15 -5
- package/dist/components/auth-forms.js +144 -61
- package/dist/components/email-otp-state.d.ts +11 -0
- package/dist/components/email-otp-state.js +25 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/organization-switcher.js +6 -4
- package/dist/components/password-field.d.ts +15 -0
- package/dist/components/password-field.js +12 -0
- package/dist/components/password-reset-flow.d.ts +25 -0
- package/dist/components/password-reset-flow.js +51 -0
- package/dist/components/password-reset.d.ts +34 -0
- package/dist/components/password-reset.js +41 -0
- package/dist/components/user-button.d.ts +18 -0
- package/dist/components/user-button.js +147 -69
- package/dist/server/actor.js +1 -13
- package/dist/server/attribution.d.ts +3 -0
- package/dist/server/attribution.js +26 -0
- package/dist/server/index.d.ts +1 -1
- package/dist/server/middleware.d.ts +7 -1
- package/dist/server/middleware.js +60 -28
- package/package.json +3 -3
|
@@ -7,7 +7,7 @@ import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
|
|
|
7
7
|
import { ArrowLeft, Building2, KeyRound, Loader2, LogOutIcon, Mail, Pencil, Plus, ShieldCheck, StopCircle, Trash2, UserCircleIcon, Users, UserIcon, } from "lucide-react";
|
|
8
8
|
import { QRCode } from "react-qr-code";
|
|
9
9
|
import { createContext, useContext, useRef, useEffect, useState, } from "react";
|
|
10
|
-
import { DataTable,
|
|
10
|
+
import { DataTable, } from "@krak-stack/registry/data-table";
|
|
11
11
|
import { AppBrand } from "@krak-stack/registry/app-brand";
|
|
12
12
|
import { EditingLocaleSwitcher } from "@krak-stack/registry/editing-locale-switcher";
|
|
13
13
|
import { effectFormMessages, ImageField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
|
|
@@ -17,7 +17,11 @@ import { CopyButton } from "@krak-stack/registry/copy-button";
|
|
|
17
17
|
import { Dialog, DialogFooter, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
18
18
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
19
19
|
import { Separator } from "@/components/ui/separator";
|
|
20
|
+
import { FieldLabel } from "@/components/ui/field";
|
|
21
|
+
import { Input } from "@/components/ui/input";
|
|
20
22
|
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
23
|
+
import { PasswordField } from "./password-field.js";
|
|
24
|
+
import { PasswordResetActions, PasswordResetFeedback, usePasswordResetRequest, } from "./password-reset-flow.js";
|
|
21
25
|
import { authSessionAtom, notifyAuthChange } from "./auth-atoms.js";
|
|
22
26
|
import { useKrakstackAuth } from "./auth-provider.js";
|
|
23
27
|
import { parseApiKeyReferrers } from "./api-key.js";
|
|
@@ -44,6 +48,13 @@ const messages = {
|
|
|
44
48
|
user_account_confirm_revoke: "Revoke account",
|
|
45
49
|
user_account_connected: "Connected",
|
|
46
50
|
user_account_current_password: "Current password",
|
|
51
|
+
sign_in_forgot_password: "Forgot your password?",
|
|
52
|
+
user_password_reset_title: "Check your email",
|
|
53
|
+
user_password_reset_description: "We sent you a link to reset your password. After resetting, sign in again to continue.",
|
|
54
|
+
user_password_reset_error: "Unable to send password reset email. Please try again.",
|
|
55
|
+
user_password_reset_sending: "Sending reset email…",
|
|
56
|
+
user_password_reset_resend: "Resend email",
|
|
57
|
+
user_password_reset_countdown: "Resend in {seconds}s",
|
|
47
58
|
user_account_google_connect: "Set up",
|
|
48
59
|
user_account_google_description: "Use your Google account as a sign-in option.",
|
|
49
60
|
user_account_google_link_error: "Could not connect Google.",
|
|
@@ -140,6 +151,7 @@ const messages = {
|
|
|
140
151
|
user_contact_add_website: "Add website",
|
|
141
152
|
user_contact_description: "Add up to 8 public contacts of each type, separately from the email used to sign in.",
|
|
142
153
|
user_contact_email_type: "Email",
|
|
154
|
+
user_contact_primary: "Primary",
|
|
143
155
|
user_contact_extension: "Extension",
|
|
144
156
|
user_contact_label: "Label",
|
|
145
157
|
user_contact_phone_type: "Phone",
|
|
@@ -181,6 +193,13 @@ const messages = {
|
|
|
181
193
|
user_account_confirm_revoke: "Révoquer le compte",
|
|
182
194
|
user_account_connected: "Connecté",
|
|
183
195
|
user_account_current_password: "Mot de passe actuel",
|
|
196
|
+
sign_in_forgot_password: "Mot de passe oublié?",
|
|
197
|
+
user_password_reset_title: "Consultez votre courriel",
|
|
198
|
+
user_password_reset_description: "Nous vous avons envoyé un lien pour réinitialiser votre mot de passe. Après la réinitialisation, reconnectez-vous pour continuer.",
|
|
199
|
+
user_password_reset_error: "Impossible d’envoyer le courriel de réinitialisation. Veuillez réessayer.",
|
|
200
|
+
user_password_reset_sending: "Envoi du courriel de réinitialisation…",
|
|
201
|
+
user_password_reset_resend: "Renvoyer le courriel",
|
|
202
|
+
user_password_reset_countdown: "Renvoyer dans {seconds} s",
|
|
184
203
|
user_account_google_connect: "Configurer",
|
|
185
204
|
user_account_google_description: "Utilisez votre compte Google comme option de connexion.",
|
|
186
205
|
user_account_google_link_error: "Impossible de connecter Google.",
|
|
@@ -277,6 +296,7 @@ const messages = {
|
|
|
277
296
|
user_contact_add_website: "Ajouter un site Web",
|
|
278
297
|
user_contact_description: "Ajoutez jusqu’à 8 coordonnées publiques de chaque type, distinctes du courriel utilisé pour vous connecter.",
|
|
279
298
|
user_contact_email_type: "Courriel",
|
|
299
|
+
user_contact_primary: "Principal",
|
|
280
300
|
user_contact_extension: "Poste",
|
|
281
301
|
user_contact_label: "Libellé",
|
|
282
302
|
user_contact_phone_type: "Téléphone",
|
|
@@ -360,6 +380,14 @@ const hasAdminRole = (user) => {
|
|
|
360
380
|
const decoded = Schema.decodeUnknownOption(UserRole)(user);
|
|
361
381
|
return Option.isSome(decoded) && hasRole(decoded.value.role, ["admin"]);
|
|
362
382
|
};
|
|
383
|
+
export const userContactEmailDefaults = (metadata, email) => (metadata.emails ?? []).filter((contact) => contact.email.trim().toLowerCase() !== email.trim().toLowerCase());
|
|
384
|
+
export const userPrimaryContactEmail = (email) => ({
|
|
385
|
+
email,
|
|
386
|
+
translations: [
|
|
387
|
+
{ locale: "en", label: messages.en.user_contact_primary },
|
|
388
|
+
{ locale: "fr", label: messages.fr.user_contact_primary },
|
|
389
|
+
],
|
|
390
|
+
});
|
|
363
391
|
const changePasswordFormBuilder = FormBuilder.empty
|
|
364
392
|
.addField("currentPassword", Schema.NonEmptyString)
|
|
365
393
|
.addField("newPassword", Schema.NonEmptyString);
|
|
@@ -491,6 +519,8 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
491
519
|
const [totpSetup, setTotpSetup] = useState(null);
|
|
492
520
|
const [managingTwoFactor, setManagingTwoFactor] = useState(false);
|
|
493
521
|
const [revokingAccount, setRevokingAccount] = useState(null);
|
|
522
|
+
const [passwordResetVisible, setPasswordResetVisible] = useState(false);
|
|
523
|
+
const passwordReset = usePasswordResetRequest(resolvedBaseUrl);
|
|
494
524
|
const settingsDialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
|
|
495
525
|
const [formError, setFormError] = useState(null);
|
|
496
526
|
const shouldLoadAccounts = Boolean(session) &&
|
|
@@ -553,6 +583,20 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
553
583
|
const canManageUserSettings = !isOrganizationImpersonating;
|
|
554
584
|
const canUseAdminSettings = !isOrganizationImpersonating;
|
|
555
585
|
const isAdmin = hasAdminRole(session.user);
|
|
586
|
+
const startPasswordReset = () => {
|
|
587
|
+
if (passwordReset.result.waiting)
|
|
588
|
+
return;
|
|
589
|
+
if (passwordReset.resendSeconds > 0) {
|
|
590
|
+
setPasswordResetVisible(true);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
passwordReset.send({
|
|
594
|
+
locale: getLocale,
|
|
595
|
+
email: displayEmail,
|
|
596
|
+
redirectTo: `${window.location.origin}/reset-password`,
|
|
597
|
+
onSent: () => setPasswordResetVisible(true),
|
|
598
|
+
});
|
|
599
|
+
};
|
|
556
600
|
const startSignOut = () => {
|
|
557
601
|
const redirectUrl = signOutRedirect.startsWith("http")
|
|
558
602
|
? signOutRedirect
|
|
@@ -565,17 +609,23 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
565
609
|
refreshSession,
|
|
566
610
|
}), children: [_jsx(StopCircle, {}), m.user_button_stop_impersonating()] })) : null, _jsx(DropdownMenuSeparator, {})] })) : null, _jsxs(DropdownMenuItem, { disabled: signOutResult.waiting, onClick: startSignOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] }), authActionError ? (_jsx(DropdownMenuLabel, { className: "text-destructive text-xs font-normal", children: authActionError })) : null] }) })] })), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "account", onOpenChange: (open) => {
|
|
567
611
|
setSettingsDialog((current) => open ? "account" : current === "account" ? null : current);
|
|
568
|
-
}, children: _jsx(UserForm, { defaultValues: {
|
|
612
|
+
}, children: _jsx(UserForm, { primaryEmail: displayEmail, defaultValues: {
|
|
569
613
|
name: displayName ?? "",
|
|
570
614
|
image: displayImage || null,
|
|
571
|
-
emails:
|
|
615
|
+
emails: userContactEmailDefaults(metadata, displayEmail),
|
|
572
616
|
phones: Array.from(metadata.phones ?? []),
|
|
573
617
|
websites: Array.from(metadata.websites ?? []),
|
|
574
618
|
socials: Array.from(metadata.socials ?? []),
|
|
575
619
|
}, error: formError, onSubmit: (values) => Effect.gen(function* () {
|
|
576
620
|
setFormError(null);
|
|
577
621
|
const metadata = yield* Effect.try({
|
|
578
|
-
try: () => userMetadataFromForm(
|
|
622
|
+
try: () => userMetadataFromForm({
|
|
623
|
+
...values,
|
|
624
|
+
emails: [
|
|
625
|
+
userPrimaryContactEmail(displayEmail),
|
|
626
|
+
...values.emails,
|
|
627
|
+
],
|
|
628
|
+
}),
|
|
579
629
|
catch: () => new Error(m.user_contact_validation_error()),
|
|
580
630
|
});
|
|
581
631
|
const imageFile = isFile(values.image) ? values.image : null;
|
|
@@ -599,54 +649,68 @@ export const UserButton = ({ baseUrl, signOutRedirect = "/", side = "bottom", de
|
|
|
599
649
|
}).pipe(Effect.tapError((error) => Effect.sync(() => setFormError(error instanceof Error
|
|
600
650
|
? error.message
|
|
601
651
|
: m.user_form_update_error())))) }) }), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "security", onOpenChange: (open) => {
|
|
652
|
+
setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
|
|
653
|
+
}, onOpenChangeComplete: (open) => {
|
|
654
|
+
if (open)
|
|
655
|
+
return;
|
|
656
|
+
// Keep the active page intact until the exit animation has finished.
|
|
657
|
+
setPasswordResetVisible(false);
|
|
602
658
|
setChangingPassword(false);
|
|
603
659
|
setSettingPassword(false);
|
|
604
660
|
setTotpSetup(null);
|
|
605
661
|
setManagingTwoFactor(false);
|
|
606
662
|
setRevokingAccount(null);
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
? m.user_account_password_change_title()
|
|
610
|
-
: settingPassword
|
|
611
|
-
? m.user_account_password_set()
|
|
612
|
-
: revokingAccount
|
|
613
|
-
? m.user_account_revoke()
|
|
614
|
-
: managingTwoFactor
|
|
615
|
-
? m.user_two_factor_title()
|
|
616
|
-
: m.user_security_title() }), _jsx(DialogDescription, { children: changingPassword
|
|
617
|
-
? m.user_account_password_change_description()
|
|
618
|
-
: settingPassword
|
|
619
|
-
? m.user_account_password_description()
|
|
620
|
-
: revokingAccount
|
|
621
|
-
? m.user_account_revoke_description({
|
|
622
|
-
provider: providerName(revokingAccount.providerId, m),
|
|
623
|
-
})
|
|
624
|
-
: managingTwoFactor
|
|
625
|
-
? m.user_two_factor_description()
|
|
626
|
-
: m.user_security_description() })] }), changingPassword ||
|
|
663
|
+
}, children: _jsxs(ScrollableDialogContent, { size: "3xl", children: [_jsx(ScrollableDialogHeader, { children: _jsxs(DialogHeader, { className: "gap-4", children: [passwordResetVisible ||
|
|
664
|
+
changingPassword ||
|
|
627
665
|
settingPassword ||
|
|
628
666
|
revokingAccount ||
|
|
629
|
-
managingTwoFactor ? (_jsxs(Button, { className: "
|
|
667
|
+
managingTwoFactor ? (_jsxs(Button, { className: "h-auto w-fit p-0", type: "button", variant: "link", disabled: passwordResetVisible && passwordReset.result.waiting, onClick: () => {
|
|
668
|
+
if (passwordResetVisible) {
|
|
669
|
+
setPasswordResetVisible(false);
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
630
672
|
setChangingPassword(false);
|
|
631
673
|
setSettingPassword(false);
|
|
632
674
|
setTotpSetup(null);
|
|
633
675
|
setManagingTwoFactor(false);
|
|
634
676
|
setRevokingAccount(null);
|
|
635
|
-
}, children: [_jsx(ArrowLeft, {}), m.user_account_back()] })) : null
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
677
|
+
}, children: [_jsx(ArrowLeft, {}), m.user_account_back()] })) : null, _jsxs("div", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(DialogTitle, { className: "text-2xl", children: passwordResetVisible
|
|
678
|
+
? m.user_password_reset_title()
|
|
679
|
+
: changingPassword
|
|
680
|
+
? m.user_account_password_change_title()
|
|
681
|
+
: settingPassword
|
|
682
|
+
? m.user_account_password_set()
|
|
683
|
+
: revokingAccount
|
|
684
|
+
? m.user_account_revoke()
|
|
685
|
+
: managingTwoFactor
|
|
686
|
+
? m.user_two_factor_title()
|
|
687
|
+
: m.user_security_title() }), _jsx(DialogDescription, { children: passwordResetVisible
|
|
688
|
+
? m.user_password_reset_description()
|
|
689
|
+
: changingPassword
|
|
690
|
+
? m.user_account_password_change_description()
|
|
691
|
+
: settingPassword
|
|
692
|
+
? m.user_account_password_description()
|
|
693
|
+
: revokingAccount
|
|
694
|
+
? m.user_account_revoke_description({
|
|
695
|
+
provider: providerName(revokingAccount.providerId, m),
|
|
696
|
+
})
|
|
697
|
+
: managingTwoFactor
|
|
698
|
+
? m.user_two_factor_description()
|
|
699
|
+
: m.user_security_description() })] })] }) }), _jsxs(ScrollableDialogBody, { children: [_jsx(PasswordResetFeedback, { pending: passwordReset.result.waiting, sendingLabel: m.user_password_reset_sending(), error: AsyncResult.isFailure(passwordReset.result) ? (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: m.user_password_reset_error() })) : null }), passwordResetVisible ? (_jsx(PasswordResetActions, { pending: passwordReset.result.waiting, resendSeconds: passwordReset.resendSeconds, onResend: startPasswordReset, resendLabel: m.user_password_reset_resend(), countdownLabel: (seconds) => m.user_password_reset_countdown({ seconds }) })) : changingPassword ? (_jsx(ChangePasswordForm, { baseUrl: resolvedBaseUrl, onResetPassword: startPasswordReset })) : settingPassword ? (_jsx(SetPasswordForm, { baseUrl: resolvedBaseUrl, onSaved: async () => {
|
|
700
|
+
await accountCache.reload();
|
|
701
|
+
setSettingPassword(false);
|
|
702
|
+
} })) : revokingAccount ? (_jsx(RevokeAccountForm, { onResetPassword: startPasswordReset, baseUrl: resolvedBaseUrl, account: revokingAccount, requirePassword: requiresPasswordForAccountRevoke(accountCache.accounts ?? []), onCancel: () => setRevokingAccount(null), onRevoked: async () => {
|
|
703
|
+
await accountCache.reload();
|
|
704
|
+
setRevokingAccount(null);
|
|
705
|
+
} })) : totpSetup ? (_jsx(VerifyTotpSetup, { baseUrl: resolvedBaseUrl, setup: totpSetup, onVerified: async () => {
|
|
706
|
+
await refreshSession();
|
|
707
|
+
setTotpSetup(null);
|
|
708
|
+
setManagingTwoFactor(false);
|
|
709
|
+
} })) : managingTwoFactor ? (_jsx(AccountSecuritySettings, { onResetPassword: startPasswordReset, baseUrl: resolvedBaseUrl, accountCache: accountCache, onSetup: setTotpSetup })) : (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(ConnectedAccounts, { onChangePassword: () => setChangingPassword(true), onSetupPassword: () => setSettingPassword(true), onRevokeAccount: setRevokingAccount, baseUrl: resolvedBaseUrl, accountCache: accountCache, googleEnabled: projectConfig?.authOptions.google ?? true, currentSiteHref: currentSiteHref, navigate: navigate }), _jsx(Separator, {}), _jsxs("section", { className: "flex flex-col gap-6", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_two_factor_title() }), _jsx("p", { className: "text-muted-foreground text-xs", children: m.user_two_factor_description() })] }), _jsx(Badge, { variant: hasTwoFactorEnabled(session?.user)
|
|
710
|
+
? "default"
|
|
711
|
+
: "secondary", children: hasTwoFactorEnabled(session?.user)
|
|
712
|
+
? m.user_two_factor_enabled()
|
|
713
|
+
: m.user_two_factor_disabled() })] }), hasTwoFactorEnabled(session?.user) ? (_jsx(AccountSecuritySettings, { onResetPassword: startPasswordReset, baseUrl: resolvedBaseUrl, accountCache: accountCache, onSetup: setTotpSetup })) : (_jsx(Button, { type: "button", className: "self-start", onClick: () => setManagingTwoFactor(true), children: m.user_two_factor_enable_submit() }))] })] }))] })] }) }), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "apiKeys", onOpenChange: (open) => {
|
|
650
714
|
setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
651
715
|
}, children: _jsx(ScrollableDialogContent, { size: "4xl", children: _jsx(ApiKeyManager, { baseUrl: resolvedBaseUrl, active: settingsDialog === "apiKeys", locale: auth?.locale ?? "en", permissionLabels: auth?.accessLabels ?? undefined, permissions: apiKeyPermissions ?? auth?.access?.apiKeyPermissions.user ?? {} }) }) }), isAdmin ? (_jsxs(_Fragment, { children: [_jsx(Dialog, { open: settingsDialog === "adminUsers", onOpenChange: (open) => {
|
|
652
716
|
setSettingsDialog((current) => open ? "adminUsers" : current === "adminUsers" ? null : current);
|
|
@@ -712,13 +776,13 @@ function PasswordSettings({ onSetupPassword, onRevokeAccount, onChangePassword,
|
|
|
712
776
|
? m.user_account_password_connected_description()
|
|
713
777
|
: m.user_account_password_description() })] })] }), passwordAccount ? (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Button, { type: "button", variant: "outline", onClick: onChangePassword, children: m.user_account_change() }), _jsx(Button, { type: "button", variant: "outline", onClick: () => onRevokeAccount(passwordAccount), children: m.user_account_revoke() })] })) : (_jsx(Button, { type: "button", variant: "outline", onClick: onSetupPassword, children: m.user_account_password_setup() }))] }) })) : !accountCache.error ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, accountCache.error ? (_jsx("p", { className: "text-destructive text-sm", children: accountCache.error })) : null] }));
|
|
714
778
|
}
|
|
715
|
-
function ChangePasswordForm({ baseUrl }) {
|
|
779
|
+
function ChangePasswordForm({ baseUrl, onResetPassword, }) {
|
|
716
780
|
const m = useUserButtonMessages();
|
|
717
781
|
const [saved, setSaved] = useState(false);
|
|
718
782
|
let reset = () => { };
|
|
719
783
|
const [form] = useState(() => FormReact.make(changePasswordFormBuilder, {
|
|
720
784
|
runtime: authClientApi(baseUrl).runtime,
|
|
721
|
-
fields: { currentPassword:
|
|
785
|
+
fields: { currentPassword: PasswordField, newPassword: PasswordField },
|
|
722
786
|
mode: { validation: "onSubmit" },
|
|
723
787
|
onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.tap(() => Effect.sync(() => setSaved(false))), Effect.flatMap((client) => client.auth.changePassword({
|
|
724
788
|
payload: {
|
|
@@ -736,13 +800,16 @@ function ChangePasswordForm({ baseUrl }) {
|
|
|
736
800
|
event.preventDefault();
|
|
737
801
|
event.stopPropagation();
|
|
738
802
|
submit();
|
|
739
|
-
}, children: [_jsx(form.currentPassword, { label: m.user_account_current_password(),
|
|
803
|
+
}, children: [_jsx(form.currentPassword, { label: m.user_account_current_password(), autoComplete: "current-password", recovery: {
|
|
804
|
+
label: m.sign_in_forgot_password(),
|
|
805
|
+
onClick: onResetPassword,
|
|
806
|
+
}, required: true }), _jsx(form.newPassword, { label: m.user_account_new_password(), autoComplete: "new-password", required: true }), _jsx(SubmitError, { result: submitResult }), saved ? (_jsx("p", { className: "text-sm text-green-600", children: m.user_account_password_change_success() })) : null, _jsx(SubmitButton, { form: form, children: m.user_account_password_change_submit() })] }) }));
|
|
740
807
|
}
|
|
741
808
|
function SetPasswordForm({ baseUrl, onSaved, }) {
|
|
742
809
|
const m = useUserButtonMessages();
|
|
743
810
|
const [form] = useState(() => FormReact.make(passwordFormBuilder(true), {
|
|
744
811
|
runtime: authClientApi(baseUrl).runtime,
|
|
745
|
-
fields: { password:
|
|
812
|
+
fields: { password: PasswordField },
|
|
746
813
|
mode: { validation: "onSubmit" },
|
|
747
814
|
onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.authExtra.setPassword({
|
|
748
815
|
payload: { newPassword: decoded.password },
|
|
@@ -756,13 +823,13 @@ function SetPasswordForm({ baseUrl, onSaved, }) {
|
|
|
756
823
|
event.preventDefault();
|
|
757
824
|
event.stopPropagation();
|
|
758
825
|
submit();
|
|
759
|
-
}, children: [_jsx(form.password, { label: m.user_account_new_password(),
|
|
826
|
+
}, children: [_jsx(form.password, { label: m.user_account_new_password(), autoComplete: "new-password", required: true }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form, children: m.user_account_password_set() })] }) }));
|
|
760
827
|
}
|
|
761
|
-
function RevokeAccountForm({ baseUrl, account, requirePassword, onCancel, onRevoked, }) {
|
|
828
|
+
function RevokeAccountForm({ baseUrl, onResetPassword, account, requirePassword, onCancel, onRevoked, }) {
|
|
762
829
|
const m = useUserButtonMessages();
|
|
763
830
|
const [form] = useState(() => FormReact.make(passwordFormBuilder(requirePassword), {
|
|
764
831
|
runtime: authClientApi(baseUrl).runtime,
|
|
765
|
-
fields: { password:
|
|
832
|
+
fields: { password: PasswordField },
|
|
766
833
|
mode: { validation: "onSubmit" },
|
|
767
834
|
onSubmit: (_, { decoded }) => Effect.gen(function* () {
|
|
768
835
|
const client = yield* authHttpClient(baseUrl);
|
|
@@ -793,7 +860,10 @@ function RevokeAccountForm({ baseUrl, account, requirePassword, onCancel, onRevo
|
|
|
793
860
|
event.preventDefault();
|
|
794
861
|
event.stopPropagation();
|
|
795
862
|
submit();
|
|
796
|
-
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(),
|
|
863
|
+
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(), autoComplete: "current-password", recovery: {
|
|
864
|
+
label: m.sign_in_forgot_password(),
|
|
865
|
+
onClick: onResetPassword,
|
|
866
|
+
}, required: true })) : null, _jsx(SubmitError, { result: submitResult }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(Button, { type: "button", variant: "outline", onClick: onCancel, children: m.user_account_cancel() }), requirePassword ? (_jsx(SubmitButton, { form: form, children: m.user_confirm_password() })) : (_jsxs(Button, { type: "button", disabled: submitResult.waiting, onClick: () => submit(), children: [submitResult.waiting ? (_jsx(Loader2, { "data-icon": "inline-start", className: "animate-spin" })) : null, m.user_account_confirm_revoke()] }))] })] }) }));
|
|
797
867
|
}
|
|
798
868
|
const providerName = (providerId, m) => {
|
|
799
869
|
if (providerId === "google")
|
|
@@ -802,7 +872,7 @@ const providerName = (providerId, m) => {
|
|
|
802
872
|
return m.user_account_password_title();
|
|
803
873
|
return providerId;
|
|
804
874
|
};
|
|
805
|
-
const UserForm = ({ defaultValues, error, onSubmit, }) => {
|
|
875
|
+
const UserForm = ({ defaultValues, primaryEmail, error, onSubmit, }) => {
|
|
806
876
|
const auth = useKrakstackAuth();
|
|
807
877
|
const m = useUserButtonMessages();
|
|
808
878
|
const [editingLocale, setEditingLocale] = useState(getLocale());
|
|
@@ -830,10 +900,10 @@ const UserForm = ({ defaultValues, error, onSubmit, }) => {
|
|
|
830
900
|
height: 40,
|
|
831
901
|
suggestedWidth: 512,
|
|
832
902
|
suggestedHeight: 512,
|
|
833
|
-
} }), _jsx(form.name, { label: m.user_form_name_label(), autoComplete: "name", required: true }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h3", { className: "text-sm leading-none font-medium", children: m.user_contact_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_contact_description() })] }), _jsx(EditingLocaleSwitcher, { locale: auth?.locale, value: editingLocale, onValueChange: (value) => setEditingLocale(value === "fr" ? "fr" : "en") })] }),
|
|
903
|
+
} }), _jsx(form.name, { label: m.user_form_name_label(), autoComplete: "name", required: true }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h3", { className: "text-sm leading-none font-medium", children: m.user_contact_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_contact_description() })] }), _jsx(EditingLocaleSwitcher, { locale: auth?.locale, value: editingLocale, onValueChange: (value) => setEditingLocale(value === "fr" ? "fr" : "en") })] }), _jsxs(UserContactGroup, { title: m.user_contact_email_type(), children: [_jsxs("div", { className: "bg-muted/20 rounded-lg border p-4", children: [_jsx(FieldLabel, { htmlFor: "user-primary-contact-email", children: m.user_contact_primary() }), _jsx(Input, { id: "user-primary-contact-email", className: "mt-2", type: "email", value: primaryEmail, readOnly: true })] }), _jsx(form.emails, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT - 1, messages: userContactFieldMessages(m) })] }), _jsx(UserContactGroup, { title: m.user_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) }), _jsx(UserContactGroup, { title: m.user_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale, maxItems: USER_CONTACT_LIMIT, messages: userContactFieldMessages(m) }) })] })] }), _jsx(DialogFooter, { className: "-mx-6 -mb-6 border-t px-6 py-4", children: _jsxs("div", { className: "flex flex-col gap-3", children: [error && (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: error })), _jsx(SubmitButton, { form: form })] }) })] }) }) }));
|
|
834
904
|
};
|
|
835
905
|
const UserContactGroup = ({ children, title, }) => (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsx("h4", { className: "text-sm font-medium", children: title }), children] }));
|
|
836
|
-
function AccountSecuritySettings({ baseUrl, accountCache, onSetup, }) {
|
|
906
|
+
function AccountSecuritySettings({ baseUrl, onResetPassword, accountCache, onSetup, }) {
|
|
837
907
|
const m = useUserButtonMessages();
|
|
838
908
|
const sessionAtom = authSessionAtom(baseUrl);
|
|
839
909
|
const sessionResult = useAtomValue(sessionAtom);
|
|
@@ -850,16 +920,16 @@ function AccountSecuritySettings({ baseUrl, accountCache, onSetup, }) {
|
|
|
850
920
|
: null;
|
|
851
921
|
return (_jsxs("div", { className: "flex flex-col gap-6", children: [requirePassword === null ? (_jsx("p", { className: accountCache.error
|
|
852
922
|
? "text-destructive text-sm"
|
|
853
|
-
: "text-muted-foreground text-sm", children: accountCache.error ?? m.user_loading() })) : twoFactorEnabled ? (_jsx(DisableTotpForm, { baseUrl: baseUrl, requirePassword: requirePassword, onDisabled: async () => {
|
|
923
|
+
: "text-muted-foreground text-sm", children: accountCache.error ?? m.user_loading() })) : twoFactorEnabled ? (_jsx(DisableTotpForm, { onResetPassword: onResetPassword, baseUrl: baseUrl, requirePassword: requirePassword, onDisabled: async () => {
|
|
854
924
|
setMessage(m.user_two_factor_disabled_message());
|
|
855
925
|
await refreshSession();
|
|
856
|
-
} })) : (_jsx(EnableTotpForm, { baseUrl: baseUrl, requirePassword: requirePassword, onEnabled: onSetup })), message ? (_jsx("p", { className: "text-muted-foreground text-sm", children: message })) : null] }));
|
|
926
|
+
} })) : (_jsx(EnableTotpForm, { onResetPassword: onResetPassword, baseUrl: baseUrl, requirePassword: requirePassword, onEnabled: onSetup })), message ? (_jsx("p", { className: "text-muted-foreground text-sm", children: message })) : null] }));
|
|
857
927
|
}
|
|
858
|
-
function EnableTotpForm({ baseUrl, requirePassword, onEnabled, }) {
|
|
928
|
+
function EnableTotpForm({ baseUrl, onResetPassword, requirePassword, onEnabled, }) {
|
|
859
929
|
const m = useUserButtonMessages();
|
|
860
930
|
const [form] = useState(() => FormReact.make(passwordFormBuilder(requirePassword), {
|
|
861
931
|
runtime: authClientApi(baseUrl).runtime,
|
|
862
|
-
fields: { password:
|
|
932
|
+
fields: { password: PasswordField },
|
|
863
933
|
mode: { validation: "onSubmit" },
|
|
864
934
|
onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.twoFactorEnable({
|
|
865
935
|
payload: requirePassword ? { password: decoded.password } : {},
|
|
@@ -883,7 +953,10 @@ function EnableTotpForm({ baseUrl, requirePassword, onEnabled, }) {
|
|
|
883
953
|
event.preventDefault();
|
|
884
954
|
event.stopPropagation();
|
|
885
955
|
submit();
|
|
886
|
-
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(),
|
|
956
|
+
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(), autoComplete: "current-password", recovery: {
|
|
957
|
+
label: m.sign_in_forgot_password(),
|
|
958
|
+
onClick: onResetPassword,
|
|
959
|
+
}, required: true })) : null, _jsx(SubmitError, { result: submitResult }), requirePassword ? (_jsx(SubmitButton, { form: form, children: m.user_confirm_password() })) : (_jsxs(Button, { type: "button", disabled: submitResult.waiting, onClick: () => submit(), children: [submitResult.waiting ? (_jsx(Loader2, { "data-icon": "inline-start", className: "animate-spin" })) : null, m.user_two_factor_enable_submit()] }))] }) }));
|
|
887
960
|
}
|
|
888
961
|
function VerifyTotpSetup({ baseUrl, setup, onVerified, }) {
|
|
889
962
|
const m = useUserButtonMessages();
|
|
@@ -905,11 +978,11 @@ function VerifyTotpSetup({ baseUrl, setup, onVerified, }) {
|
|
|
905
978
|
submit();
|
|
906
979
|
}, children: [_jsx(form.code, { label: m.user_two_factor_code(), autoComplete: "one-time-code", inputMode: "numeric", required: true }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) })] }));
|
|
907
980
|
}
|
|
908
|
-
function DisableTotpForm({ baseUrl, requirePassword, onDisabled, }) {
|
|
981
|
+
function DisableTotpForm({ baseUrl, onResetPassword, requirePassword, onDisabled, }) {
|
|
909
982
|
const m = useUserButtonMessages();
|
|
910
983
|
const [form] = useState(() => FormReact.make(passwordFormBuilder(requirePassword), {
|
|
911
984
|
runtime: authClientApi(baseUrl).runtime,
|
|
912
|
-
fields: { password:
|
|
985
|
+
fields: { password: PasswordField },
|
|
913
986
|
mode: { validation: "onSubmit" },
|
|
914
987
|
onSubmit: (_, { decoded }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.twoFactorDisable({
|
|
915
988
|
payload: requirePassword ? { password: decoded.password } : {},
|
|
@@ -923,7 +996,10 @@ function DisableTotpForm({ baseUrl, requirePassword, onDisabled, }) {
|
|
|
923
996
|
event.preventDefault();
|
|
924
997
|
event.stopPropagation();
|
|
925
998
|
submit();
|
|
926
|
-
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(),
|
|
999
|
+
}, children: [requirePassword ? (_jsx(form.password, { label: m.user_field_password(), autoComplete: "current-password", recovery: {
|
|
1000
|
+
label: m.sign_in_forgot_password(),
|
|
1001
|
+
onClick: onResetPassword,
|
|
1002
|
+
}, required: true })) : null, _jsx(SubmitError, { result: submitResult }), requirePassword ? (_jsx(SubmitButton, { form: form, children: m.user_confirm_password() })) : (_jsxs(Button, { type: "button", disabled: submitResult.waiting, onClick: () => submit(), children: [submitResult.waiting ? (_jsx(Loader2, { "data-icon": "inline-start", className: "animate-spin" })) : null, effectFormMessages().submit] }))] }) }));
|
|
927
1003
|
}
|
|
928
1004
|
function ApiKeyManager({ baseUrl, active, locale, permissionLabels, permissions = {}, }) {
|
|
929
1005
|
const m = useUserButtonMessages();
|
|
@@ -995,7 +1071,11 @@ function ApiKeyManager({ baseUrl, active, locale, permissionLabels, permissions
|
|
|
995
1071
|
? cause.message
|
|
996
1072
|
: m.user_api_key_delete_error()))))));
|
|
997
1073
|
const deleteKey = useAtomSet(deleteKeyAction);
|
|
998
|
-
return (_jsxs(_Fragment, { children: [_jsx(ScrollableDialogHeader, { children: _jsxs(DialogHeader, { className: "
|
|
1074
|
+
return (_jsxs(_Fragment, { children: [_jsx(ScrollableDialogHeader, { children: _jsxs(DialogHeader, { className: "gap-4", children: [creating || editingKey ? (_jsxs(Button, { className: "h-auto w-fit p-0", onClick: () => {
|
|
1075
|
+
setCreating(false);
|
|
1076
|
+
setCreatedKey(null);
|
|
1077
|
+
setEditingKey(null);
|
|
1078
|
+
}, type: "button", variant: "link", children: [_jsx(ArrowLeft, {}), m.user_api_key_back()] })) : null, _jsxs("div", { className: "flex min-w-0 flex-col gap-2", children: [_jsx(DialogTitle, { className: "text-2xl", children: editingKey
|
|
999
1079
|
? m.user_api_key_edit_title()
|
|
1000
1080
|
: createdKey
|
|
1001
1081
|
? m.user_api_key_created_title()
|
|
@@ -1007,14 +1087,10 @@ function ApiKeyManager({ baseUrl, active, locale, permissionLabels, permissions
|
|
|
1007
1087
|
? m.user_api_key_created_description()
|
|
1008
1088
|
: creating
|
|
1009
1089
|
? m.user_api_key_create_description()
|
|
1010
|
-
: m.user_api_keys_description() })] }), creating
|
|
1011
|
-
setCreating(false);
|
|
1012
|
-
setCreatedKey(null);
|
|
1013
|
-
setEditingKey(null);
|
|
1014
|
-
}, type: "button", variant: "secondary", children: [_jsx(ArrowLeft, {}), m.user_api_key_back()] })) : (_jsxs(Button, { className: "mt-2 w-fit sm:mt-0", onClick: () => {
|
|
1090
|
+
: m.user_api_keys_description() })] }), !creating && !editingKey ? (_jsxs(Button, { className: "w-fit", onClick: () => {
|
|
1015
1091
|
setCreatedKey(null);
|
|
1016
1092
|
setCreating(true);
|
|
1017
|
-
}, type: "button", children: [_jsx(Plus, {}), m.user_api_key_create_title()] }))] }) }), _jsxs(ScrollableDialogBody, { className: "flex min-w-0 flex-col gap-5", children: [creating && !createdKey ? (_jsx("section", { className: "w-full", children: _jsx(createForm.Initialize, { defaultValues: { name: "", referrers: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
|
|
1093
|
+
}, type: "button", children: [_jsx(Plus, {}), m.user_api_key_create_title()] })) : null] }) }), _jsxs(ScrollableDialogBody, { className: "flex min-w-0 flex-col gap-5", children: [creating && !createdKey ? (_jsx("section", { className: "w-full", children: _jsx(createForm.Initialize, { defaultValues: { name: "", referrers: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
|
|
1018
1094
|
event.preventDefault();
|
|
1019
1095
|
event.stopPropagation();
|
|
1020
1096
|
submitCreateForm();
|
|
@@ -1086,9 +1162,11 @@ const apiKeyColumns = ({ m, }) => [
|
|
|
1086
1162
|
{
|
|
1087
1163
|
field: "permissions",
|
|
1088
1164
|
headerName: m.user_api_key_permissions(),
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1165
|
+
type: "list",
|
|
1166
|
+
typeOptions: {
|
|
1167
|
+
getItems: (data) => formatPermissions(data.permissions).map((label) => ({ label })),
|
|
1168
|
+
emptyLabel: m.user_api_key_no_permissions(),
|
|
1169
|
+
visibleCount: 1,
|
|
1092
1170
|
},
|
|
1093
1171
|
},
|
|
1094
1172
|
];
|
package/dist/server/actor.js
CHANGED
|
@@ -110,19 +110,7 @@ const matchesConstraint = (actor, constraint) => {
|
|
|
110
110
|
const requiredActor = (access, constraint) => resolveCurrentActor(access).pipe(Effect.flatMap((actor) => matchesConstraint(actor, constraint)
|
|
111
111
|
? Effect.succeed(actor)
|
|
112
112
|
: Effect.fail(new HttpApiError.Forbidden({}))));
|
|
113
|
-
const withCurrentActor = (httpEffect, actor) =>
|
|
114
|
-
const userId = actor.actor.type === "user"
|
|
115
|
-
? actor.actor.userId
|
|
116
|
-
: actor.actor.owner.type === "user"
|
|
117
|
-
? actor.actor.owner.userId
|
|
118
|
-
: undefined;
|
|
119
|
-
const attributes = {};
|
|
120
|
-
if (actor.organizationId)
|
|
121
|
-
attributes["organization.id"] = actor.organizationId;
|
|
122
|
-
if (userId)
|
|
123
|
-
attributes["user.id"] = userId;
|
|
124
|
-
return Effect.annotateCurrentSpan(attributes).pipe(Effect.andThen(httpEffect.pipe(Effect.provideService(CurrentActor, actor), Effect.annotateSpans(attributes), Effect.annotateLogs(attributes))));
|
|
125
|
-
};
|
|
113
|
+
const withCurrentActor = (httpEffect, actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor));
|
|
126
114
|
export function ActorRequired(constraint) {
|
|
127
115
|
if (!constraint)
|
|
128
116
|
return AnyActorRequired;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
/** Replace auth-owned attribution rather than merging it with an outer actor. */
|
|
3
|
+
export declare const withAuthAnnotations: <A, E, R>(effect: Effect.Effect<A, E, R>, attributes: Readonly<Record<string, string>>) => Effect.Effect<A, E, Exclude<Exclude<R, never>, never>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Effect, Option, References } from "effect";
|
|
2
|
+
/** Replace auth-owned attribution rather than merging it with an outer actor. */
|
|
3
|
+
export const withAuthAnnotations = (effect, attributes) => {
|
|
4
|
+
const ownedAttribute = (key) => key === "user.id" ||
|
|
5
|
+
key === "organization.id" ||
|
|
6
|
+
key.startsWith("app.actor.");
|
|
7
|
+
const replaceAttribution = (annotations) => ({
|
|
8
|
+
...Object.fromEntries(Object.entries(annotations).filter(([key]) => !ownedAttribute(key))),
|
|
9
|
+
...attributes,
|
|
10
|
+
});
|
|
11
|
+
return Effect.gen(function* () {
|
|
12
|
+
const logs = yield* References.CurrentLogAnnotations;
|
|
13
|
+
const spans = yield* References.TracerSpanAnnotations;
|
|
14
|
+
const current = yield* Effect.currentSpan.pipe(Effect.option);
|
|
15
|
+
if (Option.isSome(current)) {
|
|
16
|
+
for (const key of current.value.attributes.keys()) {
|
|
17
|
+
if (ownedAttribute(key) && attributes[key] === undefined) {
|
|
18
|
+
// Tracer has no removeAttribute API; clear stale current-span values.
|
|
19
|
+
current.value.attribute(key, "");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
yield* Effect.annotateCurrentSpan(attributes);
|
|
24
|
+
return yield* effect.pipe(Effect.provideService(References.TracerSpanAnnotations, replaceAttribution(spans)), Effect.provideService(References.CurrentLogAnnotations, replaceAttribution(logs)));
|
|
25
|
+
});
|
|
26
|
+
};
|
package/dist/server/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { AuthProxyError, authProxyKeyHeader, proxyOriginHeaders, readProxyOrigin
|
|
|
8
8
|
export { ActorRequired } from "./actor.js";
|
|
9
9
|
export type { ActorConstraint } from "./actor.js";
|
|
10
10
|
export { ApiKeySecurity, AuthMiddleware, makeAuthenticationLive, } from "./middleware.js";
|
|
11
|
-
export type { AuthenticationLiveOptions } from "./middleware.js";
|
|
11
|
+
export type { AuthenticationLiveOptions, AuthRouterOptions, } from "./middleware.js";
|
|
12
12
|
export { ServerActiveOrganization, ServerCreateDomainPayload, ServerDomain, ServerDomainHostParams, ServerDomainIdParams, ServerDomainRecordsResponse, ServerMembersResponse, ServerOrganizationChildrenResponse, ServerOrganizationsResponse, ServerUpdateDomainPayload, ServerUsersResponse, } from "./schema.js";
|
|
13
13
|
export type { Member, Organization, OrganizationMetadata, User, } from "../schema.js";
|
|
14
14
|
export { ApiKeyPermissionGrant, CurrentActor, Forbidden, all, actorUserId, any, defineProjectAccess, permission, policy, withPolicy, } from "../access.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
|
-
import { HttpServerRequest } from "effect/http";
|
|
2
|
+
import { HttpRouter, HttpServerRequest } from "effect/http";
|
|
3
3
|
import { HttpApiError, HttpApiMiddleware, HttpApiSecurity } from "effect/http-api";
|
|
4
4
|
import { AuthService, type AuthServiceLayerOptions } from "../service.js";
|
|
5
5
|
export declare const ApiKeySecurity: HttpApiSecurity.ApiKey;
|
|
@@ -17,6 +17,8 @@ declare const AuthMiddleware_base: HttpApiMiddleware.ServiceClass<AuthMiddleware
|
|
|
17
17
|
}, AuthService, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden, typeof HttpApiError.ServiceUnavailable], never>>;
|
|
18
18
|
export declare class AuthMiddleware extends AuthMiddleware_base {
|
|
19
19
|
static readonly layer: (options?: AuthenticationLiveOptions | Layer.Layer<AuthService, unknown>) => Layer.Layer<AuthMiddleware, never, never>;
|
|
20
|
+
/** The same optional authentication and attribution for plain HttpRouter routes. */
|
|
21
|
+
static readonly routerLayer: (options?: AuthRouterOptions) => Layer.Layer<never, import("effect/Config").ConfigError, HttpRouter.Request<"Error", HttpApiError.Forbidden> | HttpRouter.Request<"Error", HttpApiError.ServiceUnavailable>>;
|
|
20
22
|
}
|
|
21
23
|
export type AuthenticationLiveOptions = AuthServiceLayerOptions & {
|
|
22
24
|
readonly allowedOrganizationImpersonationRoutes?: readonly {
|
|
@@ -25,5 +27,9 @@ export type AuthenticationLiveOptions = AuthServiceLayerOptions & {
|
|
|
25
27
|
}[];
|
|
26
28
|
readonly authLayer?: Layer.Layer<AuthService, unknown, HttpServerRequest.HttpServerRequest>;
|
|
27
29
|
};
|
|
30
|
+
export type AuthRouterOptions = AuthenticationLiveOptions & {
|
|
31
|
+
/** Resolve auth only for these exact URL pathnames. Defaults to every route in scope. */
|
|
32
|
+
readonly paths?: readonly string[];
|
|
33
|
+
};
|
|
28
34
|
export declare const makeAuthenticationLive: (options?: AuthenticationLiveOptions | Layer.Layer<AuthService, unknown>) => Layer.Layer<AuthMiddleware, never, never>;
|
|
29
35
|
export {};
|