bwh-auth 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Brian Herila
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,216 @@
1
+ # bwh-auth
2
+
3
+ Shared headless React auth components for BWH applications.
4
+
5
+ This package owns auth-specific React behavior and browser helpers. It does not import
6
+ or bundle a UI kit, Blade page wrappers, or application Vite entrypoints. Consumers must inject their own UI components and mount these components from app-owned pages/entrypoints.
7
+
8
+ ## Ownership boundary
9
+
10
+ `bwh-auth` exports React components only. Laravel apps should keep their own Blade files such as `resources/views/auth/login.blade.php` and Vite entrypoints such as `resources/js/auth/login.tsx`; those app files import and mount these shared components.
11
+
12
+ ## Components
13
+
14
+ - `LoginForm`
15
+ - `SignupForm`
16
+ - `PasswordResetRequestForm`
17
+ - `ResetPasswordForm`
18
+ - `ChangePasswordForm`
19
+ - `TwoFactorForm`
20
+ - `PasskeyLoginButton`
21
+ - `PasskeySection`
22
+
23
+ ## Install
24
+
25
+ For app CI before npm publication, use the GitHub Release tarball. This is the recommended path because the tarball includes built `dist` files and does not require CI to build this package during dependency installation.
26
+
27
+ ```sh
28
+ pnpm add https://github.com/bherila/auth/releases/download/bwh-auth-v0.2.0/bwh-auth-0.2.0.tgz
29
+ ```
30
+
31
+ Or pin it manually in `package.json`:
32
+
33
+ ```json
34
+ {
35
+ "dependencies": {
36
+ "bwh-auth": "https://github.com/bherila/auth/releases/download/bwh-auth-v0.2.0/bwh-auth-0.2.0.tgz"
37
+ }
38
+ }
39
+ ```
40
+
41
+ When installing locally during package development, a path dependency is still useful:
42
+
43
+ ```sh
44
+ pnpm add bwh-auth@file:../auth/ui
45
+ ```
46
+
47
+ Install peer dependencies in the consuming app:
48
+
49
+ ```sh
50
+ pnpm add lucide-react react react-dom
51
+ ```
52
+
53
+ React and React DOM are usually already present in Laravel/Vite apps.
54
+
55
+ ## Component Injection
56
+
57
+ Higher-level components require injected components so each app can use its own
58
+ shadcn/Base UI components and Vite can tree-shake cleanly.
59
+
60
+ ```tsx
61
+ import { LoginForm, type AuthComponentInput } from "bwh-auth"
62
+ import { Button } from "@/components/ui/button"
63
+ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
64
+ import { Input } from "@/components/ui/input"
65
+ import { Label } from "@/components/ui/label"
66
+
67
+ export function getShadcnComponents() {
68
+ return {
69
+ Button,
70
+ Card,
71
+ CardContent,
72
+ CardDescription: ({ ...props }) => <div {...props} />,
73
+ CardHeader,
74
+ CardTitle,
75
+ Input,
76
+ Label,
77
+ // Extra keys are allowed so this helper can be shared across features.
78
+ Textarea,
79
+ Dialog,
80
+ } satisfies AuthComponentInput
81
+ }
82
+
83
+ export function LoginPage() {
84
+ return <LoginForm components={getShadcnComponents()} />
85
+ }
86
+ ```
87
+
88
+ ## Custom Signup Fields
89
+
90
+ `SignupForm` is field-driven so apps can keep app-specific registration concepts, such as invite codes or policy checkboxes, while reusing the shared auth form behavior.
91
+
92
+ ```tsx
93
+ <SignupForm
94
+ components={getShadcnComponents()}
95
+ submitMode="native"
96
+ fields={[
97
+ { name: 'first_name', label: 'First Name', required: true, autoComplete: 'given-name' },
98
+ { name: 'last_name', label: 'Last Name', required: true, autoComplete: 'family-name' },
99
+ { name: 'email', label: 'Email', type: 'email', required: true, autoComplete: 'email' },
100
+ { name: 'password', label: 'Password', type: 'password', required: true, minLength: 8, autoComplete: 'new-password' },
101
+ { name: 'password_confirmation', label: 'Confirm Password', type: 'password', required: true, minLength: 8, autoComplete: 'new-password' },
102
+ { name: 'invite_code', label: 'Season Invite Code', required: true },
103
+ { name: 'agreement', label: 'I agree to keep this program confidential.', type: 'checkbox', required: true },
104
+ ]}
105
+ />
106
+ ```
107
+
108
+ Signup fields can use `hiddenWhen` for flows such as passwordless signup, where the app submits `passwordless=1` and hides password fields:
109
+
110
+ ```tsx
111
+ const fields = [
112
+ { name: 'email', label: 'Email', type: 'email', required: true },
113
+ { name: 'passwordless', label: 'Use a passkey instead of a password', type: 'checkbox' },
114
+ { name: 'password', label: 'Password', type: 'password', required: true, hiddenWhen: (values) => Boolean(values.passwordless) },
115
+ { name: 'password_confirmation', label: 'Confirm Password', type: 'password', required: true, hiddenWhen: (values) => Boolean(values.passwordless) },
116
+ ]
117
+ ```
118
+
119
+ For fetch-based signup flows, `onSuccess` receives both the server result and submitted values. That lets apps create the user first, then enroll a passkey through the shared WebAuthn helper:
120
+
121
+ ```tsx
122
+ import { SignupForm, registerPasskey } from 'bwh-auth'
123
+
124
+ <SignupForm
125
+ components={getShadcnComponents()}
126
+ submitMode="fetch"
127
+ fields={fields}
128
+ onSuccess={async (result, values) => {
129
+ if (values.passwordless) {
130
+ await registerPasskey({ endpoints: { csrfToken } })
131
+ }
132
+
133
+ window.location.assign(result.redirect || '/')
134
+ }}
135
+ />
136
+ ```
137
+
138
+ ## Passkey sign-in
139
+
140
+ `LoginForm` can include an explicit passkey sign-in button and can opt into WebAuthn conditional UI so passkeys appear in the browser autofill menu for the email field. Conditional UI uses `PublicKeyCredential.isConditionalMediationAvailable()`, starts a conditional `navigator.credentials.get()` request, and sets the email input autocomplete to `username webauthn` when supported.
141
+
142
+ ```tsx
143
+ <LoginForm
144
+ components={getShadcnComponents()}
145
+ enablePasskeys
146
+ enablePasskeyAutofill
147
+ />
148
+ ```
149
+
150
+ The explicit passkey button and conditional autofill both default to the Laravel package routes:
151
+
152
+ - `POST /api/passkeys/auth/options`
153
+ - `POST /api/passkeys/auth`
154
+
155
+ ## Password Change
156
+
157
+ `ChangePasswordForm` is intended for authenticated settings pages or dialogs. The consuming app owns the wrapper and backend endpoint; the form posts to `/api/change-password` by default and accepts `endpoints.changePassword` for apps that use a different route.
158
+
159
+ ```tsx
160
+ <ChangePasswordForm
161
+ components={getShadcnComponents()}
162
+ endpoints={{ csrfToken }}
163
+ onSuccess={() => setMessage('Password changed successfully.')}
164
+ onError={setError}
165
+ />
166
+ ```
167
+
168
+ ## Endpoint Defaults
169
+
170
+ Auth forms default to the Laravel package API routes where the Laravel package owns the endpoint:
171
+
172
+ - `POST /api/auth/forgot-password`
173
+ - `POST /api/auth/reset-password`
174
+ - `POST /api/change-password`
175
+ - `POST /api/auth/two-factor/verify`
176
+ - `POST /api/auth/two-factor/resend`
177
+ - `POST /api/auth/two-factor/report/:token`
178
+
179
+ Passkey components default to the Laravel package routes:
180
+
181
+ - `GET /api/passkeys`
182
+ - `POST /api/passkeys/register/options`
183
+ - `POST /api/passkeys/register`
184
+ - `DELETE /api/passkeys/:id`
185
+ - `POST /api/passkeys/auth/options`
186
+ - `POST /api/passkeys/auth`
187
+
188
+ ## Releasing
189
+
190
+ Create and upload a GitHub release from this package directory:
191
+
192
+ ```sh
193
+ pnpm release
194
+ ```
195
+
196
+ The release script:
197
+
198
+ - requires a clean git working tree
199
+ - bumps `ui/package.json` version, defaulting to `patch`
200
+ - runs `pnpm install --lockfile-only`
201
+ - runs typecheck and build
202
+ - creates `ui/release/bwh-auth-VERSION.tgz`
203
+ - commits the version bump
204
+ - creates and pushes a tag like `bwh-auth-v0.1.1`
205
+ - creates a GitHub release with the tarball asset
206
+ - prints the install URL
207
+
208
+ Version bump options:
209
+
210
+ ```sh
211
+ pnpm release patch
212
+ pnpm release minor
213
+ pnpm release major
214
+ pnpm release --version=0.2.0
215
+ pnpm release --dry-run
216
+ ```