@ttoss/react-auth 2.6.5 → 2.6.7

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/esm/index.js CHANGED
@@ -521,33 +521,38 @@ var AuthContext = React3.createContext({
521
521
  signOut,
522
522
  isAuthenticated: false,
523
523
  user: null,
524
- tokens: null
524
+ tokens: null,
525
+ screen: {
526
+ value: "signIn",
527
+ context: {}
528
+ },
529
+ setScreen: () => {}
525
530
  });
526
531
  var AuthProvider = ({
527
532
  children
528
533
  }) => {
529
- const [{
530
- user,
531
- tokens,
532
- isAuthenticated
533
- }, setAuthState] = React3.useState({
534
+ const [authState, setAuthState] = React3.useState({
534
535
  user: null,
535
536
  tokens: null,
536
537
  isAuthenticated: void 0
537
538
  });
539
+ const [screen, setScreen] = React3.useState({
540
+ value: "signIn",
541
+ context: {}
542
+ });
538
543
  React3.useEffect(() => {
539
544
  const updateUser = () => {
540
545
  getCurrentUser().then(async ({
541
546
  userId
542
547
  }) => {
543
- const [session, user2] = await Promise.all([fetchAuthSession(), fetchUserAttributes()]);
548
+ const [session, user] = await Promise.all([fetchAuthSession(), fetchUserAttributes()]);
544
549
  const idToken = session.tokens?.idToken?.toString() ?? "";
545
550
  const accessToken = session.tokens?.accessToken.toString() ?? "";
546
551
  setAuthState({
547
552
  user: {
548
553
  id: userId,
549
- email: user2.email ?? "",
550
- emailVerified: user2.email_verified ?? ""
554
+ email: user.email ?? "",
555
+ emailVerified: user.email_verified ?? ""
551
556
  },
552
557
  tokens: {
553
558
  idToken,
@@ -556,8 +561,7 @@ var AuthProvider = ({
556
561
  },
557
562
  isAuthenticated: true
558
563
  });
559
- }).catch(e => {
560
- console.error(e);
564
+ }).catch(() => {
561
565
  setAuthState({
562
566
  user: null,
563
567
  tokens: null,
@@ -571,15 +575,17 @@ var AuthProvider = ({
571
575
  updateUserListener();
572
576
  };
573
577
  }, []);
574
- if (isAuthenticated === void 0) {
578
+ if (authState.isAuthenticated === void 0) {
575
579
  return null;
576
580
  }
577
581
  return /* @__PURE__ */jsx7(AuthContext.Provider, {
578
582
  value: {
579
583
  signOut,
580
- isAuthenticated,
581
- user,
582
- tokens
584
+ isAuthenticated: authState.isAuthenticated ?? false,
585
+ user: authState.user,
586
+ tokens: authState.tokens,
587
+ screen,
588
+ setScreen
583
589
  },
584
590
  children
585
591
  });
@@ -937,12 +943,10 @@ var AuthLogic = props => {
937
943
  intl
938
944
  } = useI18n7();
939
945
  const {
940
- isAuthenticated
946
+ isAuthenticated,
947
+ screen,
948
+ setScreen
941
949
  } = useAuth();
942
- const [screen, setScreen] = React5.useState({
943
- value: "signIn",
944
- context: {}
945
- });
946
950
  const {
947
951
  setLoading,
948
952
  addNotification,
@@ -1000,7 +1004,7 @@ var AuthLogic = props => {
1000
1004
  } finally {
1001
1005
  setLoading(false);
1002
1006
  }
1003
- }, [addNotification, intl, setLoading]);
1007
+ }, [addNotification, intl, setLoading, setScreen]);
1004
1008
  const onSignUp = React5.useCallback(async ({
1005
1009
  email,
1006
1010
  password
@@ -1030,7 +1034,7 @@ var AuthLogic = props => {
1030
1034
  } finally {
1031
1035
  setLoading(false);
1032
1036
  }
1033
- }, [setLoading, addNotification]);
1037
+ }, [setLoading, setScreen, addNotification]);
1034
1038
  const onConfirmSignUp = React5.useCallback(async ({
1035
1039
  email,
1036
1040
  code
@@ -1055,13 +1059,13 @@ var AuthLogic = props => {
1055
1059
  } finally {
1056
1060
  setLoading(false);
1057
1061
  }
1058
- }, [setLoading, addNotification]);
1062
+ }, [setLoading, setScreen, addNotification]);
1059
1063
  const onReturnToSignIn = React5.useCallback(() => {
1060
1064
  setScreen({
1061
1065
  value: "signIn",
1062
1066
  context: {}
1063
1067
  });
1064
- }, []);
1068
+ }, [setScreen]);
1065
1069
  const onForgotPassword = React5.useCallback(async ({
1066
1070
  email
1067
1071
  }) => {
@@ -1084,7 +1088,7 @@ var AuthLogic = props => {
1084
1088
  } finally {
1085
1089
  setLoading(false);
1086
1090
  }
1087
- }, [setLoading, addNotification]);
1091
+ }, [setLoading, setScreen, addNotification]);
1088
1092
  const onForgotPasswordResetPassword = React5.useCallback(async ({
1089
1093
  email,
1090
1094
  code,
@@ -1111,7 +1115,7 @@ var AuthLogic = props => {
1111
1115
  } finally {
1112
1116
  setLoading(false);
1113
1117
  }
1114
- }, [setLoading, addNotification]);
1118
+ }, [setLoading, setScreen, addNotification]);
1115
1119
  if (isAuthenticated) {
1116
1120
  return null;
1117
1121
  }
package/dist/index.d.ts CHANGED
@@ -66,6 +66,33 @@ type Tokens = {
66
66
  accessToken: string;
67
67
  refreshToken: string;
68
68
  } | null;
69
+ type AuthScreen = {
70
+ value: 'signIn';
71
+ context: {
72
+ email?: string;
73
+ };
74
+ } | {
75
+ value: 'signUp';
76
+ context: Record<string, never>;
77
+ } | {
78
+ value: 'signUpConfirm';
79
+ context: {
80
+ email: string;
81
+ };
82
+ } | {
83
+ value: 'signUpResendConfirmation';
84
+ context: {
85
+ email: string;
86
+ };
87
+ } | {
88
+ value: 'forgotPassword';
89
+ context: Record<string, never>;
90
+ } | {
91
+ value: 'forgotPasswordResetPassword';
92
+ context: {
93
+ email: string;
94
+ };
95
+ };
69
96
  declare const AuthProvider: ({ children }: {
70
97
  children: React.ReactNode;
71
98
  }) => react_jsx_runtime.JSX.Element | null;
@@ -74,6 +101,8 @@ declare const useAuth: () => {
74
101
  isAuthenticated: boolean;
75
102
  user: User;
76
103
  tokens: Tokens;
104
+ screen: AuthScreen;
105
+ setScreen: React.Dispatch<React.SetStateAction<AuthScreen>>;
77
106
  };
78
107
 
79
108
  export { Auth, type AuthProps, AuthProvider, type OnConfirmSignUp, type OnForgotPassword, type OnForgotPasswordResetPassword, type OnSignIn, type OnSignInInput, type OnSignUp, type OnSignUpInput, useAuth };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/react-auth",
3
- "version": "2.6.5",
3
+ "version": "2.6.7",
4
4
  "description": "ttoss authentication module for React apps.",
5
5
  "license": "MIT",
6
6
  "author": "ttoss",
@@ -30,12 +30,12 @@
30
30
  "peerDependencies": {
31
31
  "aws-amplify": "^6.0.0",
32
32
  "react": ">=16.8.0",
33
- "@ttoss/components": "^2.2.10",
33
+ "@ttoss/components": "^2.2.11",
34
34
  "@ttoss/forms": "^0.29.9",
35
- "@ttoss/logger": "^0.6.1",
36
- "@ttoss/react-notifications": "^2.1.16",
37
35
  "@ttoss/react-i18n": "^2.0.11",
38
- "@ttoss/ui": "^5.5.6"
36
+ "@ttoss/ui": "^5.5.6",
37
+ "@ttoss/logger": "^0.6.1",
38
+ "@ttoss/react-notifications": "^2.1.17"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@jest/globals": "^29.7.0",
@@ -45,15 +45,15 @@
45
45
  "react": "^19.0.0",
46
46
  "tsup": "^8.3.5",
47
47
  "@ttoss/cloud-auth": "^0.12.28",
48
- "@ttoss/config": "^1.35.3",
48
+ "@ttoss/components": "^2.2.11",
49
49
  "@ttoss/forms": "^0.29.9",
50
- "@ttoss/components": "^2.2.10",
50
+ "@ttoss/config": "^1.35.3",
51
51
  "@ttoss/i18n-cli": "^0.7.28",
52
52
  "@ttoss/logger": "^0.6.1",
53
53
  "@ttoss/react-i18n": "^2.0.11",
54
+ "@ttoss/react-notifications": "^2.1.17",
54
55
  "@ttoss/test-utils": "^2.1.23",
55
- "@ttoss/ui": "^5.5.6",
56
- "@ttoss/react-notifications": "^2.1.16"
56
+ "@ttoss/ui": "^5.5.6"
57
57
  },
58
58
  "keywords": [
59
59
  "React",