@ttoss/react-auth-strapi 0.4.28 → 0.4.30
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/{index.js → index.cjs} +73 -98
- package/dist/index.d.cts +18 -18
- package/dist/index.d.mts +23 -0
- package/dist/{esm/index.js → index.mjs} +47 -56
- package/i18n/compiled/en.json +4 -4
- package/package.json +14 -14
- package/dist/index.d.ts +0 -23
|
@@ -1,75 +1,52 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
3
|
+
value: 'Module'
|
|
4
|
+
});
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
5
6
|
var __create = Object.create;
|
|
6
7
|
var __defProp = Object.defineProperty;
|
|
7
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
9
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
10
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __name = (target, value) => __defProp(target, "name", {
|
|
12
|
-
value,
|
|
13
|
-
configurable: true
|
|
14
|
-
});
|
|
15
|
-
var __export = (target, all) => {
|
|
16
|
-
for (var name in all) __defProp(target, name, {
|
|
17
|
-
get: all[name],
|
|
18
|
-
enumerable: true
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
12
|
var __copyProps = (to, from, except, desc) => {
|
|
22
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
-
for (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
17
|
+
__defProp(to, key, {
|
|
18
|
+
get: (k => from[k]).bind(null, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
27
23
|
}
|
|
28
24
|
return to;
|
|
29
25
|
};
|
|
30
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
31
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
32
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
33
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
34
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
35
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
36
27
|
value: mod,
|
|
37
28
|
enumerable: true
|
|
38
29
|
}) : target, mod));
|
|
39
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
40
|
-
value: true
|
|
41
|
-
}), mod);
|
|
42
|
-
|
|
43
|
-
// src/index.ts
|
|
44
|
-
var index_exports = {};
|
|
45
|
-
__export(index_exports, {
|
|
46
|
-
Auth: () => Auth,
|
|
47
|
-
AuthProvider: () => AuthProvider,
|
|
48
|
-
useAuth: () => useAuth
|
|
49
|
-
});
|
|
50
|
-
module.exports = __toCommonJS(index_exports);
|
|
51
|
-
|
|
52
|
-
// src/Auth.tsx
|
|
53
|
-
var import_react_auth_core2 = require("@ttoss/react-auth-core");
|
|
54
|
-
var import_react_notifications = require("@ttoss/react-notifications");
|
|
55
|
-
var React2 = __toESM(require("react"), 1);
|
|
56
30
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
31
|
+
//#endregion
|
|
32
|
+
let _ttoss_react_auth_core = require("@ttoss/react-auth-core");
|
|
33
|
+
let _ttoss_react_notifications = require("@ttoss/react-notifications");
|
|
34
|
+
let react = require("react");
|
|
35
|
+
react = __toESM(react);
|
|
36
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
60
37
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
38
|
+
//#region src/storage.ts
|
|
39
|
+
const AUTH_STORAGE_REFRESH_TOKEN_KEY = "ttoss-strapi-auth-refresh-token";
|
|
40
|
+
const isBrowser = typeof window !== "undefined";
|
|
41
|
+
const getLocalStorage = () => {
|
|
65
42
|
try {
|
|
66
43
|
return isBrowser ? window.localStorage : null;
|
|
67
44
|
} catch {
|
|
68
45
|
return null;
|
|
69
46
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
getRefreshToken:
|
|
47
|
+
};
|
|
48
|
+
const storage = {
|
|
49
|
+
getRefreshToken: () => {
|
|
73
50
|
const ls = getLocalStorage();
|
|
74
51
|
if (!ls) return null;
|
|
75
52
|
try {
|
|
@@ -77,35 +54,34 @@ var storage = {
|
|
|
77
54
|
} catch {
|
|
78
55
|
return null;
|
|
79
56
|
}
|
|
80
|
-
},
|
|
81
|
-
setRefreshToken:
|
|
57
|
+
},
|
|
58
|
+
setRefreshToken: refreshToken => {
|
|
82
59
|
const ls = getLocalStorage();
|
|
83
60
|
if (!ls) return;
|
|
84
61
|
try {
|
|
85
62
|
ls.setItem(AUTH_STORAGE_REFRESH_TOKEN_KEY, refreshToken);
|
|
86
63
|
} catch {}
|
|
87
|
-
},
|
|
88
|
-
clearRefreshToken:
|
|
64
|
+
},
|
|
65
|
+
clearRefreshToken: () => {
|
|
89
66
|
const ls = getLocalStorage();
|
|
90
67
|
if (!ls) return;
|
|
91
68
|
try {
|
|
92
69
|
ls.removeItem(AUTH_STORAGE_REFRESH_TOKEN_KEY);
|
|
93
70
|
} catch {}
|
|
94
|
-
}
|
|
71
|
+
}
|
|
95
72
|
};
|
|
96
73
|
|
|
97
|
-
|
|
98
|
-
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/AuthProvider.tsx
|
|
76
|
+
const AuthContext = react.createContext({
|
|
99
77
|
apiUrl: ""
|
|
100
78
|
});
|
|
101
|
-
|
|
102
|
-
const getAuthData =
|
|
79
|
+
const AuthProvider = props => {
|
|
80
|
+
const getAuthData = react.useCallback(async () => {
|
|
103
81
|
try {
|
|
104
82
|
const refreshToken = storage.getRefreshToken();
|
|
105
|
-
if (!refreshToken)
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
const refreshResponse = await fetch(`${props.apiUrl}/auth/local/refresh`, {
|
|
83
|
+
if (!refreshToken) return null;
|
|
84
|
+
const refreshData = await (await fetch(`${props.apiUrl}/auth/local/refresh`, {
|
|
109
85
|
method: "POST",
|
|
110
86
|
headers: {
|
|
111
87
|
"Content-Type": "application/json"
|
|
@@ -113,8 +89,7 @@ var AuthProvider = /* @__PURE__ */__name(props => {
|
|
|
113
89
|
body: JSON.stringify({
|
|
114
90
|
refreshToken
|
|
115
91
|
})
|
|
116
|
-
});
|
|
117
|
-
const refreshData = await refreshResponse.json();
|
|
92
|
+
})).json();
|
|
118
93
|
if ("error" in refreshData) {
|
|
119
94
|
storage.clearRefreshToken();
|
|
120
95
|
return null;
|
|
@@ -147,31 +122,34 @@ var AuthProvider = /* @__PURE__ */__name(props => {
|
|
|
147
122
|
return null;
|
|
148
123
|
}
|
|
149
124
|
}, [props.apiUrl]);
|
|
150
|
-
const signOut =
|
|
125
|
+
const signOut = react.useCallback(async () => {
|
|
151
126
|
storage.clearRefreshToken();
|
|
152
127
|
}, []);
|
|
153
|
-
return /* @__PURE__ */
|
|
128
|
+
return /* @__PURE__ */(0, react_jsx_runtime.jsx)(AuthContext.Provider, {
|
|
154
129
|
value: {
|
|
155
130
|
apiUrl: props.apiUrl
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
131
|
+
},
|
|
132
|
+
children: /* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_react_auth_core.AuthProvider, {
|
|
133
|
+
getAuthData,
|
|
134
|
+
signOut,
|
|
135
|
+
children: props.children
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
const useAuth = () => {
|
|
140
|
+
const authCore = (0, _ttoss_react_auth_core.useAuth)();
|
|
164
141
|
const {
|
|
165
142
|
apiUrl
|
|
166
|
-
} =
|
|
143
|
+
} = react.useContext(AuthContext);
|
|
167
144
|
return {
|
|
168
145
|
apiUrl,
|
|
169
146
|
...authCore
|
|
170
147
|
};
|
|
171
|
-
}
|
|
148
|
+
};
|
|
172
149
|
|
|
173
|
-
|
|
174
|
-
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/Auth.tsx
|
|
152
|
+
const Auth = props => {
|
|
175
153
|
const {
|
|
176
154
|
setAuthData,
|
|
177
155
|
apiUrl
|
|
@@ -179,11 +157,11 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
179
157
|
const {
|
|
180
158
|
screen,
|
|
181
159
|
setScreen
|
|
182
|
-
} = (0,
|
|
160
|
+
} = (0, _ttoss_react_auth_core.useAuthScreen)(props.initialScreen);
|
|
183
161
|
const {
|
|
184
162
|
addNotification
|
|
185
|
-
} = (0,
|
|
186
|
-
const onSignIn =
|
|
163
|
+
} = (0, _ttoss_react_notifications.useNotifications)();
|
|
164
|
+
const onSignIn = react.useCallback(async ({
|
|
187
165
|
email,
|
|
188
166
|
password
|
|
189
167
|
}) => {
|
|
@@ -200,8 +178,7 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
200
178
|
});
|
|
201
179
|
const data = await response.json();
|
|
202
180
|
if (!response.ok) {
|
|
203
|
-
|
|
204
|
-
if (errorMessage === "Your account email is not confirmed") {
|
|
181
|
+
if (data.error?.message === "Your account email is not confirmed") {
|
|
205
182
|
const resendResponse = await fetch(`${apiUrl}/auth/send-email-confirmation`, {
|
|
206
183
|
method: "POST",
|
|
207
184
|
headers: {
|
|
@@ -212,10 +189,9 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
212
189
|
})
|
|
213
190
|
});
|
|
214
191
|
if (!resendResponse.ok) {
|
|
215
|
-
const resendData = await resendResponse.json();
|
|
216
192
|
addNotification({
|
|
217
193
|
title: "Resend confirmation email failed",
|
|
218
|
-
message:
|
|
194
|
+
message: (await resendResponse.json()).error?.message || "An error occurred while resending the confirmation email.",
|
|
219
195
|
type: "error"
|
|
220
196
|
});
|
|
221
197
|
return;
|
|
@@ -253,7 +229,7 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
253
229
|
});
|
|
254
230
|
}
|
|
255
231
|
}, [setAuthData, setScreen, addNotification, apiUrl]);
|
|
256
|
-
const onSignUp =
|
|
232
|
+
const onSignUp = react.useCallback(async ({
|
|
257
233
|
email,
|
|
258
234
|
password
|
|
259
235
|
}) => {
|
|
@@ -289,7 +265,7 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
289
265
|
});
|
|
290
266
|
}
|
|
291
267
|
}, [addNotification, setScreen, apiUrl]);
|
|
292
|
-
const onForgotPassword =
|
|
268
|
+
const onForgotPassword = react.useCallback(async ({
|
|
293
269
|
email
|
|
294
270
|
}) => {
|
|
295
271
|
try {
|
|
@@ -325,7 +301,7 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
325
301
|
});
|
|
326
302
|
}
|
|
327
303
|
}, [addNotification, setScreen, apiUrl]);
|
|
328
|
-
const onForgotPasswordResetPassword =
|
|
304
|
+
const onForgotPasswordResetPassword = react.useCallback(async ({
|
|
329
305
|
email: _email,
|
|
330
306
|
code,
|
|
331
307
|
newPassword
|
|
@@ -367,12 +343,12 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
367
343
|
});
|
|
368
344
|
}
|
|
369
345
|
}, [addNotification, setScreen, apiUrl]);
|
|
370
|
-
const onConfirmSignUpCheckEmail =
|
|
346
|
+
const onConfirmSignUpCheckEmail = react.useCallback(async () => {
|
|
371
347
|
setScreen({
|
|
372
348
|
value: "signIn"
|
|
373
349
|
});
|
|
374
350
|
}, [setScreen]);
|
|
375
|
-
return /* @__PURE__ */
|
|
351
|
+
return /* @__PURE__ */(0, react_jsx_runtime.jsx)(_ttoss_react_auth_core.Auth, {
|
|
376
352
|
logo: props.logo,
|
|
377
353
|
layout: props.layout,
|
|
378
354
|
screen,
|
|
@@ -383,10 +359,9 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
383
359
|
onForgotPasswordResetPassword,
|
|
384
360
|
onConfirmSignUpCheckEmail
|
|
385
361
|
});
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
});
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
//#endregion
|
|
365
|
+
exports.Auth = Auth;
|
|
366
|
+
exports.AuthProvider = AuthProvider;
|
|
367
|
+
exports.useAuth = useAuth;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as _ttoss_react_auth_core from '@ttoss/react-auth-core';
|
|
3
|
-
import { AuthProps, AuthScreen } from '@ttoss/react-auth-core';
|
|
4
|
-
export { AuthScreen } from '@ttoss/react-auth-core';
|
|
5
|
-
import * as React from 'react';
|
|
6
1
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) => react_jsx_runtime.JSX.Element;
|
|
2
|
+
import { AuthProps, AuthScreen } from "@ttoss/react-auth-core";
|
|
3
|
+
import * as React from "react";
|
|
10
4
|
|
|
5
|
+
//#region src/Auth.d.ts
|
|
6
|
+
declare const Auth: (props: Pick<AuthProps, "logo" | "layout"> & {
|
|
7
|
+
initialScreen?: AuthScreen;
|
|
8
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/AuthProvider.d.ts
|
|
11
11
|
declare const AuthProvider: (props: React.PropsWithChildren<{
|
|
12
|
-
|
|
13
|
-
}>) =>
|
|
12
|
+
apiUrl: string;
|
|
13
|
+
}>) => import("react/jsx-runtime").JSX.Element;
|
|
14
14
|
declare const useAuth: () => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
signOut: () => Promise<void>;
|
|
16
|
+
isAuthenticated: boolean;
|
|
17
|
+
user: import("@ttoss/react-auth-core").AuthUser | null;
|
|
18
|
+
tokens: import("@ttoss/react-auth-core").AuthTokens | null;
|
|
19
|
+
setAuthData: React.Dispatch<React.SetStateAction<import("@ttoss/react-auth-core").AuthData>>;
|
|
20
|
+
apiUrl: string;
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
export { Auth, AuthProvider, useAuth };
|
|
22
|
+
//#endregion
|
|
23
|
+
export { Auth, AuthProvider, type AuthScreen, useAuth };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
import { AuthProps, AuthScreen } from "@ttoss/react-auth-core";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/Auth.d.ts
|
|
6
|
+
declare const Auth: (props: Pick<AuthProps, "logo" | "layout"> & {
|
|
7
|
+
initialScreen?: AuthScreen;
|
|
8
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/AuthProvider.d.ts
|
|
11
|
+
declare const AuthProvider: (props: React.PropsWithChildren<{
|
|
12
|
+
apiUrl: string;
|
|
13
|
+
}>) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
declare const useAuth: () => {
|
|
15
|
+
signOut: () => Promise<void>;
|
|
16
|
+
isAuthenticated: boolean;
|
|
17
|
+
user: import("@ttoss/react-auth-core").AuthUser | null;
|
|
18
|
+
tokens: import("@ttoss/react-auth-core").AuthTokens | null;
|
|
19
|
+
setAuthData: React.Dispatch<React.SetStateAction<import("@ttoss/react-auth-core").AuthData>>;
|
|
20
|
+
apiUrl: string;
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { Auth, AuthProvider, type AuthScreen, useAuth };
|
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
|
|
3
|
-
var __name = (target, value) => __defProp(target, "name", {
|
|
4
|
-
value,
|
|
5
|
-
configurable: true
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/Auth.tsx
|
|
9
|
-
import { Auth as AuthCore, useAuthScreen } from "@ttoss/react-auth-core";
|
|
2
|
+
import { Auth as Auth$1, AuthProvider as AuthProvider$1, useAuth as useAuth$1, useAuthScreen } from "@ttoss/react-auth-core";
|
|
10
3
|
import { useNotifications } from "@ttoss/react-notifications";
|
|
11
|
-
import * as React2 from "react";
|
|
12
|
-
|
|
13
|
-
// src/AuthProvider.tsx
|
|
14
|
-
import { AuthProvider as AuthProviderCore, useAuth as useAuthCore } from "@ttoss/react-auth-core";
|
|
15
4
|
import * as React from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
16
6
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
//#region src/storage.ts
|
|
8
|
+
const AUTH_STORAGE_REFRESH_TOKEN_KEY = "ttoss-strapi-auth-refresh-token";
|
|
9
|
+
const isBrowser = typeof window !== "undefined";
|
|
10
|
+
const getLocalStorage = () => {
|
|
21
11
|
try {
|
|
22
12
|
return isBrowser ? window.localStorage : null;
|
|
23
13
|
} catch {
|
|
24
14
|
return null;
|
|
25
15
|
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getRefreshToken:
|
|
16
|
+
};
|
|
17
|
+
const storage = {
|
|
18
|
+
getRefreshToken: () => {
|
|
29
19
|
const ls = getLocalStorage();
|
|
30
20
|
if (!ls) return null;
|
|
31
21
|
try {
|
|
@@ -33,35 +23,34 @@ var storage = {
|
|
|
33
23
|
} catch {
|
|
34
24
|
return null;
|
|
35
25
|
}
|
|
36
|
-
},
|
|
37
|
-
setRefreshToken:
|
|
26
|
+
},
|
|
27
|
+
setRefreshToken: refreshToken => {
|
|
38
28
|
const ls = getLocalStorage();
|
|
39
29
|
if (!ls) return;
|
|
40
30
|
try {
|
|
41
31
|
ls.setItem(AUTH_STORAGE_REFRESH_TOKEN_KEY, refreshToken);
|
|
42
32
|
} catch {}
|
|
43
|
-
},
|
|
44
|
-
clearRefreshToken:
|
|
33
|
+
},
|
|
34
|
+
clearRefreshToken: () => {
|
|
45
35
|
const ls = getLocalStorage();
|
|
46
36
|
if (!ls) return;
|
|
47
37
|
try {
|
|
48
38
|
ls.removeItem(AUTH_STORAGE_REFRESH_TOKEN_KEY);
|
|
49
39
|
} catch {}
|
|
50
|
-
}
|
|
40
|
+
}
|
|
51
41
|
};
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/AuthProvider.tsx
|
|
45
|
+
const AuthContext = React.createContext({
|
|
55
46
|
apiUrl: ""
|
|
56
47
|
});
|
|
57
|
-
|
|
48
|
+
const AuthProvider = props => {
|
|
58
49
|
const getAuthData = React.useCallback(async () => {
|
|
59
50
|
try {
|
|
60
51
|
const refreshToken = storage.getRefreshToken();
|
|
61
|
-
if (!refreshToken)
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
const refreshResponse = await fetch(`${props.apiUrl}/auth/local/refresh`, {
|
|
52
|
+
if (!refreshToken) return null;
|
|
53
|
+
const refreshData = await (await fetch(`${props.apiUrl}/auth/local/refresh`, {
|
|
65
54
|
method: "POST",
|
|
66
55
|
headers: {
|
|
67
56
|
"Content-Type": "application/json"
|
|
@@ -69,8 +58,7 @@ var AuthProvider = /* @__PURE__ */__name(props => {
|
|
|
69
58
|
body: JSON.stringify({
|
|
70
59
|
refreshToken
|
|
71
60
|
})
|
|
72
|
-
});
|
|
73
|
-
const refreshData = await refreshResponse.json();
|
|
61
|
+
})).json();
|
|
74
62
|
if ("error" in refreshData) {
|
|
75
63
|
storage.clearRefreshToken();
|
|
76
64
|
return null;
|
|
@@ -106,17 +94,19 @@ var AuthProvider = /* @__PURE__ */__name(props => {
|
|
|
106
94
|
const signOut = React.useCallback(async () => {
|
|
107
95
|
storage.clearRefreshToken();
|
|
108
96
|
}, []);
|
|
109
|
-
return /* @__PURE__ */
|
|
97
|
+
return /* @__PURE__ */jsx(AuthContext.Provider, {
|
|
110
98
|
value: {
|
|
111
99
|
apiUrl: props.apiUrl
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
100
|
+
},
|
|
101
|
+
children: /* @__PURE__ */jsx(AuthProvider$1, {
|
|
102
|
+
getAuthData,
|
|
103
|
+
signOut,
|
|
104
|
+
children: props.children
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
const useAuth = () => {
|
|
109
|
+
const authCore = useAuth$1();
|
|
120
110
|
const {
|
|
121
111
|
apiUrl
|
|
122
112
|
} = React.useContext(AuthContext);
|
|
@@ -124,10 +114,11 @@ var useAuth = /* @__PURE__ */__name(() => {
|
|
|
124
114
|
apiUrl,
|
|
125
115
|
...authCore
|
|
126
116
|
};
|
|
127
|
-
}
|
|
117
|
+
};
|
|
128
118
|
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/Auth.tsx
|
|
121
|
+
const Auth = props => {
|
|
131
122
|
const {
|
|
132
123
|
setAuthData,
|
|
133
124
|
apiUrl
|
|
@@ -139,7 +130,7 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
139
130
|
const {
|
|
140
131
|
addNotification
|
|
141
132
|
} = useNotifications();
|
|
142
|
-
const onSignIn =
|
|
133
|
+
const onSignIn = React.useCallback(async ({
|
|
143
134
|
email,
|
|
144
135
|
password
|
|
145
136
|
}) => {
|
|
@@ -156,8 +147,7 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
156
147
|
});
|
|
157
148
|
const data = await response.json();
|
|
158
149
|
if (!response.ok) {
|
|
159
|
-
|
|
160
|
-
if (errorMessage === "Your account email is not confirmed") {
|
|
150
|
+
if (data.error?.message === "Your account email is not confirmed") {
|
|
161
151
|
const resendResponse = await fetch(`${apiUrl}/auth/send-email-confirmation`, {
|
|
162
152
|
method: "POST",
|
|
163
153
|
headers: {
|
|
@@ -168,10 +158,9 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
168
158
|
})
|
|
169
159
|
});
|
|
170
160
|
if (!resendResponse.ok) {
|
|
171
|
-
const resendData = await resendResponse.json();
|
|
172
161
|
addNotification({
|
|
173
162
|
title: "Resend confirmation email failed",
|
|
174
|
-
message:
|
|
163
|
+
message: (await resendResponse.json()).error?.message || "An error occurred while resending the confirmation email.",
|
|
175
164
|
type: "error"
|
|
176
165
|
});
|
|
177
166
|
return;
|
|
@@ -209,7 +198,7 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
209
198
|
});
|
|
210
199
|
}
|
|
211
200
|
}, [setAuthData, setScreen, addNotification, apiUrl]);
|
|
212
|
-
const onSignUp =
|
|
201
|
+
const onSignUp = React.useCallback(async ({
|
|
213
202
|
email,
|
|
214
203
|
password
|
|
215
204
|
}) => {
|
|
@@ -245,7 +234,7 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
245
234
|
});
|
|
246
235
|
}
|
|
247
236
|
}, [addNotification, setScreen, apiUrl]);
|
|
248
|
-
const onForgotPassword =
|
|
237
|
+
const onForgotPassword = React.useCallback(async ({
|
|
249
238
|
email
|
|
250
239
|
}) => {
|
|
251
240
|
try {
|
|
@@ -281,7 +270,7 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
281
270
|
});
|
|
282
271
|
}
|
|
283
272
|
}, [addNotification, setScreen, apiUrl]);
|
|
284
|
-
const onForgotPasswordResetPassword =
|
|
273
|
+
const onForgotPasswordResetPassword = React.useCallback(async ({
|
|
285
274
|
email: _email,
|
|
286
275
|
code,
|
|
287
276
|
newPassword
|
|
@@ -323,12 +312,12 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
323
312
|
});
|
|
324
313
|
}
|
|
325
314
|
}, [addNotification, setScreen, apiUrl]);
|
|
326
|
-
const onConfirmSignUpCheckEmail =
|
|
315
|
+
const onConfirmSignUpCheckEmail = React.useCallback(async () => {
|
|
327
316
|
setScreen({
|
|
328
317
|
value: "signIn"
|
|
329
318
|
});
|
|
330
319
|
}, [setScreen]);
|
|
331
|
-
return /* @__PURE__ */
|
|
320
|
+
return /* @__PURE__ */jsx(Auth$1, {
|
|
332
321
|
logo: props.logo,
|
|
333
322
|
layout: props.layout,
|
|
334
323
|
screen,
|
|
@@ -339,5 +328,7 @@ var Auth = /* @__PURE__ */__name(props => {
|
|
|
339
328
|
onForgotPasswordResetPassword,
|
|
340
329
|
onConfirmSignUpCheckEmail
|
|
341
330
|
});
|
|
342
|
-
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
//#endregion
|
|
343
334
|
export { Auth, AuthProvider, useAuth };
|
package/i18n/compiled/en.json
CHANGED
|
@@ -259,7 +259,8 @@
|
|
|
259
259
|
],
|
|
260
260
|
"fOOwej": [
|
|
261
261
|
{
|
|
262
|
-
"
|
|
262
|
+
"type": 6,
|
|
263
|
+
"value": "max_files",
|
|
263
264
|
"options": {
|
|
264
265
|
"one": {
|
|
265
266
|
"value": [
|
|
@@ -292,9 +293,8 @@
|
|
|
292
293
|
]
|
|
293
294
|
}
|
|
294
295
|
},
|
|
295
|
-
"
|
|
296
|
-
"
|
|
297
|
-
"value": "max_files"
|
|
296
|
+
"offset": 0,
|
|
297
|
+
"pluralType": "cardinal"
|
|
298
298
|
}
|
|
299
299
|
],
|
|
300
300
|
"gy0Ynb": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/react-auth-strapi",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.30",
|
|
4
4
|
"description": "Authentication components and abstractions for React apps using Strapi.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"React",
|
|
@@ -34,28 +34,28 @@
|
|
|
34
34
|
"@jest/globals": "^29.7.0",
|
|
35
35
|
"@types/react": "^19.2.14",
|
|
36
36
|
"jest": "^30.3.0",
|
|
37
|
-
"react": "^19.2.
|
|
38
|
-
"
|
|
39
|
-
"@ttoss/
|
|
40
|
-
"@ttoss/
|
|
41
|
-
"@ttoss/react-auth-core": "^0.4.
|
|
42
|
-
"@ttoss/react-i18n": "^2.2.
|
|
43
|
-
"@ttoss/react-notifications": "^2.7.
|
|
44
|
-
"@ttoss/test-utils": "^4.2.
|
|
45
|
-
"@ttoss/ui": "^6.9.
|
|
37
|
+
"react": "^19.2.6",
|
|
38
|
+
"tsdown": "^0.22.0",
|
|
39
|
+
"@ttoss/i18n-cli": "^0.8.13",
|
|
40
|
+
"@ttoss/config": "^1.37.13",
|
|
41
|
+
"@ttoss/react-auth-core": "^0.4.30",
|
|
42
|
+
"@ttoss/react-i18n": "^2.2.14",
|
|
43
|
+
"@ttoss/react-notifications": "^2.7.21",
|
|
44
|
+
"@ttoss/test-utils": "^4.2.13",
|
|
45
|
+
"@ttoss/ui": "^6.9.20"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": ">=16.8.0",
|
|
49
|
-
"@ttoss/react-auth-core": "^0.4.
|
|
50
|
-
"@ttoss/react-i18n": "^2.2.
|
|
51
|
-
"@ttoss/react-notifications": "^2.7.
|
|
49
|
+
"@ttoss/react-auth-core": "^0.4.30",
|
|
50
|
+
"@ttoss/react-i18n": "^2.2.14",
|
|
51
|
+
"@ttoss/react-notifications": "^2.7.21"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public",
|
|
55
55
|
"provenance": true
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
|
-
"build": "
|
|
58
|
+
"build": "tsdown",
|
|
59
59
|
"i18n": "ttoss-i18n",
|
|
60
60
|
"test": "jest --projects tests/unit"
|
|
61
61
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as _ttoss_react_auth_core from '@ttoss/react-auth-core';
|
|
3
|
-
import { AuthProps, AuthScreen } from '@ttoss/react-auth-core';
|
|
4
|
-
export { AuthScreen } from '@ttoss/react-auth-core';
|
|
5
|
-
import * as React from 'react';
|
|
6
|
-
|
|
7
|
-
declare const Auth: (props: Pick<AuthProps, "logo" | "layout"> & {
|
|
8
|
-
initialScreen?: AuthScreen;
|
|
9
|
-
}) => react_jsx_runtime.JSX.Element;
|
|
10
|
-
|
|
11
|
-
declare const AuthProvider: (props: React.PropsWithChildren<{
|
|
12
|
-
apiUrl: string;
|
|
13
|
-
}>) => react_jsx_runtime.JSX.Element;
|
|
14
|
-
declare const useAuth: () => {
|
|
15
|
-
signOut: () => Promise<void>;
|
|
16
|
-
isAuthenticated: boolean;
|
|
17
|
-
user: _ttoss_react_auth_core.AuthUser | null;
|
|
18
|
-
tokens: _ttoss_react_auth_core.AuthTokens | null;
|
|
19
|
-
setAuthData: React.Dispatch<React.SetStateAction<_ttoss_react_auth_core.AuthData>>;
|
|
20
|
-
apiUrl: string;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export { Auth, AuthProvider, useAuth };
|