@donotdev/auth 0.1.42 → 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/dist/AuthStore.js +1 -1
- package/dist/components/AccountLinking.d.ts +1 -1
- package/dist/components/AccountLinking.d.ts.map +1 -1
- package/dist/components/AuthFallback.d.ts +11 -3
- package/dist/components/AuthFallback.d.ts.map +1 -1
- package/dist/components/AuthPartnerButton.d.ts +2 -2
- package/dist/components/AuthPartnerButton.d.ts.map +1 -1
- package/dist/components/AuthPartnerButton.js +1 -1
- package/dist/components/DeleteAccountDialogs.d.ts +2 -2
- package/dist/components/DeleteAccountDialogs.d.ts.map +1 -1
- package/dist/components/DeleteAccountDialogs.js +1 -1
- package/dist/components/EmailLinkForm.d.ts +1 -1
- package/dist/components/EmailLinkForm.d.ts.map +1 -1
- package/dist/components/EmailLinkForm.js +1 -1
- package/dist/components/EmailPasswordForm.d.ts +1 -1
- package/dist/components/EmailPasswordForm.d.ts.map +1 -1
- package/dist/components/EmailPasswordForm.js +2 -2
- package/dist/components/EmailVerification.d.ts +1 -1
- package/dist/components/EmailVerification.d.ts.map +1 -1
- package/dist/components/Feature.d.ts.map +1 -1
- package/dist/components/Feature.js +1 -1
- package/dist/components/FeatureGuard.d.ts +67 -6
- package/dist/components/FeatureGuard.d.ts.map +1 -1
- package/dist/components/FeatureGuard.js +1 -1
- package/dist/components/FeaturePlaceholder.d.ts +11 -3
- package/dist/components/FeaturePlaceholder.d.ts.map +1 -1
- package/dist/components/FeaturePlaceholder.js +1 -1
- package/dist/components/GoogleOneTap.d.ts +33 -1
- package/dist/components/GoogleOneTap.d.ts.map +1 -1
- package/dist/components/GoogleOneTap.js +1 -1
- package/dist/components/LoginModal.d.ts +1 -1
- package/dist/components/LoginModal.d.ts.map +1 -1
- package/dist/components/LoginModal.js +1 -1
- package/dist/components/MultipleAuthProviders.d.ts +1 -1
- package/dist/components/MultipleAuthProviders.d.ts.map +1 -1
- package/dist/components/MultipleAuthProviders.js +1 -1
- package/dist/components/NetworkStatusIndicator.d.ts +1 -1
- package/dist/components/NetworkStatusIndicator.d.ts.map +1 -1
- package/dist/components/PasswordResetCallback.d.ts +1 -1
- package/dist/components/PasswordResetCallback.d.ts.map +1 -1
- package/dist/components/PasswordResetCallback.js +1 -1
- package/dist/components/PasswordStrengthIndicator.d.ts +1 -1
- package/dist/components/PasswordStrengthIndicator.d.ts.map +1 -1
- package/dist/components/PasswordStrengthIndicator.js +1 -1
- package/dist/components/PasswordUpdateDialog.d.ts +1 -1
- package/dist/components/PasswordUpdateDialog.d.ts.map +1 -1
- package/dist/components/RateLimitAlert.d.ts +8 -0
- package/dist/components/RateLimitAlert.d.ts.map +1 -1
- package/dist/components/RateLimitAlert.js +1 -1
- package/dist/hooks/useAuthMethodToggle.js +1 -1
- package/dist/hooks/useAuthPartner.d.ts +1 -1
- package/dist/hooks/useAuthPartner.d.ts.map +1 -1
- package/dist/hooks/useAuthPartner.js +1 -1
- package/dist/hooks/useEmailLinkForm.js +1 -1
- package/dist/hooks/useFedCM.js +1 -1
- package/dist/hooks/useGoogleOneTap.js +1 -1
- package/dist/hooks/useNetworkStatus.js +1 -1
- package/dist/index.js +1 -1
- package/dist/symbol-index.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useAuth.d.ts.map +1 -1
- package/dist/useAuth.js +1 -1
- package/guidelines/AUTH.md +281 -0
- package/package.json +9 -8
package/dist/useAuth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../src/useAuth.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAKV,OAAO,EAER,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../src/useAuth.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAKV,OAAO,EAER,MAAM,gBAAgB,CAAC;AAmKxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAsXnE"}
|
package/dist/useAuth.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useEffect as
|
|
1
|
+
"use client";import{useEffect as H,useCallback as s,useRef as J}from"react";import{DEGRADED_AUTH_API as w,FEATURE_STATUS as l,handleError as K,hasProvider as Q,getProvider as X,isClient as i,USER_ROLES as R,SUBSCRIPTION_TIERS as ee,hasRoleAccess as y,hasTierAccess as te,getGlobalSingleton as ne,useAuthSessionSnapshot as ie}from"@donotdev/core";import{useAuthStore as u}from"./AuthStore";import{getAuthMethod as C}from"./constants";const e=ne("auth-provider",()=>({instance:null,initializing:!1,errorNotified:!1}));function se(){const a=n=>{const c=u.getState();if(y(c.user?.role,R.ADMIN))return!0;const o=c.userProfile?.permissions;return o?o.includes(n):!1};return{navigate:n=>{const c=u.getState();return n===!1?!0:n===!0?!!c.user:!(n.required&&!c.user||n.role&&!y(c.user?.role,n.role)||n.tier&&!te(c.userSubscription?.tier,n.tier)||n.validate&&c.userSubscription&&c.user?.role&&!n.validate(c.user.role,c.userSubscription.tier))},view:n=>a(`${n}:view`),edit:n=>a(`${n}:edit`),delete:n=>a(`${n}:delete`),create:n=>a(`${n}:create`),has:n=>a(n),perform:(n,c)=>{const o=u.getState();if(y(o.user?.role,R.ADMIN))return!0;if(!a(n))return!1;if(c){const d=o.userProfile?.capabilities;if(d?.[n]){const h=d[n];for(const[g,m]of Object.entries(c))if(typeof h[g]=="number"&&typeof m=="number"&&m>h[g])return!1}}return!0}}}const ae=se(),b=new Set(["user","loading","error","status","userProfile","userSubscription","emailVerification","passwordResetPending","partnerError","getPartnerState","setPartnerState"]);function re(a){const n=J(null);H(()=>{if(!i())return;const{status:t}=u.getState();return t===l.READY||e.initializing?void 0:(e.initializing=!0,(async()=>{try{if(Q("auth"))e.instance=X("auth");else{const{getFirebaseAuth:r}=await import("@donotdev/firebase");e.instance=r()}if(!e.instance)return;"setStore"in e.instance&&e.instance.setStore(u.getState()),u.getState().setAuthService(e.instance),await e.instance.initialize(),n.current=e.instance.onAuthStateChanged(()=>{}),e.errorNotified=!1}catch(r){u.getState().setStatus(l.DEGRADED),e.errorNotified||(K(r,{userMessage:"Authentication initialization failed",context:{operation:"useAuth.initialize"},severity:"warning",showNotification:!1}),e.errorNotified=!0)}finally{e.initializing=!1}})(),()=>{n.current?.(),n.current=null,e.initializing=!1})},[]);const c=s(async(t,r)=>!i()||!e.instance?null:e.instance.signInWithEmail(t,r),[]),o=s(async(t,r,f)=>!i()||!e.instance?null:e.instance.createUserWithEmail(t,r,f),[]),d=s(async(t,r)=>{if(!i()||!e.instance)return null;const f=C(r);return e.instance.signInWithPartner(t,f)},[]),h=s(async(t,r)=>{if(!i()||!e.instance)return null;const f=C(r);return e.instance.linkWithPartner(t,f)},[]),g=s(async t=>!i()||!e.instance?null:e.instance.signInWithGoogleCredential(t),[]),m=s(async()=>{if(!(!i()||!e.instance))return e.instance.signOut()},[]),W=s(async t=>{if(!(!i()||!e.instance))return e.instance.sendPasswordResetEmail(t)},[]),v=s(async t=>{if(!(!i()||!e.instance))return e.instance.updatePassword(t)},[]),T=s(async t=>!i()||!e.instance?.verifyPasswordResetCode?null:e.instance.verifyPasswordResetCode(t),[]),D=s(async(t,r)=>{if(!(!i()||!e.instance?.confirmPasswordReset))return e.instance.confirmPasswordReset(t,r)},[]),N=s(async()=>{if(!(!i()||!e.instance))return e.instance.sendEmailVerification()},[]),U=s(async(t,r)=>{if(!(!i()||!e.instance))return e.instance.sendSignInLinkToEmail(t,r)},[]),G=s(async(t,r)=>!i()||!e.instance?null:e.instance.signInWithEmailLink(t,r),[]),k=s(t=>!i()||!e.instance?!1:e.instance.isSignInWithEmailLink(t),[]),L=s(async()=>!i()||!e.instance?null:e.instance.getCurrentUser(),[]),z=s(async()=>!i()||!e.instance?{status:"pending"}:e.instance.getEmailVerificationStatus(),[]),M=s(async()=>!i()||!e.instance?!1:e.instance.isEmailVerificationEnabled(),[]),V=s(async t=>!i()||!e.instance?!1:e.instance.hasRole(t),[]),O=s(async t=>!i()||!e.instance?!1:e.instance.hasTier(t),[]),F=s(async t=>!i()||!e.instance?!1:e.instance.hasFeature(t),[]),_=s(()=>i()?u.getState().getCustomClaims():{},[]),$=s(t=>i()?u.getState().getCustomClaim(t):null,[]),x=s(async t=>{if(!(!i()||!e.instance))return e.instance.reauthenticateWithPassword(t)},[]),Y=s(async(t,r)=>{if(!(!i()||!e.instance))return e.instance.reauthenticateWithProvider(t,r)},[]),Z=s(async t=>{if(!(!i()||!e.instance))return e.instance.deleteAccount(t)},[]),j=s(async t=>{if(!(!i()||!e.instance?.setRememberMe))return e.instance.setRememberMe(t)},[]),A={signInWithEmail:c,createUserWithEmail:o,signInWithPartner:d,linkWithPartner:h,signInWithGoogleCredential:g,signOut:m,sendPasswordResetEmail:W,updatePassword:v,verifyPasswordResetCode:T,confirmPasswordReset:D,sendEmailVerification:N,getEmailVerificationStatus:z,isEmailVerificationEnabled:M,sendSignInLinkToEmail:U,signInWithEmailLink:G,isSignInWithEmailLink:k,getCurrentUser:L,reauthenticateWithPassword:x,reauthenticateWithProvider:Y,deleteAccount:Z,setRememberMe:j,hasRole:V,hasTier:O,hasFeature:F,getCustomClaims:_,getCustomClaim:$},I=new Set(["isAuthenticated","userRole","userTier","can"]),q=u(t=>b.has(a)?t[a]:null),B=u(t=>I.has(a)?a==="isAuthenticated"?!!t.user:a==="userRole"?t.user?.role||R.GUEST:a==="userTier"?t.userSubscription?.tier||ee.FREE:a==="can"?ae:null:null),P=u(t=>t.status),S=ie(),p=P===l.INITIALIZING&&S!==null,E=p?l.READY:P;if(a==="status")return E;if(p){if(a==="user")return S.user;if(a==="isAuthenticated")return!!S.user;if(a==="userRole")return S.user?.role||R.GUEST}return E===l.INITIALIZING||E===l.DEGRADED||E===l.ERROR?w[a]:a==="isAvailable"?!0:b.has(a)?q:a in A?A[a]:I.has(a)?B:w[a]}export{re as useAuth};
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# Authentication
|
|
2
|
+
|
|
3
|
+
**Most is pre-configured.** Works with Firebase Auth or Supabase Auth. Add env vars and config. Framework handles providers, callbacks, sessions.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Standard Use
|
|
8
|
+
|
|
9
|
+
**Environment:**
|
|
10
|
+
```bash
|
|
11
|
+
# .env
|
|
12
|
+
VITE_AUTH_PARTNERS=password,emailLink,google,github,facebook
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Firebase:** Enable providers in Firebase Console > Authentication > Sign-in method
|
|
16
|
+
**Supabase:** Enable providers in Supabase Dashboard > Authentication > Providers
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Auth Config
|
|
21
|
+
|
|
22
|
+
All auth behavior is configured in `src/config/app.ts` under the `auth` key. The framework provides sensible defaults.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
// src/config/app.ts
|
|
26
|
+
export const appConfig: AppConfig = {
|
|
27
|
+
auth: {
|
|
28
|
+
// Where to redirect when auth is required but user is not logged in.
|
|
29
|
+
// null (default) = show AuthGuardFallback in-place (no redirect, best UX).
|
|
30
|
+
// string = redirect to that route (e.g. '/signin').
|
|
31
|
+
authRoute: null,
|
|
32
|
+
|
|
33
|
+
// Where to redirect when user has wrong role (default: '/404').
|
|
34
|
+
roleRoute: '/404',
|
|
35
|
+
|
|
36
|
+
// Where to redirect when user has wrong subscription tier (default: '/404').
|
|
37
|
+
tierRoute: '/404',
|
|
38
|
+
|
|
39
|
+
// Path to a dedicated login page. If set, AuthHeader links to it.
|
|
40
|
+
// If undefined (default), auth providers show in the header dropdown.
|
|
41
|
+
loginPath: undefined,
|
|
42
|
+
|
|
43
|
+
// Path to password reset callback page (default: '/auth/reset-password').
|
|
44
|
+
// Framework auto-handles this route.
|
|
45
|
+
resetPasswordPath: '/auth/reset-password',
|
|
46
|
+
|
|
47
|
+
// Path to profile page (default: '/profile').
|
|
48
|
+
profilePath: '/profile',
|
|
49
|
+
|
|
50
|
+
// Custom menu items in the authenticated user dropdown.
|
|
51
|
+
authMenuItems: [
|
|
52
|
+
{ path: '/dashboard', label: 'Dashboard' },
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Auth Route Behavior
|
|
59
|
+
|
|
60
|
+
| `authRoute` value | Behavior when unauthenticated user hits protected route |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `null` (default) | `AuthGuardFallback` renders in-place - sign-in form on the protected page itself. User stays in context. Best UX. |
|
|
63
|
+
| `'/'` | Redirect to homepage. |
|
|
64
|
+
| `'/signin'` | Redirect to custom sign-in page. App must define this route. |
|
|
65
|
+
|
|
66
|
+
After successful sign-in, the user is redirected back to the original page they requested (via `dndev.auth.returnTo` in sessionStorage, handled by `AuthReturnTo`).
|
|
67
|
+
|
|
68
|
+
### Role & Tier Routes
|
|
69
|
+
|
|
70
|
+
`roleRoute` and `tierRoute` control where users land when they have insufficient permissions. Default is `/404` - the user sees a not-found page rather than being told a resource exists they can't access.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Protected Routes
|
|
75
|
+
|
|
76
|
+
Define auth requirements in page `meta`:
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
// Basic protection - any authenticated user
|
|
80
|
+
export const meta: PageMeta = {
|
|
81
|
+
namespace: NAMESPACE,
|
|
82
|
+
auth: { required: true },
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Role-based access
|
|
86
|
+
export const meta: PageMeta = {
|
|
87
|
+
namespace: NAMESPACE,
|
|
88
|
+
auth: { required: true, role: 'admin' },
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Tier-based access
|
|
92
|
+
export const meta: PageMeta = {
|
|
93
|
+
namespace: NAMESPACE,
|
|
94
|
+
auth: { required: true, tier: 'pro' },
|
|
95
|
+
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**SEO note:** Auth-guarded routes are still indexed by default. Add `noindex: true` to page meta if the route should be hidden from search engines.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Components
|
|
103
|
+
|
|
104
|
+
### AuthGuard
|
|
105
|
+
|
|
106
|
+
Wraps route content. Checks auth state and either renders children, redirects, or shows fallback.
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { AuthGuard } from '@donotdev/ui';
|
|
110
|
+
|
|
111
|
+
// Automatic - framework wraps routes based on page meta.auth
|
|
112
|
+
// Manual usage:
|
|
113
|
+
<AuthGuard auth={{ required: true }}>
|
|
114
|
+
<ProtectedContent />
|
|
115
|
+
</AuthGuard>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Behavior flow:**
|
|
119
|
+
1. Auth initializing → show spinner
|
|
120
|
+
2. Auth resolved, user authorized → render children
|
|
121
|
+
3. Auth resolved, user not authorized:
|
|
122
|
+
- `authRoute` is null → render `AuthGuardFallback` in-place
|
|
123
|
+
- `authRoute` is set → redirect to that route
|
|
124
|
+
4. Auth slow (>5s) → show slow-loading warning with refresh button
|
|
125
|
+
|
|
126
|
+
### AuthGuardFallback
|
|
127
|
+
|
|
128
|
+
Shows sign-in options directly on the protected route. No redirect needed.
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
import { AuthGuardFallback } from '@donotdev/ui';
|
|
132
|
+
|
|
133
|
+
// Automatic when authRoute is null (default).
|
|
134
|
+
// Manual usage:
|
|
135
|
+
<AuthGuardFallback
|
|
136
|
+
title="Custom title"
|
|
137
|
+
description="Custom description"
|
|
138
|
+
showBackButton={true}
|
|
139
|
+
onBack={() => navigate('/')}
|
|
140
|
+
/>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### AuthReturnTo
|
|
144
|
+
|
|
145
|
+
Mounted in RootLayout. After OAuth callback, redirects user back to the page they originally requested. No configuration needed.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Hooks
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
import { useAuth } from '@donotdev/auth';
|
|
153
|
+
import { MultipleAuthProviders, AuthPartnerButton } from '@donotdev/auth';
|
|
154
|
+
import { AuthHeader, AuthMenu } from '@donotdev/ui';
|
|
155
|
+
|
|
156
|
+
// Hook
|
|
157
|
+
const user = useAuth('user');
|
|
158
|
+
const signIn = useAuth('signInWithEmail');
|
|
159
|
+
const signOut = useAuth('signOut');
|
|
160
|
+
|
|
161
|
+
// Components
|
|
162
|
+
<MultipleAuthProviders layout="vertical" emailMode="signin" />
|
|
163
|
+
<AuthPartnerButton partnerId="google" method="popup" />
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**Pre-configured:** `AuthHeader` in layout (null if auth disabled), OAuth callbacks, session management, account linking.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## User Roles
|
|
171
|
+
|
|
172
|
+
**Role hierarchy:** `guest (0) < user (1) < admin (2) < super (3)`
|
|
173
|
+
|
|
174
|
+
**Default:** All authenticated users are `'user'` role.
|
|
175
|
+
|
|
176
|
+
**Setting admin/super roles:**
|
|
177
|
+
|
|
178
|
+
**Firebase** - Set customClaims:
|
|
179
|
+
```typescript
|
|
180
|
+
import { getFirebaseAdminAuth } from '@donotdev/firebase/server';
|
|
181
|
+
|
|
182
|
+
const auth = getFirebaseAdminAuth();
|
|
183
|
+
await auth.setCustomUserClaims(userId, {
|
|
184
|
+
role: 'admin', // or 'super'
|
|
185
|
+
isAdmin: true // legacy support
|
|
186
|
+
});
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Supabase** - Set user metadata:
|
|
190
|
+
```sql
|
|
191
|
+
-- In Supabase Dashboard > SQL Editor
|
|
192
|
+
UPDATE auth.users SET raw_app_meta_data = raw_app_meta_data || '{"role": "admin"}' WHERE id = '<user-id>';
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Using CLI:**
|
|
196
|
+
```bash
|
|
197
|
+
dndev make-admin <userId>
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Note:** User must sign out and sign in again for role changes to take effect.
|
|
201
|
+
|
|
202
|
+
**Used by:** CRUD access control, protected routes, field visibility filtering.
|
|
203
|
+
|
|
204
|
+
### Redirect URLs (Supabase only)
|
|
205
|
+
|
|
206
|
+
After OAuth (Google, GitHub, etc.), Supabase redirects the user back to your app. You must tell Supabase which URLs are allowed.
|
|
207
|
+
|
|
208
|
+
**Supabase Dashboard > Authentication > URL Configuration:**
|
|
209
|
+
|
|
210
|
+
| Setting | Value |
|
|
211
|
+
|---------|-------|
|
|
212
|
+
| **Site URL** | Your **production** URL (e.g., `https://myapp.vercel.app`) |
|
|
213
|
+
| **Redirect URLs** | All URLs where auth should work (see below) |
|
|
214
|
+
|
|
215
|
+
**Add to Redirect URLs:**
|
|
216
|
+
- `http://localhost:5173` - local Vite dev
|
|
217
|
+
- `http://localhost:3000` - local Next.js dev
|
|
218
|
+
- `https://myapp.vercel.app` - production
|
|
219
|
+
- `https://*-yourteam.vercel.app` - Vercel preview deploys
|
|
220
|
+
|
|
221
|
+
> **Site URL must be production.** It's the fallback when no redirect URL matches. If it's `localhost:3000`, your deployed app redirects to localhost after OAuth.
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Security Context
|
|
226
|
+
|
|
227
|
+
Wire `DndevSecurity` into the auth provider for rate limiting, audit logging, and signup consent tracking.
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// src/bootstrap.ts (or wherever auth is initialized)
|
|
231
|
+
import { DndevSecurity } from '@donotdev/security/server';
|
|
232
|
+
|
|
233
|
+
const security = new DndevSecurity({ /* config */ });
|
|
234
|
+
auth.setSecurity(security);
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**What it enables:**
|
|
238
|
+
|
|
239
|
+
| Feature | Without setSecurity | With setSecurity |
|
|
240
|
+
|---------|-------------------|-----------------|
|
|
241
|
+
| Password reset rate limiting | No protection | Per-email throttle (prevents flooding) |
|
|
242
|
+
| Brute-force lockout | Default (5 attempts / 15 min) | Configurable via security config |
|
|
243
|
+
| GDPR signup consent audit | Silently skipped | `auth.signup.consent` event emitted |
|
|
244
|
+
| Login/logout audit trail | No events | Full audit events |
|
|
245
|
+
|
|
246
|
+
### Signup Consent (GDPR)
|
|
247
|
+
|
|
248
|
+
When `EmailPasswordForm` renders a ToS/Privacy checkbox, the framework automatically passes a `SignUpMetadata` object to the auth provider on signup:
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
// Automatically sent by EmailPasswordForm when tosAccepted is true
|
|
252
|
+
{
|
|
253
|
+
gdpr_consent_at: '2026-04-01T12:00:00.000Z', // ISO-8601 timestamp
|
|
254
|
+
gdpr_tos_version: '1.0', // optional, if configured
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**Supabase:** Stored durably in `raw_user_meta_data` on the auth.users row AND emitted as audit event.
|
|
259
|
+
|
|
260
|
+
**Firebase:** Emitted as `auth.signup.consent` audit event (no client-side user metadata storage). For durable consent records, wire a server-side listener or callable function to persist to Firestore.
|
|
261
|
+
|
|
262
|
+
### ToS/Privacy Links
|
|
263
|
+
|
|
264
|
+
Configure in `appConfig.footer.legalLinks`:
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
export const appConfig: AppConfig = {
|
|
268
|
+
footer: {
|
|
269
|
+
legalLinks: {
|
|
270
|
+
terms: '/legal/terms', // or false to disable
|
|
271
|
+
privacy: '/legal/privacy', // or false to disable
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
`EmailPasswordForm` auto-detects these. Falls back to `/legal/terms` and `/legal/privacy` if not set.
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
**Add env vars, get auth. Framework handles the rest.**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donotdev/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
|
+
"guidelines",
|
|
20
21
|
"package.json",
|
|
21
22
|
"README.md",
|
|
22
23
|
"LICENSE.md"
|
|
@@ -42,13 +43,13 @@
|
|
|
42
43
|
"type-check": "bunx tsc --noEmit"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
|
-
"@donotdev/components": "^0.
|
|
46
|
-
"@donotdev/core": "^0.
|
|
47
|
-
"@donotdev/firebase": "^0.
|
|
48
|
-
"@donotdev/supabase": "^0.
|
|
46
|
+
"@donotdev/components": "^0.2.0",
|
|
47
|
+
"@donotdev/core": "^0.2.0",
|
|
48
|
+
"@donotdev/firebase": "^0.2.0",
|
|
49
|
+
"@donotdev/supabase": "^0.2.0",
|
|
49
50
|
"lucide-react": "*",
|
|
50
|
-
"react": "^19.
|
|
51
|
-
"react-dom": "^19.
|
|
51
|
+
"react": "^19.3.1",
|
|
52
|
+
"react-dom": "^19.3.1",
|
|
52
53
|
"react-hook-form": "*"
|
|
53
54
|
},
|
|
54
55
|
"peerDependenciesMeta": {
|
|
@@ -64,4 +65,4 @@
|
|
|
64
65
|
"access": "public"
|
|
65
66
|
},
|
|
66
67
|
"dependencies": {}
|
|
67
|
-
}
|
|
68
|
+
}
|