dauth-context-react 2.1.0 → 2.3.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 +15 -11
- package/dist/{interfaces.d.ts → index.d.mts} +65 -48
- package/dist/index.d.ts +65 -8
- package/dist/index.js +730 -5
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +715 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +26 -20
- package/src/api/dauth.api.ts +20 -0
- package/src/api/interfaces/dauth.api.responses.ts +8 -0
- package/src/index.tsx +67 -32
- package/src/initialDauthState.ts +1 -0
- package/src/interfaces.ts +16 -0
- package/src/reducer/dauth.actions.ts +99 -60
- package/dist/api/dauth.api.d.ts +0 -10
- package/dist/api/interfaces/dauth.api.responses.d.ts +0 -38
- package/dist/api/utils/config.d.ts +0 -4
- package/dist/api/utils/routes.d.ts +0 -4
- package/dist/constants.d.ts +0 -2
- package/dist/dauth-context-react.cjs.development.js +0 -1118
- package/dist/dauth-context-react.cjs.development.js.map +0 -1
- package/dist/dauth-context-react.cjs.production.min.js +0 -2
- package/dist/dauth-context-react.cjs.production.min.js.map +0 -1
- package/dist/dauth-context-react.esm.js +0 -1110
- package/dist/dauth-context-react.esm.js.map +0 -1
- package/dist/initialDauthState.d.ts +0 -3
- package/dist/reducer/dauth.actions.d.ts +0 -41
- package/dist/reducer/dauth.reducer.d.ts +0 -2
- package/dist/reducer/dauth.types.d.ts +0 -5
package/README.md
CHANGED
|
@@ -108,6 +108,9 @@ interface IDauthUser {
|
|
|
108
108
|
role: string;
|
|
109
109
|
telPrefix: string;
|
|
110
110
|
telSuffix: string;
|
|
111
|
+
birthDate?: Date;
|
|
112
|
+
country?: string;
|
|
113
|
+
metadata?: any;
|
|
111
114
|
createdAt: Date;
|
|
112
115
|
updatedAt: Date;
|
|
113
116
|
lastLogin: Date;
|
|
@@ -257,19 +260,19 @@ function LayoutMain() {
|
|
|
257
260
|
## How It Works
|
|
258
261
|
|
|
259
262
|
1. **On mount:** Checks the URL for a redirect token (`?dauth_state=...`), then attempts auto-login from localStorage.
|
|
260
|
-
2. **Token
|
|
261
|
-
3. **Localhost detection:** Automatically routes API calls to `localhost:4012` during development (detects `localhost`, `127.0.0.1`, `[::1]`, and `192.168.x.x`) and to `https
|
|
262
|
-
4. **Token storage:**
|
|
263
|
+
2. **Token refresh:** Proactively refreshes the access token before expiry (5 minutes before). Falls back to periodic refresh every 5 minutes if decode fails.
|
|
264
|
+
3. **Localhost detection:** Automatically routes API calls to `localhost:4012` during development (detects `localhost`, `127.0.0.1`, `[::1]`, and `192.168.x.x`) and to `https://dauth.ovh` in production.
|
|
265
|
+
4. **Token storage:** Access token stored in localStorage under `dauth_state`, refresh token under `dauth_refresh_token`.
|
|
263
266
|
|
|
264
267
|
## Development
|
|
265
268
|
|
|
266
269
|
```bash
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
270
|
+
pnpm start # Watch mode (tsdx watch)
|
|
271
|
+
pnpm build # Production build (CJS + ESM)
|
|
272
|
+
pnpm test # Run Jest tests
|
|
273
|
+
pnpm lint # ESLint via tsdx
|
|
274
|
+
pnpm size # Check bundle size (10KB budget per entry)
|
|
275
|
+
pnpm analyze # Bundle size analysis with visualization
|
|
273
276
|
```
|
|
274
277
|
|
|
275
278
|
### Bundle Outputs
|
|
@@ -278,9 +281,10 @@ npm run analyze # Bundle size analysis with visualization
|
|
|
278
281
|
- **ESM:** `dist/dauth-context-react.esm.js`
|
|
279
282
|
- **Types:** `dist/index.d.ts`
|
|
280
283
|
|
|
281
|
-
### CI
|
|
284
|
+
### CI/CD
|
|
282
285
|
|
|
283
|
-
GitHub Actions runs lint,
|
|
286
|
+
- **CI**: GitHub Actions runs lint, test, and build on push to `main` and PRs. Self-hosted runner, Node 22.
|
|
287
|
+
- **Publish**: Automated npm publish on `v*` tags via GitHub Actions.
|
|
284
288
|
|
|
285
289
|
## Author
|
|
286
290
|
|
|
@@ -1,48 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1
|
+
import React$1 from 'react';
|
|
2
|
+
|
|
3
|
+
interface IDauthUser {
|
|
4
|
+
_id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
lastname: string;
|
|
7
|
+
nickname: string;
|
|
8
|
+
email: string;
|
|
9
|
+
isVerified: boolean;
|
|
10
|
+
language: string;
|
|
11
|
+
avatar: {
|
|
12
|
+
id: string;
|
|
13
|
+
url: string;
|
|
14
|
+
};
|
|
15
|
+
role: string;
|
|
16
|
+
telPrefix: string;
|
|
17
|
+
telSuffix: string;
|
|
18
|
+
birthDate?: Date;
|
|
19
|
+
country?: string;
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
lastLogin: Date;
|
|
24
|
+
}
|
|
25
|
+
interface IDauthDomainState {
|
|
26
|
+
name: string;
|
|
27
|
+
loginRedirect: string;
|
|
28
|
+
allowedOrigins: string[];
|
|
29
|
+
}
|
|
30
|
+
interface IDauthState {
|
|
31
|
+
user: IDauthUser;
|
|
32
|
+
domain: IDauthDomainState;
|
|
33
|
+
isLoading: boolean;
|
|
34
|
+
isAuthenticated: boolean;
|
|
35
|
+
loginWithRedirect: () => void;
|
|
36
|
+
logout: () => void;
|
|
37
|
+
getAccessToken: () => Promise<string>;
|
|
38
|
+
updateUser: (fields: Partial<IDauthUser>) => Promise<boolean>;
|
|
39
|
+
updateUserWithRedirect: () => void;
|
|
40
|
+
sendEmailVerificationStatus: {
|
|
41
|
+
status: IActionStatus;
|
|
42
|
+
isLoading: boolean;
|
|
43
|
+
};
|
|
44
|
+
sendEmailVerification: () => Promise<boolean>;
|
|
45
|
+
deleteAccount: () => Promise<boolean>;
|
|
46
|
+
}
|
|
47
|
+
interface IActionStatus {
|
|
48
|
+
type: TStatusTypes;
|
|
49
|
+
message: string;
|
|
50
|
+
}
|
|
51
|
+
type TStatusTypes = 'success' | 'error' | 'info' | 'warning';
|
|
52
|
+
interface IDauthProviderProps {
|
|
53
|
+
domainName: string;
|
|
54
|
+
children: React.ReactNode;
|
|
55
|
+
storageKey?: {
|
|
56
|
+
accessToken?: string;
|
|
57
|
+
refreshToken?: string;
|
|
58
|
+
};
|
|
59
|
+
onError?: (error: Error) => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare const DauthProvider: React$1.FC<IDauthProviderProps>;
|
|
63
|
+
declare const useDauth: () => IDauthState;
|
|
64
|
+
|
|
65
|
+
export { DauthProvider, type IDauthProviderProps, useDauth };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,65 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import React$1 from 'react';
|
|
2
|
+
|
|
3
|
+
interface IDauthUser {
|
|
4
|
+
_id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
lastname: string;
|
|
7
|
+
nickname: string;
|
|
8
|
+
email: string;
|
|
9
|
+
isVerified: boolean;
|
|
10
|
+
language: string;
|
|
11
|
+
avatar: {
|
|
12
|
+
id: string;
|
|
13
|
+
url: string;
|
|
14
|
+
};
|
|
15
|
+
role: string;
|
|
16
|
+
telPrefix: string;
|
|
17
|
+
telSuffix: string;
|
|
18
|
+
birthDate?: Date;
|
|
19
|
+
country?: string;
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
lastLogin: Date;
|
|
24
|
+
}
|
|
25
|
+
interface IDauthDomainState {
|
|
26
|
+
name: string;
|
|
27
|
+
loginRedirect: string;
|
|
28
|
+
allowedOrigins: string[];
|
|
29
|
+
}
|
|
30
|
+
interface IDauthState {
|
|
31
|
+
user: IDauthUser;
|
|
32
|
+
domain: IDauthDomainState;
|
|
33
|
+
isLoading: boolean;
|
|
34
|
+
isAuthenticated: boolean;
|
|
35
|
+
loginWithRedirect: () => void;
|
|
36
|
+
logout: () => void;
|
|
37
|
+
getAccessToken: () => Promise<string>;
|
|
38
|
+
updateUser: (fields: Partial<IDauthUser>) => Promise<boolean>;
|
|
39
|
+
updateUserWithRedirect: () => void;
|
|
40
|
+
sendEmailVerificationStatus: {
|
|
41
|
+
status: IActionStatus;
|
|
42
|
+
isLoading: boolean;
|
|
43
|
+
};
|
|
44
|
+
sendEmailVerification: () => Promise<boolean>;
|
|
45
|
+
deleteAccount: () => Promise<boolean>;
|
|
46
|
+
}
|
|
47
|
+
interface IActionStatus {
|
|
48
|
+
type: TStatusTypes;
|
|
49
|
+
message: string;
|
|
50
|
+
}
|
|
51
|
+
type TStatusTypes = 'success' | 'error' | 'info' | 'warning';
|
|
52
|
+
interface IDauthProviderProps {
|
|
53
|
+
domainName: string;
|
|
54
|
+
children: React.ReactNode;
|
|
55
|
+
storageKey?: {
|
|
56
|
+
accessToken?: string;
|
|
57
|
+
refreshToken?: string;
|
|
58
|
+
};
|
|
59
|
+
onError?: (error: Error) => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare const DauthProvider: React$1.FC<IDauthProviderProps>;
|
|
63
|
+
declare const useDauth: () => IDauthState;
|
|
64
|
+
|
|
65
|
+
export { DauthProvider, type IDauthProviderProps, useDauth };
|