dauth-context-react 2.2.0 → 2.4.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
@@ -1,6 +1,6 @@
1
1
  # dauth-context-react
2
2
 
3
- React context provider and hook for token-based authentication with the [DAuth](https://dauth.ovh) service. Provides `DauthProvider` and `useDauth()` hook for seamless integration of DAuth tenant authentication into React applications.
3
+ React context provider and hook for token-based authentication with the [Dauth](https://dauth.ovh) service. Provides `DauthProvider` and `useDauth()` hook for seamless integration of Dauth tenant authentication into React applications.
4
4
 
5
5
  ## Installation
6
6
 
@@ -71,7 +71,7 @@ function MyComponent() {
71
71
 
72
72
  | Prop | Type | Description |
73
73
  |---|---|---|
74
- | `domainName` | `string` | Your DAuth domain name (used for API routing and tenant resolution) |
74
+ | `domainName` | `string` | Your Dauth domain name (used for API routing and tenant resolution) |
75
75
  | `tsk` | `string` | Tenant Secret Key for JWT verification |
76
76
  | `children` | `React.ReactNode` | Child components |
77
77
 
@@ -85,11 +85,11 @@ Returns the current authentication state and action methods:
85
85
  | `domain` | `IDauthDomainState` | Domain configuration (name, loginRedirect, allowedOrigins) |
86
86
  | `isLoading` | `boolean` | `true` while initial auth check is in progress |
87
87
  | `isAuthenticated` | `boolean` | `true` if user is authenticated |
88
- | `loginWithRedirect` | `() => void` | Redirects to the DAuth tenant sign-in page |
88
+ | `loginWithRedirect` | `() => void` | Redirects to the Dauth tenant sign-in page |
89
89
  | `logout` | `() => void` | Clears token and resets auth state |
90
90
  | `getAccessToken` | `() => Promise<string>` | Returns a fresh access token (refreshes if needed) |
91
91
  | `updateUser` | `(fields: Partial<IDauthUser>) => Promise<boolean>` | Updates user profile fields |
92
- | `updateUserWithRedirect` | `() => void` | Redirects to the DAuth user update page |
92
+ | `updateUserWithRedirect` | `() => void` | Redirects to the Dauth user update page |
93
93
  | `sendEmailVerification` | `() => Promise<boolean>` | Sends a verification email to the user |
94
94
  | `sendEmailVerificationStatus` | `{ status: IActionStatus, isLoading: boolean }` | Status of the email verification request |
95
95
 
@@ -119,7 +119,7 @@ interface IDauthUser {
119
119
 
120
120
  ## Real-World Integration Example
121
121
 
122
- This is the pattern used in `easymediacloud-frontend-react`, which delegates all user authentication to dauth.
122
+ This is the pattern used in `easymediacloud-frontend-react`, which delegates all user authentication to Dauth.
123
123
 
124
124
  ### 1. Provider hierarchy in `App.tsx`
125
125
 
@@ -1,49 +1,71 @@
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
- deleteAccount: () => Promise<boolean>;
44
- }
45
- export interface IActionStatus {
46
- type: TStatusTypes;
47
- message: string;
48
- }
49
- 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 IDauthDomainEnvironment {
26
+ name: string;
27
+ loginRedirect: string;
28
+ }
29
+ interface IDauthDomainState {
30
+ name: string;
31
+ environments?: IDauthDomainEnvironment[];
32
+ loginRedirect: string;
33
+ allowedOrigins: string[];
34
+ }
35
+ interface IDauthState {
36
+ user: IDauthUser;
37
+ domain: IDauthDomainState;
38
+ isLoading: boolean;
39
+ isAuthenticated: boolean;
40
+ loginWithRedirect: () => void;
41
+ logout: () => void;
42
+ getAccessToken: () => Promise<string>;
43
+ updateUser: (fields: Partial<IDauthUser>) => Promise<boolean>;
44
+ updateUserWithRedirect: () => void;
45
+ sendEmailVerificationStatus: {
46
+ status: IActionStatus;
47
+ isLoading: boolean;
48
+ };
49
+ sendEmailVerification: () => Promise<boolean>;
50
+ deleteAccount: () => Promise<boolean>;
51
+ }
52
+ interface IActionStatus {
53
+ type: TStatusTypes;
54
+ message: string;
55
+ }
56
+ type TStatusTypes = 'success' | 'error' | 'info' | 'warning';
57
+ interface IDauthProviderProps {
58
+ domainName: string;
59
+ children: React.ReactNode;
60
+ storageKey?: {
61
+ accessToken?: string;
62
+ refreshToken?: string;
63
+ };
64
+ onError?: (error: Error) => void;
65
+ env?: string;
66
+ }
67
+
68
+ declare const DauthProvider: React$1.FC<IDauthProviderProps>;
69
+ declare const useDauth: () => IDauthState;
70
+
71
+ export { DauthProvider, type IDauthProviderProps, useDauth };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,71 @@
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 IDauthDomainEnvironment {
26
+ name: string;
27
+ loginRedirect: string;
28
+ }
29
+ interface IDauthDomainState {
30
+ name: string;
31
+ environments?: IDauthDomainEnvironment[];
32
+ loginRedirect: string;
33
+ allowedOrigins: string[];
34
+ }
35
+ interface IDauthState {
36
+ user: IDauthUser;
37
+ domain: IDauthDomainState;
38
+ isLoading: boolean;
39
+ isAuthenticated: boolean;
40
+ loginWithRedirect: () => void;
41
+ logout: () => void;
42
+ getAccessToken: () => Promise<string>;
43
+ updateUser: (fields: Partial<IDauthUser>) => Promise<boolean>;
44
+ updateUserWithRedirect: () => void;
45
+ sendEmailVerificationStatus: {
46
+ status: IActionStatus;
47
+ isLoading: boolean;
48
+ };
49
+ sendEmailVerification: () => Promise<boolean>;
50
+ deleteAccount: () => Promise<boolean>;
51
+ }
52
+ interface IActionStatus {
53
+ type: TStatusTypes;
54
+ message: string;
55
+ }
56
+ type TStatusTypes = 'success' | 'error' | 'info' | 'warning';
57
+ interface IDauthProviderProps {
58
+ domainName: string;
59
+ children: React.ReactNode;
60
+ storageKey?: {
61
+ accessToken?: string;
62
+ refreshToken?: string;
63
+ };
64
+ onError?: (error: Error) => void;
65
+ env?: string;
66
+ }
67
+
68
+ declare const DauthProvider: React$1.FC<IDauthProviderProps>;
69
+ declare const useDauth: () => IDauthState;
70
+
71
+ export { DauthProvider, type IDauthProviderProps, useDauth };