@nebulr-group/bridge-svelte 0.9.3 → 1.0.0-alpha.0
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 +27 -39
- package/dist/bootstrap.d.ts +24 -0
- package/dist/bootstrap.js +104 -0
- package/dist/components/BridgeBootstrap.svelte +61 -0
- package/dist/{client → components}/BridgeBootstrap.svelte.d.ts +1 -4
- package/dist/components/auth/BridgeAuthRoutes.svelte +112 -0
- package/dist/components/auth/BridgeAuthRoutes.svelte.d.ts +13 -0
- package/dist/components/auth/ForgotPassword.svelte +77 -0
- package/dist/components/auth/ForgotPassword.svelte.d.ts +14 -0
- package/dist/components/auth/HandoffSignIn.svelte +130 -0
- package/dist/components/auth/HandoffSignIn.svelte.d.ts +14 -0
- package/dist/components/auth/InviteLanding.svelte +142 -0
- package/dist/components/auth/InviteLanding.svelte.d.ts +14 -0
- package/dist/components/auth/ProfileName.svelte +17 -0
- package/dist/{client/components → components/auth}/ProfileName.svelte.d.ts +1 -3
- package/dist/components/auth/SetPassword.svelte +125 -0
- package/dist/components/auth/SetPassword.svelte.d.ts +15 -0
- package/dist/components/auth/SignInForm.svelte +213 -0
- package/dist/components/auth/SignInForm.svelte.d.ts +27 -0
- package/dist/components/auth/SignOutButton.svelte +39 -0
- package/dist/components/auth/SignOutButton.svelte.d.ts +12 -0
- package/dist/components/auth/SignUpForm.svelte +176 -0
- package/dist/components/auth/SignUpForm.svelte.d.ts +26 -0
- package/dist/components/auth/VerifyEmail.svelte +95 -0
- package/dist/components/auth/VerifyEmail.svelte.d.ts +15 -0
- package/dist/components/auth/WorkspaceChooser.svelte +118 -0
- package/dist/components/auth/WorkspaceChooser.svelte.d.ts +29 -0
- package/dist/components/auth/email-link.d.ts +2 -0
- package/dist/components/auth/email-link.js +24 -0
- package/dist/components/billing/BillingNotice.svelte +125 -0
- package/dist/components/billing/BillingNotice.svelte.d.ts +14 -0
- package/dist/components/billing/BillingPortalButton.svelte +57 -0
- package/dist/{client/components/subscription → components/billing}/BillingPortalButton.svelte.d.ts +3 -0
- package/dist/components/billing/BridgeBillingRoutes.svelte +150 -0
- package/dist/components/billing/BridgeBillingRoutes.svelte.d.ts +15 -0
- package/dist/components/billing/CheckoutNotice.svelte +131 -0
- package/dist/components/billing/CheckoutNotice.svelte.d.ts +23 -0
- package/dist/components/billing/PlanPicker.svelte +421 -0
- package/dist/components/billing/PlanPicker.svelte.d.ts +40 -0
- package/dist/components/billing/QuotaBanner.svelte +93 -0
- package/dist/components/billing/QuotaBanner.svelte.d.ts +15 -0
- package/dist/components/billing/SubscriptionStatus.svelte +41 -0
- package/dist/components/billing/SubscriptionStatus.svelte.d.ts +5 -0
- package/dist/components/billing/UpgradeDialog.svelte +69 -0
- package/dist/components/billing/UpgradeDialog.svelte.d.ts +7 -0
- package/dist/components/billing/plan-format.d.ts +36 -0
- package/dist/components/billing/plan-format.js +125 -0
- package/dist/components/billing/quota.d.ts +27 -0
- package/dist/components/billing/quota.js +18 -0
- package/dist/components/flags/FeatureFlag.svelte +82 -0
- package/dist/{flags → components/flags}/FeatureFlag.svelte.d.ts +13 -16
- package/dist/components/live/LiveStatusBadge.svelte +23 -0
- package/dist/components/live/LiveStatusBadge.svelte.d.ts +4 -0
- package/dist/components/shared/AuthFormWrapper.svelte +36 -0
- package/dist/components/shared/AuthFormWrapper.svelte.d.ts +15 -0
- package/dist/components/shared/PasswordInput.svelte +30 -0
- package/dist/components/shared/PasswordInput.svelte.d.ts +9 -0
- package/dist/{client/components/team/TeamConfirmDialog.svelte → components/team/ConfirmDialog.svelte} +25 -7
- package/dist/{client/components/team/TeamConfirmDialog.svelte.d.ts → components/team/ConfirmDialog.svelte.d.ts} +6 -4
- package/dist/components/team/EditMemberDialog.svelte +150 -0
- package/dist/components/team/EditMemberDialog.svelte.d.ts +18 -0
- package/dist/components/team/InviteDialog.svelte +143 -0
- package/dist/components/team/InviteDialog.svelte.d.ts +17 -0
- package/dist/components/team/InviteList.svelte +132 -0
- package/dist/components/team/InviteList.svelte.d.ts +7 -0
- package/dist/components/team/MemberList.svelte +297 -0
- package/dist/components/team/MemberList.svelte.d.ts +7 -0
- package/dist/components/team/ProfileForm.svelte +127 -0
- package/dist/components/team/ProfileForm.svelte.d.ts +7 -0
- package/dist/components/team/TeamPanel.svelte +87 -0
- package/dist/components/team/TeamPanel.svelte.d.ts +22 -0
- package/dist/components/team/WorkspaceForm.svelte +132 -0
- package/dist/components/team/WorkspaceForm.svelte.d.ts +7 -0
- package/dist/core/client.d.ts +31 -0
- package/dist/core/client.js +82 -0
- package/dist/core/config.d.ts +133 -0
- package/dist/core/config.js +62 -0
- package/dist/core/fetch.d.ts +1 -0
- package/dist/core/fetch.js +51 -0
- package/dist/core/flags.d.ts +41 -0
- package/dist/core/flags.js +63 -0
- package/dist/core/guard.d.ts +51 -0
- package/dist/core/guard.js +87 -0
- package/dist/core/handoff.d.ts +52 -0
- package/dist/core/handoff.js +57 -0
- package/dist/core/i18n.d.ts +22 -0
- package/dist/core/i18n.js +78 -0
- package/dist/core/messages.d.ts +11 -0
- package/dist/core/messages.js +219 -0
- package/dist/core/routes.d.ts +25 -0
- package/dist/core/routes.js +56 -0
- package/dist/core/stores.d.ts +54 -0
- package/dist/core/stores.js +113 -0
- package/dist/core/upgrade.d.ts +41 -0
- package/dist/core/upgrade.js +48 -0
- package/dist/index.d.ts +60 -91
- package/dist/index.js +56 -140
- package/dist/server/browser.js +7 -0
- package/dist/server/index.d.ts +80 -0
- package/dist/server/index.js +140 -0
- package/dist/styles.css +333 -9
- package/package.json +92 -102
- package/dist/auth/guard-cache.d.ts +0 -30
- package/dist/auth/guard-cache.js +0 -102
- package/dist/auth/route-guard.d.ts +0 -29
- package/dist/auth/route-guard.js +0 -191
- package/dist/client/BridgeBootstrap.d.ts +0 -78
- package/dist/client/BridgeBootstrap.js +0 -539
- package/dist/client/BridgeBootstrap.svelte +0 -330
- package/dist/client/auth-routes.d.ts +0 -33
- package/dist/client/auth-routes.js +0 -70
- package/dist/client/billing-role.d.ts +0 -10
- package/dist/client/billing-role.js +0 -39
- package/dist/client/billing-routes.d.ts +0 -81
- package/dist/client/billing-routes.js +0 -98
- package/dist/client/checkout-result.d.ts +0 -16
- package/dist/client/checkout-result.js +0 -31
- package/dist/client/components/ProfileName.svelte +0 -18
- package/dist/client/components/developer/ApiTokenManagement.svelte +0 -365
- package/dist/client/components/developer/ApiTokenManagement.svelte.d.ts +0 -6
- package/dist/client/components/developer/RealtimeDevBadge.svelte +0 -222
- package/dist/client/components/developer/RealtimeDevBadge.svelte.d.ts +0 -6
- package/dist/client/components/sdk-auth/BridgeAuthRoutes.svelte +0 -205
- package/dist/client/components/sdk-auth/BridgeAuthRoutes.svelte.d.ts +0 -25
- package/dist/client/components/sdk-auth/ForgotPassword.svelte +0 -223
- package/dist/client/components/sdk-auth/ForgotPassword.svelte.d.ts +0 -32
- package/dist/client/components/sdk-auth/LoginForm.svelte +0 -520
- package/dist/client/components/sdk-auth/LoginForm.svelte.d.ts +0 -48
- package/dist/client/components/sdk-auth/MagicLink.svelte +0 -162
- package/dist/client/components/sdk-auth/MagicLink.svelte.d.ts +0 -24
- package/dist/client/components/sdk-auth/MfaChallenge.svelte +0 -158
- package/dist/client/components/sdk-auth/MfaChallenge.svelte.d.ts +0 -12
- package/dist/client/components/sdk-auth/MfaSetup.svelte +0 -219
- package/dist/client/components/sdk-auth/MfaSetup.svelte.d.ts +0 -22
- package/dist/client/components/sdk-auth/PasskeyLogin.svelte +0 -107
- package/dist/client/components/sdk-auth/PasskeyLogin.svelte.d.ts +0 -13
- package/dist/client/components/sdk-auth/PasskeyRequestSetupLink.svelte +0 -107
- package/dist/client/components/sdk-auth/PasskeyRequestSetupLink.svelte.d.ts +0 -17
- package/dist/client/components/sdk-auth/PasskeySetup.svelte +0 -193
- package/dist/client/components/sdk-auth/PasskeySetup.svelte.d.ts +0 -32
- package/dist/client/components/sdk-auth/SignupForm.svelte +0 -185
- package/dist/client/components/sdk-auth/SignupForm.svelte.d.ts +0 -44
- package/dist/client/components/sdk-auth/SsoButton.svelte +0 -88
- package/dist/client/components/sdk-auth/SsoButton.svelte.d.ts +0 -23
- package/dist/client/components/sdk-auth/SsoProviderIcon.svelte +0 -56
- package/dist/client/components/sdk-auth/SsoProviderIcon.svelte.d.ts +0 -7
- package/dist/client/components/sdk-auth/TenantSelector.svelte +0 -90
- package/dist/client/components/sdk-auth/TenantSelector.svelte.d.ts +0 -13
- package/dist/client/components/sdk-auth/WorkspaceSelector.svelte +0 -116
- package/dist/client/components/sdk-auth/WorkspaceSelector.svelte.d.ts +0 -18
- package/dist/client/components/sdk-auth/shared/AuthFormWrapper.svelte +0 -60
- package/dist/client/components/sdk-auth/shared/AuthFormWrapper.svelte.d.ts +0 -33
- package/dist/client/components/sdk-auth/shared/auth-error.d.ts +0 -28
- package/dist/client/components/sdk-auth/shared/auth-error.js +0 -67
- package/dist/client/components/subscription/BillingPortalButton.svelte +0 -68
- package/dist/client/components/subscription/BridgeBillingNotice.svelte +0 -388
- package/dist/client/components/subscription/BridgeBillingNotice.svelte.d.ts +0 -22
- package/dist/client/components/subscription/BridgeBillingRoutes.svelte +0 -240
- package/dist/client/components/subscription/BridgeBillingRoutes.svelte.d.ts +0 -17
- package/dist/client/components/subscription/BridgeCheckoutNotice.svelte +0 -101
- package/dist/client/components/subscription/BridgeCheckoutNotice.svelte.d.ts +0 -15
- package/dist/client/components/subscription/BridgePaywall.svelte +0 -96
- package/dist/client/components/subscription/BridgePaywall.svelte.d.ts +0 -19
- package/dist/client/components/subscription/BridgePaywallPage.svelte +0 -96
- package/dist/client/components/subscription/BridgePaywallPage.svelte.d.ts +0 -20
- package/dist/client/components/subscription/BridgeQuotaBanner.svelte +0 -241
- package/dist/client/components/subscription/BridgeQuotaBanner.svelte.d.ts +0 -27
- package/dist/client/components/subscription/BridgeSubscriptionStatus.svelte +0 -136
- package/dist/client/components/subscription/BridgeSubscriptionStatus.svelte.d.ts +0 -9
- package/dist/client/components/subscription/BridgeUpgradeDialog.svelte +0 -116
- package/dist/client/components/subscription/BridgeUpgradeDialog.svelte.d.ts +0 -4
- package/dist/client/components/subscription/Entitled.svelte +0 -52
- package/dist/client/components/subscription/Entitled.svelte.d.ts +0 -14
- package/dist/client/components/subscription/PlanSelector.svelte +0 -478
- package/dist/client/components/subscription/PlanSelector.svelte.d.ts +0 -45
- package/dist/client/components/subscription/QuotaGate.svelte +0 -76
- package/dist/client/components/subscription/QuotaGate.svelte.d.ts +0 -18
- package/dist/client/components/subscription/plan-format.d.ts +0 -17
- package/dist/client/components/subscription/plan-format.js +0 -81
- package/dist/client/components/subscription/plan-pick.d.ts +0 -39
- package/dist/client/components/subscription/plan-pick.js +0 -49
- package/dist/client/components/subscription/subscription-badge.d.ts +0 -14
- package/dist/client/components/subscription/subscription-badge.js +0 -17
- package/dist/client/components/team/TeamAddUserDialog.svelte +0 -139
- package/dist/client/components/team/TeamAddUserDialog.svelte.d.ts +0 -23
- package/dist/client/components/team/TeamEditUserDialog.svelte +0 -131
- package/dist/client/components/team/TeamEditUserDialog.svelte.d.ts +0 -19
- package/dist/client/components/team/TeamManagementPanel.svelte +0 -79
- package/dist/client/components/team/TeamManagementPanel.svelte.d.ts +0 -26
- package/dist/client/components/team/TeamProfileForm.svelte +0 -129
- package/dist/client/components/team/TeamProfileForm.svelte.d.ts +0 -7
- package/dist/client/components/team/TeamUserActionsMenu.svelte +0 -63
- package/dist/client/components/team/TeamUserActionsMenu.svelte.d.ts +0 -9
- package/dist/client/components/team/TeamUserList.svelte +0 -267
- package/dist/client/components/team/TeamUserList.svelte.d.ts +0 -13
- package/dist/client/components/team/TeamWorkspaceForm.svelte +0 -134
- package/dist/client/components/team/TeamWorkspaceForm.svelte.d.ts +0 -7
- package/dist/client/components/team/seats.d.ts +0 -8
- package/dist/client/components/team/seats.js +0 -32
- package/dist/client/quota-banner-copy.d.ts +0 -12
- package/dist/client/quota-banner-copy.js +0 -86
- package/dist/client/resolve-config.d.ts +0 -43
- package/dist/client/resolve-config.js +0 -112
- package/dist/client/stores/config.store.d.ts +0 -16
- package/dist/client/stores/config.store.js +0 -76
- package/dist/client/stores/i18n.d.ts +0 -18
- package/dist/client/stores/i18n.js +0 -30
- package/dist/client/tracking/pii-hashing.d.ts +0 -11
- package/dist/client/tracking/pii-hashing.js +0 -29
- package/dist/client/tracking/reddit-tracking.d.ts +0 -74
- package/dist/client/tracking/reddit-tracking.js +0 -59
- package/dist/client/upgrade-dialog.d.ts +0 -23
- package/dist/client/upgrade-dialog.js +0 -44
- package/dist/client/utils/cn.d.ts +0 -1
- package/dist/client/utils/cn.js +0 -3
- package/dist/core/billing-store.d.ts +0 -70
- package/dist/core/billing-store.js +0 -365
- package/dist/core/bridge-fetch.d.ts +0 -45
- package/dist/core/bridge-fetch.js +0 -176
- package/dist/core/bridge-instance.d.ts +0 -73
- package/dist/core/bridge-instance.js +0 -308
- package/dist/core/bridge-runtime.d.ts +0 -140
- package/dist/core/bridge-runtime.js +0 -875
- package/dist/core/bridge.d.ts +0 -140
- package/dist/core/bridge.js +0 -213
- package/dist/core/direct-plan-check-note.d.ts +0 -4
- package/dist/core/direct-plan-check-note.js +0 -35
- package/dist/core/double-count-warning.d.ts +0 -8
- package/dist/core/double-count-warning.js +0 -74
- package/dist/core/entitlements.d.ts +0 -40
- package/dist/core/entitlements.js +0 -74
- package/dist/core/events.d.ts +0 -74
- package/dist/core/events.js +0 -64
- package/dist/core/feature-upgrade.d.ts +0 -49
- package/dist/core/feature-upgrade.js +0 -63
- package/dist/core/flag-definitions.d.ts +0 -15
- package/dist/core/flag-definitions.js +0 -66
- package/dist/core/lazy-slice.d.ts +0 -74
- package/dist/core/lazy-slice.js +0 -124
- package/dist/core/quota-refusal.d.ts +0 -92
- package/dist/core/quota-refusal.js +0 -176
- package/dist/core/realtime-dev-badge.d.ts +0 -31
- package/dist/core/realtime-dev-badge.js +0 -78
- package/dist/core/realtime-status.d.ts +0 -27
- package/dist/core/realtime-status.js +0 -51
- package/dist/core/snapshot-stores.d.ts +0 -116
- package/dist/core/snapshot-stores.js +0 -131
- package/dist/core/use-bridge.d.ts +0 -13
- package/dist/core/use-bridge.js +0 -47
- package/dist/core/use-quota.d.ts +0 -36
- package/dist/core/use-quota.js +0 -191
- package/dist/flags/FeatureFlag.svelte +0 -110
- package/dist/flags/bootstrap.d.ts +0 -72
- package/dist/flags/bootstrap.js +0 -357
- package/dist/flags/flag.svelte.d.ts +0 -31
- package/dist/flags/flag.svelte.js +0 -99
- package/dist/flags/index.d.ts +0 -11
- package/dist/flags/index.js +0 -24
- package/dist/flags/realtime-status.d.ts +0 -1
- package/dist/flags/realtime-status.js +0 -4
- package/dist/flags/registry.d.ts +0 -27
- package/dist/flags/registry.js +0 -63
- package/dist/shared/allowed-origins.d.ts +0 -14
- package/dist/shared/allowed-origins.js +0 -19
- package/dist/shared/logger.d.ts +0 -20
- package/dist/shared/logger.js +0 -36
- package/dist/shared/profile.d.ts +0 -18
- package/dist/shared/profile.js +0 -25
- package/dist/shared/types/config.d.ts +0 -106
- /package/dist/{client/components/sdk-auth → components}/shared/Alert.svelte +0 -0
- /package/dist/{client/components/sdk-auth → components}/shared/Alert.svelte.d.ts +0 -0
- /package/dist/{client/components/sdk-auth → components}/shared/Spinner.svelte +0 -0
- /package/dist/{client/components/sdk-auth → components}/shared/Spinner.svelte.d.ts +0 -0
- /package/dist/{shared/types/config.js → server/browser.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -17,79 +17,67 @@
|
|
|
17
17
|
|
|
18
18
|
# The Bridge for SvelteKit
|
|
19
19
|
|
|
20
|
-
`@nebulr-group/bridge-svelte` adds sign-in, workspaces
|
|
20
|
+
`@nebulr-group/bridge-svelte` adds sign-in in your own pages, workspaces, flag-based route guards, plans and checkout, the team panel and live updates to a SvelteKit 2 + Svelte 5 app, with one `.env` line and three files.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
> **This is the 1.0 alpha**, built on `@nebulr-group/bridge-auth-core` 1.0 and the new Bridge API. It installs from the `alpha` tag; `latest` stays on 0.x until 1.0.0. It runs in the browser (`ssr = false`) and signs people in with email and password.
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
**[The Bridge](https://thebridge.dev/?utm_source=npm&utm_medium=readme&utm_campaign=bridge-svelte)** is a hosted backend for SaaS apps: sign-in, multi-tenant workspaces, Stripe subscriptions with plan limits, and feature flags, managed from one dashboard.
|
|
25
25
|
|
|
26
26
|
## Install
|
|
27
27
|
|
|
28
|
-
```
|
|
29
|
-
|
|
28
|
+
```sh
|
|
29
|
+
bun add @nebulr-group/bridge-svelte@alpha
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## The whole integration
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# .env
|
|
38
|
-
VITE_BRIDGE_APP_ID=your-app-id
|
|
34
|
+
```sh
|
|
35
|
+
# .env: the issuer from your app's settings in Bridge
|
|
36
|
+
PUBLIC_BRIDGE_ISSUER=https://…/identity-access/apps/<your app id>
|
|
39
37
|
```
|
|
40
38
|
|
|
41
39
|
```ts
|
|
42
40
|
// src/routes/+layout.ts
|
|
43
41
|
import { bridgeBootstrap } from '@nebulr-group/bridge-svelte';
|
|
44
42
|
export const ssr = false;
|
|
45
|
-
export const load = bridgeBootstrap({ rules: [{ match:
|
|
43
|
+
export const load = bridgeBootstrap({ rules: [{ match: '/', public: true }] });
|
|
46
44
|
```
|
|
47
45
|
|
|
48
46
|
```svelte
|
|
49
47
|
<!-- src/routes/+layout.svelte -->
|
|
50
48
|
<script lang="ts">
|
|
51
|
-
import { BridgeBootstrap } from '@nebulr-group/bridge-svelte';
|
|
52
49
|
import '@nebulr-group/bridge-svelte/styles';
|
|
50
|
+
import { BridgeBootstrap } from '@nebulr-group/bridge-svelte';
|
|
53
51
|
let { children } = $props();
|
|
54
52
|
</script>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
</BridgeBootstrap>
|
|
53
|
+
|
|
54
|
+
<BridgeBootstrap>{@render children()}</BridgeBootstrap>
|
|
58
55
|
```
|
|
59
56
|
|
|
60
57
|
```svelte
|
|
61
|
-
<!-- src/routes/auth/[...bridge]/+page.svelte
|
|
58
|
+
<!-- src/routes/auth/[...bridge]/+page.svelte -->
|
|
62
59
|
<script lang="ts">
|
|
63
60
|
import { BridgeAuthRoutes } from '@nebulr-group/bridge-svelte';
|
|
64
61
|
</script>
|
|
62
|
+
|
|
65
63
|
<BridgeAuthRoutes />
|
|
66
64
|
```
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
[How Bridge works](https://github.com/thebridgedev/bridge-svelte/blob/main/learning/mechanisms.md) explains plan limits, the three UI levels and the four customisation levels; the [learning docs](https://github.com/thebridgedev/bridge-svelte/tree/main/learning) cover everything else. Coding agents: `npx @nebulr-group/bridge-cli guide svelte`.
|
|
71
|
-
|
|
72
|
-
## Learn more
|
|
73
|
-
|
|
74
|
-
- [Quickstart](https://thebridge.dev/docs/quickstart/svelte/?utm_source=npm&utm_medium=readme&utm_campaign=bridge-svelte)
|
|
75
|
-
- [Authentication](https://thebridge.dev/docs/auth/svelte/?utm_source=npm&utm_medium=readme&utm_campaign=bridge-svelte)
|
|
76
|
-
- [Sign-in inside your app](https://thebridge.dev/docs/sdk-auth/svelte/?utm_source=npm&utm_medium=readme&utm_campaign=bridge-svelte)
|
|
77
|
-
- [Feature flags](https://thebridge.dev/docs/feature-flags/svelte/?utm_source=npm&utm_medium=readme&utm_campaign=bridge-svelte)
|
|
78
|
-
- [Branding](https://thebridge.dev/docs/branding/svelte/?utm_source=npm&utm_medium=readme&utm_campaign=bridge-svelte)
|
|
79
|
-
- [Live updates](https://thebridge.dev/docs/live-updates/svelte/?utm_source=npm&utm_medium=readme&utm_campaign=bridge-svelte)
|
|
80
|
-
- [Subscriptions and plan limits](https://thebridge.dev/docs/billing/how-it-works/?utm_source=npm&utm_medium=readme&utm_campaign=bridge-svelte)
|
|
66
|
+
In your app's settings in Bridge, add your app's address as a browser address and `https://<your app>/auth` as its email-links address. See the [Quickstart](https://github.com/thebridgedev/bridge-svelte/blob/v1/learning/quickstart/quickstart.md).
|
|
81
67
|
|
|
82
|
-
##
|
|
68
|
+
## What it gives you
|
|
83
69
|
|
|
84
|
-
|
|
|
70
|
+
| Area | Pieces |
|
|
85
71
|
|---|---|
|
|
86
|
-
|
|
|
87
|
-
|
|
|
88
|
-
|
|
|
89
|
-
|
|
|
90
|
-
|
|
|
91
|
-
|
|
|
92
|
-
|
|
|
72
|
+
| Sign-in | `BridgeAuthRoutes` (sign-in, sign-up, verify-email, forgot-password, set-password, invite, workspaces, handoff), `SignInForm`, `SignUpForm`, `VerifyEmail`, `ForgotPassword`, `SetPassword`, `InviteLanding`, `WorkspaceChooser`, `SignOutButton`, `ProfileName` |
|
|
73
|
+
| Gates | route `rules`, `FeatureFlag`, `useFlag`, `flag`, `requireFlag`, the paywall: all on flag results, never a role or the plan |
|
|
74
|
+
| Billing | `BridgeBillingRoutes`, `PlanPicker`, `BillingPortalButton`, `SubscriptionStatus`, `BillingNotice`, `QuotaBanner`, `CheckoutNotice`, `UpgradeDialog`, `bridgeFetch` |
|
|
75
|
+
| Team | `TeamPanel`, `MemberList`, `InviteDialog`, `InviteList`, `EditMemberDialog`, `WorkspaceForm`, `ProfileForm` |
|
|
76
|
+
| State | `session`, `user`, `workspace`, `workspaces`, `me`, `flags`, `billing`, `plans`, `usage`, `liveStatus`, `getBridge()` |
|
|
77
|
+
| Server | `@nebulr-group/bridge-svelte/server`: `bridgeHandle`, `requireActor`, `meter`, `flagsFor` |
|
|
78
|
+
| Hand-off | `HandoffSignIn`, `readHandoff`, `handoffSignIn`: a sign-in page for a command-line tool |
|
|
79
|
+
|
|
80
|
+
All the guides: [the learning docs](https://github.com/thebridgedev/bridge-svelte/tree/v1/learning).
|
|
93
81
|
|
|
94
82
|
## License
|
|
95
83
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Bridge } from '@nebulr-group/bridge-auth-core';
|
|
2
|
+
import { type BridgeConfig } from './core/config.js';
|
|
3
|
+
/** What the root layout's load gives every page. */
|
|
4
|
+
export interface BridgeLayoutData {
|
|
5
|
+
/** The page's Bridge client. */
|
|
6
|
+
readonly bridge: Bridge;
|
|
7
|
+
}
|
|
8
|
+
/** The parts of a SvelteKit load event bridgeBootstrap reads. */
|
|
9
|
+
export interface BridgeLoadEvent {
|
|
10
|
+
readonly url: URL;
|
|
11
|
+
readonly params: Partial<Record<string, string>>;
|
|
12
|
+
readonly route: {
|
|
13
|
+
readonly id: string | null;
|
|
14
|
+
};
|
|
15
|
+
depends(...deps: `${string}:${string}`[]): void;
|
|
16
|
+
}
|
|
17
|
+
/** Load dependencies `<BridgeBootstrap>` invalidates, so the guard runs again. */
|
|
18
|
+
export declare const SESSION_DEPENDENCY = "bridge:session";
|
|
19
|
+
export declare const FLAGS_DEPENDENCY = "bridge:flags";
|
|
20
|
+
/**
|
|
21
|
+
* Makes the root layout's load function. Set `export const ssr = false`
|
|
22
|
+
* next to it: the client runs in the browser.
|
|
23
|
+
*/
|
|
24
|
+
export declare function bridgeBootstrap(options?: BridgeConfig): (event: BridgeLoadEvent) => Promise<BridgeLayoutData>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `bridgeBootstrap`: the root layout's load function. It makes the page's
|
|
3
|
+
* Bridge client, sends email links to their pages, and guards every
|
|
4
|
+
* navigation.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* // src/routes/+layout.ts
|
|
8
|
+
* import { bridgeBootstrap } from '@nebulr-group/bridge-svelte';
|
|
9
|
+
* export const ssr = false;
|
|
10
|
+
* export const load = bridgeBootstrap({ rules: [{ match: '/', public: true }] });
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
import { error, redirect } from '@sveltejs/kit';
|
|
14
|
+
import { env } from '$env/dynamic/public';
|
|
15
|
+
import { readEmailLink, readReturnTo } from '@nebulr-group/bridge-auth-core';
|
|
16
|
+
import { get } from 'svelte/store';
|
|
17
|
+
import { startClient } from './core/client.js';
|
|
18
|
+
import { resolveConfig } from './core/config.js';
|
|
19
|
+
import { decide, normalizePath } from './core/guard.js';
|
|
20
|
+
import { authPageAt, isCatchAll, isUnder, pageForLink, parseBillingPage, ROUTE_PARAM } from './core/routes.js';
|
|
21
|
+
/** Load dependencies `<BridgeBootstrap>` invalidates, so the guard runs again. */
|
|
22
|
+
export const SESSION_DEPENDENCY = 'bridge:session';
|
|
23
|
+
export const FLAGS_DEPENDENCY = 'bridge:flags';
|
|
24
|
+
/** How long a navigation waits for Bridge before deciding as if nobody were signed in. */
|
|
25
|
+
const READY_WAIT_MS = 8000;
|
|
26
|
+
function within(promise, ms) {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
const timer = setTimeout(() => resolve(undefined), ms);
|
|
29
|
+
promise.then((value) => {
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
resolve(value);
|
|
32
|
+
}, () => {
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
resolve(undefined);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** Sends the browser on, keeping the email link's fragment. */
|
|
39
|
+
function followLink(config, url) {
|
|
40
|
+
if (typeof window === 'undefined')
|
|
41
|
+
return;
|
|
42
|
+
const hash = window.location.hash;
|
|
43
|
+
const link = readEmailLink(hash);
|
|
44
|
+
if (link === null)
|
|
45
|
+
return;
|
|
46
|
+
const page = `${config.authBase}/${pageForLink(link)}`;
|
|
47
|
+
if (normalizePath(url.pathname) === page)
|
|
48
|
+
return;
|
|
49
|
+
redirect(307, `${page}${hash}`);
|
|
50
|
+
}
|
|
51
|
+
async function guard(client, config, url) {
|
|
52
|
+
await within(client.ready, READY_WAIT_MS);
|
|
53
|
+
const flagsNeeded = authPageAt(normalizePath(url.pathname), config.authBase) === null;
|
|
54
|
+
if (flagsNeeded && get(client.flags.status) !== 'ready')
|
|
55
|
+
await within(client.flags.load(), READY_WAIT_MS);
|
|
56
|
+
return decide(config, {
|
|
57
|
+
path: url.pathname,
|
|
58
|
+
target: `${normalizePath(url.pathname)}${url.search}`,
|
|
59
|
+
session: client.session.get(),
|
|
60
|
+
flags: client.flags,
|
|
61
|
+
returnTo: readReturnTo(url, config.returnToParam),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Makes the root layout's load function. Set `export const ssr = false`
|
|
66
|
+
* next to it: the client runs in the browser.
|
|
67
|
+
*/
|
|
68
|
+
export function bridgeBootstrap(options = {}) {
|
|
69
|
+
return async function load(event) {
|
|
70
|
+
if (typeof window === 'undefined') {
|
|
71
|
+
throw new Error('[bridge] bridgeBootstrap runs in the browser. Add `export const ssr = false` to your root +layout.ts.');
|
|
72
|
+
}
|
|
73
|
+
event.depends(SESSION_DEPENDENCY, FLAGS_DEPENDENCY);
|
|
74
|
+
const config = resolveConfig(options, env.PUBLIC_BRIDGE_ISSUER);
|
|
75
|
+
const client = startClient(config);
|
|
76
|
+
const { url } = event;
|
|
77
|
+
// Matched as the router resolves the route: decoded, without a trailing slash.
|
|
78
|
+
const path = normalizePath(url.pathname);
|
|
79
|
+
// An email link lands on the email-links address with its token in the fragment: on to its page.
|
|
80
|
+
followLink(config, url);
|
|
81
|
+
if (config.authBase !== '' && path === config.authBase)
|
|
82
|
+
redirect(307, `${config.authBase}/sign-in${url.search}`);
|
|
83
|
+
// A catch-all route under the auth or billing base answers an unknown page with the app's own 404.
|
|
84
|
+
if (isCatchAll(event.route.id)) {
|
|
85
|
+
const rest = event.params[ROUTE_PARAM];
|
|
86
|
+
if (isUnder(path, config.authBase) && authPageAt(path, config.authBase) === null)
|
|
87
|
+
error(404, 'Not found');
|
|
88
|
+
if (isUnder(path, config.billingBase) && parseBillingPage(rest) === null)
|
|
89
|
+
error(404, 'Not found');
|
|
90
|
+
}
|
|
91
|
+
const decision = await guard(client, config, url);
|
|
92
|
+
switch (decision.type) {
|
|
93
|
+
case 'sign-in':
|
|
94
|
+
case 'redirect':
|
|
95
|
+
redirect(307, decision.to);
|
|
96
|
+
// eslint-disable-next-line no-fallthrough
|
|
97
|
+
case 'forbidden':
|
|
98
|
+
error(403, 'Forbidden');
|
|
99
|
+
// eslint-disable-next-line no-fallthrough
|
|
100
|
+
case 'allow':
|
|
101
|
+
return { bridge: client };
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Wrap the root layout's content in it:
|
|
3
|
+
|
|
4
|
+
<BridgeBootstrap>{@render children()}</BridgeBootstrap>
|
|
5
|
+
|
|
6
|
+
It runs the route guard again when the session or the flags change (a
|
|
7
|
+
sign-out in another tab, a workspace switch, a flag turned off), and
|
|
8
|
+
renders the upgrade dialog a plan limit opens.
|
|
9
|
+
-->
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import type { Snippet } from 'svelte';
|
|
12
|
+
import { onDestroy } from 'svelte';
|
|
13
|
+
import { invalidate } from '$app/navigation';
|
|
14
|
+
import { bridgeClient, bridgeConfig } from '../core/client.js';
|
|
15
|
+
import { closeUpgrade, upgradeRequest } from '../core/upgrade.js';
|
|
16
|
+
import { canManageBilling } from '../core/flags.js';
|
|
17
|
+
import { FLAGS_DEPENDENCY, SESSION_DEPENDENCY } from '../bootstrap.js';
|
|
18
|
+
import UpgradeDialog from './billing/UpgradeDialog.svelte';
|
|
19
|
+
|
|
20
|
+
let { children }: { children?: Snippet } = $props();
|
|
21
|
+
|
|
22
|
+
const mayUpgrade = canManageBilling();
|
|
23
|
+
const Dialog = $derived(typeof $bridgeConfig?.upgradeDialog === 'function' ? $bridgeConfig.upgradeDialog : UpgradeDialog);
|
|
24
|
+
const dialogOn = $derived($bridgeConfig?.upgradeDialog !== false);
|
|
25
|
+
const upgradeHref = $derived($bridgeConfig?.paywall ?? `${$bridgeConfig?.billingBase ?? '/subscription'}/plan`);
|
|
26
|
+
|
|
27
|
+
let stops: (() => void)[] = [];
|
|
28
|
+
let flagTimer: ReturnType<typeof setTimeout> | null = null;
|
|
29
|
+
|
|
30
|
+
$effect(() => {
|
|
31
|
+
const client = $bridgeClient;
|
|
32
|
+
for (const stop of stops) stop();
|
|
33
|
+
stops = [];
|
|
34
|
+
if (client === null) return;
|
|
35
|
+
const again = () => void invalidate(SESSION_DEPENDENCY);
|
|
36
|
+
stops.push(client.on('signed-in', again), client.on('signed-out', again), client.on('workspace-changed', again));
|
|
37
|
+
// Flag results change in bursts (a reload after a notice); guard once they settle.
|
|
38
|
+
let first = true;
|
|
39
|
+
stops.push(
|
|
40
|
+
client.flags.subscribe(() => {
|
|
41
|
+
if (first) {
|
|
42
|
+
first = false;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (flagTimer !== null) clearTimeout(flagTimer);
|
|
46
|
+
flagTimer = setTimeout(() => void invalidate(FLAGS_DEPENDENCY), 150);
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
onDestroy(() => {
|
|
52
|
+
for (const stop of stops) stop();
|
|
53
|
+
if (flagTimer !== null) clearTimeout(flagTimer);
|
|
54
|
+
});
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
{@render children?.()}
|
|
58
|
+
|
|
59
|
+
{#if dialogOn && $upgradeRequest}
|
|
60
|
+
<Dialog request={$upgradeRequest} {upgradeHref} canUpgrade={$mayUpgrade} onclose={closeUpgrade} />
|
|
61
|
+
{/if}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type StartBridgeRuntimeOptions } from '../core/bridge-runtime.js';
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
3
2
|
type $$ComponentProps = {
|
|
4
|
-
runtime?: StartBridgeRuntimeOptions;
|
|
5
|
-
onBootstrapComplete?: () => void;
|
|
6
3
|
children?: Snippet;
|
|
7
4
|
};
|
|
8
5
|
declare const BridgeBootstrap: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Every sign-in page from one file:
|
|
3
|
+
|
|
4
|
+
src/routes/auth/[...bridge]/+page.svelte
|
|
5
|
+
<BridgeAuthRoutes />
|
|
6
|
+
|
|
7
|
+
Serves sign-in, sign-up, verify-email, forgot-password, set-password,
|
|
8
|
+
invite, workspaces and handoff. An unknown page gets the app's own 404.
|
|
9
|
+
|
|
10
|
+
Customising, in rungs:
|
|
11
|
+
1. `--bridge-*` CSS tokens restyle the forms.
|
|
12
|
+
2. `frame(page, form)` replaces everything around the form on every page;
|
|
13
|
+
`heading(page)` replaces the form's heading on each page.
|
|
14
|
+
3. To own one page, create it (`src/routes/auth/sign-in/+page.svelte`):
|
|
15
|
+
SvelteKit prefers the specific route, and the other pages keep working.
|
|
16
|
+
4. Headless: build on `getBridge()`.
|
|
17
|
+
-->
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import type { Snippet } from 'svelte';
|
|
20
|
+
import { goto } from '$app/navigation';
|
|
21
|
+
import { page } from '$app/state';
|
|
22
|
+
import { readReturnTo } from '@nebulr-group/bridge-auth-core';
|
|
23
|
+
import { peekConfig } from '../../core/client.js';
|
|
24
|
+
import type { BridgeMessages } from '../../core/config.js';
|
|
25
|
+
import { translator } from '../../core/i18n.js';
|
|
26
|
+
import { parseAuthPage, ROUTE_PARAM, type AuthPage } from '../../core/routes.js';
|
|
27
|
+
import { signedIn } from '../../core/stores.js';
|
|
28
|
+
import AuthFormWrapper from '../shared/AuthFormWrapper.svelte';
|
|
29
|
+
import SignInForm from './SignInForm.svelte';
|
|
30
|
+
import SignUpForm from './SignUpForm.svelte';
|
|
31
|
+
import VerifyEmail from './VerifyEmail.svelte';
|
|
32
|
+
import ForgotPassword from './ForgotPassword.svelte';
|
|
33
|
+
import SetPassword from './SetPassword.svelte';
|
|
34
|
+
import InviteLanding from './InviteLanding.svelte';
|
|
35
|
+
import WorkspaceChooser from './WorkspaceChooser.svelte';
|
|
36
|
+
import HandoffSignIn from './HandoffSignIn.svelte';
|
|
37
|
+
|
|
38
|
+
interface Props {
|
|
39
|
+
/** Replaces everything around the form, on every page. */
|
|
40
|
+
frame?: Snippet<[AuthPage, Snippet]>;
|
|
41
|
+
/** Replaces the form's heading, per page. */
|
|
42
|
+
heading?: Snippet<[AuthPage]>;
|
|
43
|
+
messages?: BridgeMessages;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let { frame, heading, messages }: Props = $props();
|
|
47
|
+
|
|
48
|
+
const t = $derived(translator(messages));
|
|
49
|
+
const current = $derived(parseAuthPage(page.params[ROUTE_PARAM]));
|
|
50
|
+
const config = peekConfig();
|
|
51
|
+
|
|
52
|
+
function afterSwitch() {
|
|
53
|
+
void goto(readReturnTo(page.url, config?.returnToParam) ?? config?.afterSignIn ?? '/', { invalidateAll: true });
|
|
54
|
+
}
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
{#snippet body(p: AuthPage)}
|
|
58
|
+
{#snippet boundHeading()}
|
|
59
|
+
{@render heading?.(p)}
|
|
60
|
+
{/snippet}
|
|
61
|
+
{@const pageHeading = heading ? boundHeading : undefined}
|
|
62
|
+
{#if p === 'sign-in'}
|
|
63
|
+
<SignInForm headingSnippet={pageHeading} {messages} />
|
|
64
|
+
{:else if p === 'sign-up'}
|
|
65
|
+
<SignUpForm headingSnippet={pageHeading} {messages} />
|
|
66
|
+
{:else if p === 'verify-email'}
|
|
67
|
+
<VerifyEmail headingSnippet={pageHeading} {messages} />
|
|
68
|
+
{:else if p === 'forgot-password'}
|
|
69
|
+
<ForgotPassword headingSnippet={pageHeading} {messages} />
|
|
70
|
+
{:else if p === 'set-password'}
|
|
71
|
+
<SetPassword headingSnippet={pageHeading} {messages} />
|
|
72
|
+
{:else if p === 'invite'}
|
|
73
|
+
<InviteLanding headingSnippet={pageHeading} {messages} />
|
|
74
|
+
{:else if p === 'handoff'}
|
|
75
|
+
<HandoffSignIn headingSnippet={pageHeading} {messages} />
|
|
76
|
+
{:else if p === 'workspaces'}
|
|
77
|
+
{#if $signedIn}
|
|
78
|
+
<AuthFormWrapper heading={t('workspace.chooseHeading')} headingSnippet={pageHeading}>
|
|
79
|
+
<WorkspaceChooser onSwitch={afterSwitch} {messages} />
|
|
80
|
+
</AuthFormWrapper>
|
|
81
|
+
{:else}
|
|
82
|
+
<SignInForm headingSnippet={pageHeading} {messages} />
|
|
83
|
+
{/if}
|
|
84
|
+
{/if}
|
|
85
|
+
{/snippet}
|
|
86
|
+
|
|
87
|
+
{#if current}
|
|
88
|
+
{@const p = current}
|
|
89
|
+
{#snippet form()}
|
|
90
|
+
{@render body(p)}
|
|
91
|
+
{/snippet}
|
|
92
|
+
<div data-bridge-auth-route={p} style="display: contents">
|
|
93
|
+
{#if frame}
|
|
94
|
+
{@render frame(p, form)}
|
|
95
|
+
{:else}
|
|
96
|
+
<div class="bridge-auth-page">
|
|
97
|
+
{@render form()}
|
|
98
|
+
</div>
|
|
99
|
+
{/if}
|
|
100
|
+
</div>
|
|
101
|
+
{/if}
|
|
102
|
+
|
|
103
|
+
<style>
|
|
104
|
+
/* In the `bridge` layer with the stylesheet, so any CSS of the app wins. */
|
|
105
|
+
@layer bridge {
|
|
106
|
+
.bridge-auth-page {
|
|
107
|
+
display: flex;
|
|
108
|
+
justify-content: center;
|
|
109
|
+
padding: var(--bridge-auth-page-padding, 3rem 1rem);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
</style>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { BridgeMessages } from '../../core/config.js';
|
|
3
|
+
import { type AuthPage } from '../../core/routes.js';
|
|
4
|
+
interface Props {
|
|
5
|
+
/** Replaces everything around the form, on every page. */
|
|
6
|
+
frame?: Snippet<[AuthPage, Snippet]>;
|
|
7
|
+
/** Replaces the form's heading, per page. */
|
|
8
|
+
heading?: Snippet<[AuthPage]>;
|
|
9
|
+
messages?: BridgeMessages;
|
|
10
|
+
}
|
|
11
|
+
declare const BridgeAuthRoutes: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type BridgeAuthRoutes = ReturnType<typeof BridgeAuthRoutes>;
|
|
13
|
+
export default BridgeAuthRoutes;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Asks for a reset link. Bridge answers the same whether or not the address
|
|
3
|
+
has an account, so the page always says the email is on its way.
|
|
4
|
+
-->
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import type { Snippet } from 'svelte';
|
|
7
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
8
|
+
import { getBridge, peekConfig } from '../../core/client.js';
|
|
9
|
+
import type { BridgeMessages } from '../../core/config.js';
|
|
10
|
+
import { errorMessage, translator } from '../../core/i18n.js';
|
|
11
|
+
import AuthFormWrapper from '../shared/AuthFormWrapper.svelte';
|
|
12
|
+
import Alert from '../shared/Alert.svelte';
|
|
13
|
+
import Spinner from '../shared/Spinner.svelte';
|
|
14
|
+
|
|
15
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
16
|
+
heading?: string | null;
|
|
17
|
+
headingSnippet?: Snippet;
|
|
18
|
+
description?: string | null;
|
|
19
|
+
loginHref?: string;
|
|
20
|
+
onSent?: (email: string) => void;
|
|
21
|
+
messages?: BridgeMessages;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let { heading = undefined, headingSnippet, description = undefined, loginHref = undefined, onSent, messages, class: className, style, ...rest }: Props = $props();
|
|
25
|
+
|
|
26
|
+
const t = $derived(translator(messages));
|
|
27
|
+
const authBase = peekConfig()?.authBase ?? '/auth';
|
|
28
|
+
|
|
29
|
+
let email = $state('');
|
|
30
|
+
let loading = $state(false);
|
|
31
|
+
let sent = $state(false);
|
|
32
|
+
let failure = $state<string | null>(null);
|
|
33
|
+
|
|
34
|
+
async function submit(event: SubmitEvent) {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
if (loading) return;
|
|
37
|
+
failure = null;
|
|
38
|
+
loading = true;
|
|
39
|
+
try {
|
|
40
|
+
await getBridge().password.forgot(email.trim());
|
|
41
|
+
sent = true;
|
|
42
|
+
onSent?.(email.trim());
|
|
43
|
+
} catch (error) {
|
|
44
|
+
failure = errorMessage(error, t, 'forgot.error.send');
|
|
45
|
+
} finally {
|
|
46
|
+
loading = false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<AuthFormWrapper
|
|
52
|
+
heading={sent ? null : heading === undefined ? t('forgot.headingRequest') : heading}
|
|
53
|
+
headingSnippet={sent ? undefined : headingSnippet}
|
|
54
|
+
description={sent ? null : description === undefined ? t('forgot.description') : description}
|
|
55
|
+
class={className}
|
|
56
|
+
{style}
|
|
57
|
+
data-bridge-forgot-password={sent ? 'sent' : 'form'}
|
|
58
|
+
{...rest}
|
|
59
|
+
>
|
|
60
|
+
{#if failure}<Alert variant="error">{failure}</Alert>{/if}
|
|
61
|
+
{#if sent}
|
|
62
|
+
<Alert variant="success">{t('forgot.emailSent')}</Alert>
|
|
63
|
+
{:else}
|
|
64
|
+
<form onsubmit={submit}>
|
|
65
|
+
<div class="bridge-form-group">
|
|
66
|
+
<label for="forgot-email">{t('field.email')}</label>
|
|
67
|
+
<input id="forgot-email" type="email" autocomplete="email" placeholder={t('placeholder.email')} required bind:value={email} disabled={loading} />
|
|
68
|
+
</div>
|
|
69
|
+
<button type="submit" class="bridge-btn bridge-btn-primary" disabled={loading || !email.trim()}>
|
|
70
|
+
{#if loading}<Spinner size={16} />{:else}{t('forgot.submit')}{/if}
|
|
71
|
+
</button>
|
|
72
|
+
</form>
|
|
73
|
+
{/if}
|
|
74
|
+
<div class="bridge-form-footer">
|
|
75
|
+
<a href={loginHref ?? `${authBase}/sign-in`} class="bridge-link">{t('action.backToSignIn')}</a>
|
|
76
|
+
</div>
|
|
77
|
+
</AuthFormWrapper>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { BridgeMessages } from '../../core/config.js';
|
|
4
|
+
interface Props extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
heading?: string | null;
|
|
6
|
+
headingSnippet?: Snippet;
|
|
7
|
+
description?: string | null;
|
|
8
|
+
loginHref?: string;
|
|
9
|
+
onSent?: (email: string) => void;
|
|
10
|
+
messages?: BridgeMessages;
|
|
11
|
+
}
|
|
12
|
+
declare const ForgotPassword: import("svelte").Component<Props, {}, "">;
|
|
13
|
+
type ForgotPassword = ReturnType<typeof ForgotPassword>;
|
|
14
|
+
export default ForgotPassword;
|