dauth-context-react 2.4.0 → 3.0.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.
@@ -1,9 +1,4 @@
1
- import {
2
- IActionStatus,
3
- IDauthDomainState,
4
- IDauthState,
5
- IDauthUser,
6
- } from './interfaces';
1
+ import { IDauthDomainState, IDauthState, IDauthUser } from './interfaces';
7
2
 
8
3
  const initialDauthState: IDauthState = {
9
4
  user: {
@@ -20,15 +15,6 @@ const initialDauthState: IDauthState = {
20
15
  getAccessToken: () => Promise.resolve(''),
21
16
  updateUser: () => Promise.resolve(false),
22
17
  updateUserWithRedirect: () => {},
23
- // Send email verification
24
- sendEmailVerificationStatus: {
25
- status: {
26
- type: 'info',
27
- message: 'Sending email verification...',
28
- } as IActionStatus,
29
- isLoading: false,
30
- },
31
- sendEmailVerification: () => Promise.resolve(false),
32
18
  deleteAccount: () => Promise.resolve(false),
33
19
  };
34
20
 
package/src/interfaces.ts CHANGED
@@ -26,11 +26,17 @@ export interface IDauthDomainEnvironment {
26
26
  loginRedirect: string;
27
27
  }
28
28
 
29
+ export interface IDauthAuthMethods {
30
+ magicLink: boolean;
31
+ passkey: boolean;
32
+ }
33
+
29
34
  export interface IDauthDomainState {
30
35
  name: string;
31
36
  environments?: IDauthDomainEnvironment[];
32
37
  loginRedirect: string;
33
38
  allowedOrigins: string[];
39
+ authMethods?: IDauthAuthMethods;
34
40
  }
35
41
 
36
42
  export interface IDauthState {
@@ -43,12 +49,6 @@ export interface IDauthState {
43
49
  getAccessToken: () => Promise<string>;
44
50
  updateUser: (fields: Partial<IDauthUser>) => Promise<boolean>;
45
51
  updateUserWithRedirect: () => void;
46
- // Send email verification
47
- sendEmailVerificationStatus: {
48
- status: IActionStatus;
49
- isLoading: boolean;
50
- };
51
- sendEmailVerification: () => Promise<boolean>;
52
52
  deleteAccount: () => Promise<boolean>;
53
53
  }
54
54
 
@@ -72,4 +72,6 @@ export interface IDauthProviderProps {
72
72
  };
73
73
  onError?: (error: Error) => void;
74
74
  env?: string;
75
+ /** Override the dauth server URL (e.g. 'https://dev.dauth.ovh' for staging) */
76
+ dauthUrl?: string;
75
77
  }
@@ -3,7 +3,6 @@ import {
3
3
  getUserAPI,
4
4
  logoutAPI,
5
5
  refreshTokenAPI,
6
- sendEmailVerificationAPI,
7
6
  updateUserAPI,
8
7
  } from '../api/dauth.api';
9
8
  import {
@@ -207,64 +206,7 @@ export async function setUpdateUserAction({
207
206
  return false;
208
207
  }
209
208
  } catch (error) {
210
- onError(
211
- error instanceof Error ? error : new Error('Update user error')
212
- );
213
- return false;
214
- }
215
- }
216
-
217
- type TSetSendEmailVerificationAction = ActionContext & {
218
- token: string;
219
- };
220
- export async function sendEmailVerificationAction({
221
- dispatch,
222
- domainName,
223
- token,
224
- }: TSetSendEmailVerificationAction) {
225
- dispatch({
226
- type: DauthTypes.SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
227
- payload: true,
228
- });
229
- dispatch({
230
- type: DauthTypes.SET_SEND_EMAIL_VERIFICATION_STATUS,
231
- payload: { type: 'info', message: 'Sending email verification...' },
232
- });
233
- try {
234
- const sendEmailFetch = await sendEmailVerificationAPI(domainName, token);
235
- if (sendEmailFetch.response.status === 200) {
236
- dispatch({
237
- type: DauthTypes.SET_SEND_EMAIL_VERIFICATION_STATUS,
238
- payload: { type: 'success', message: sendEmailFetch.data.message },
239
- });
240
- dispatch({
241
- type: DauthTypes.SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
242
- payload: false,
243
- });
244
- return true;
245
- } else {
246
- dispatch({
247
- type: DauthTypes.SET_SEND_EMAIL_VERIFICATION_STATUS,
248
- payload: { type: 'error', message: sendEmailFetch.data.message },
249
- });
250
- dispatch({
251
- type: DauthTypes.SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
252
- payload: false,
253
- });
254
- return false;
255
- }
256
- } catch (_) {
257
- dispatch({
258
- type: DauthTypes.SET_SEND_EMAIL_VERIFICATION_STATUS,
259
- payload: {
260
- type: 'error',
261
- message: 'Send email verification fetch error',
262
- },
263
- });
264
- dispatch({
265
- type: DauthTypes.SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
266
- payload: false,
267
- });
209
+ onError(error instanceof Error ? error : new Error('Update user error'));
268
210
  return false;
269
211
  }
270
212
  }
@@ -316,9 +258,7 @@ export async function deleteAccountAction({
316
258
  }
317
259
  return false;
318
260
  } catch (error) {
319
- onError(
320
- error instanceof Error ? error : new Error('Delete account error')
321
- );
261
+ onError(error instanceof Error ? error : new Error('Delete account error'));
322
262
  return false;
323
263
  }
324
264
  }
@@ -34,31 +34,6 @@ export default function userReducer(state: IDauthState, action: any) {
34
34
  return updateUser;
35
35
  }
36
36
 
37
- case DauthTypes.SET_SEND_EMAIL_VERIFICATION_STATUS: {
38
- const setSendEmailVerificationStatus: IDauthState = {
39
- ...state,
40
- sendEmailVerificationStatus: {
41
- ...state.sendEmailVerificationStatus,
42
- status: {
43
- type: payload.type,
44
- message: payload.message,
45
- },
46
- },
47
- };
48
- return setSendEmailVerificationStatus;
49
- }
50
-
51
- case DauthTypes.SET_SEND_EMAIL_VERIFICATION_IS_LOADING: {
52
- const setSendEmailVerificationIsLoading: IDauthState = {
53
- ...state,
54
- sendEmailVerificationStatus: {
55
- ...state.sendEmailVerificationStatus,
56
- isLoading: payload,
57
- },
58
- };
59
- return setSendEmailVerificationIsLoading;
60
- }
61
-
62
37
  default:
63
38
  return state;
64
39
  }
@@ -1,7 +1,3 @@
1
1
  export const LOGIN = 'LOGIN';
2
2
  export const SET_IS_LOADING = 'SET_IS_LOADING';
3
3
  export const UPDATE_USER = 'UPDATE_USER';
4
- export const SET_SEND_EMAIL_VERIFICATION_IS_LOADING =
5
- 'SET_SEND_EMAIL_VERIFICATION_IS_LOADING';
6
- export const SET_SEND_EMAIL_VERIFICATION_STATUS =
7
- 'SET_SEND_EMAIL_VERIFICATION_STATUS';