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 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 verification:** Runs a 5-minute interval to verify the stored token is still valid against the DAuth backend.
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://<domainName>.dauth.ovh` in production.
262
- 4. **Token storage:** Tokens are stored in localStorage under the key `dauth_state`.
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
- npm start # Watch mode (tsdx watch)
268
- npm run build # Production build (CJS + ESM)
269
- npm test # Run Jest tests
270
- npm run lint # ESLint via tsdx
271
- npm run size # Check bundle size (10KB budget per entry)
272
- npm run analyze # Bundle size analysis with visualization
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, tests with coverage, and build across Node 20.x on Ubuntu, Windows, and macOS.
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
- export interface IDauthUser {
2
- _id: string;
3
- name: string;
4
- lastname: string;
5
- nickname: string;
6
- email: string;
7
- isVerified: boolean;
8
- language: string;
9
- avatar: {
10
- id: string;
11
- url: string;
12
- };
13
- role: string;
14
- telPrefix: string;
15
- telSuffix: string;
16
- birthDate?: Date;
17
- country?: string;
18
- metadata?: Record<string, unknown>;
19
- createdAt: Date;
20
- updatedAt: Date;
21
- lastLogin: Date;
22
- }
23
- export interface IDauthDomainState {
24
- name: string;
25
- loginRedirect: string;
26
- allowedOrigins: string[];
27
- }
28
- export interface IDauthState {
29
- user: IDauthUser;
30
- domain: IDauthDomainState;
31
- isLoading: boolean;
32
- isAuthenticated: boolean;
33
- loginWithRedirect: () => void;
34
- logout: () => void;
35
- getAccessToken: () => Promise<string>;
36
- updateUser: (fields: Partial<IDauthUser>) => Promise<boolean>;
37
- updateUserWithRedirect: () => void;
38
- sendEmailVerificationStatus: {
39
- status: IActionStatus;
40
- isLoading: boolean;
41
- };
42
- sendEmailVerification: () => Promise<boolean>;
43
- }
44
- export interface IActionStatus {
45
- type: TStatusTypes;
46
- message: string;
47
- }
48
- export declare type TStatusTypes = 'success' | 'error' | 'info' | 'warning';
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
- interface DauthProviderProps {
3
- domainName: string;
4
- children: React.ReactNode;
5
- }
6
- export declare const DauthProvider: React.FC<DauthProviderProps>;
7
- export declare const useDauth: () => import("./interfaces").IDauthState;
8
- export {};
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 };