@refinedev/core 4.45.0 → 4.46.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/CHANGELOG.md +82 -0
- package/README.md +131 -123
- package/dist/components/authenticated/index.d.ts +34 -0
- package/dist/components/authenticated/index.d.ts.map +1 -1
- package/dist/components/gh-banner/index.d.ts.map +1 -1
- package/dist/components/gh-banner/styles.d.ts.map +1 -1
- package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
- package/dist/components/pages/auth/components/register/index.d.ts.map +1 -1
- package/dist/components/pages/welcome/index.d.ts.map +1 -1
- package/dist/esm/index.js +30 -49
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/data/useMany.d.ts +1 -1
- package/dist/hooks/data/useMany.d.ts.map +1 -1
- package/dist/hooks/data/useOne.d.ts +1 -1
- package/dist/hooks/data/useOne.d.ts.map +1 -1
- package/dist/hooks/form/useForm.d.ts +1 -1
- package/dist/hooks/form/useForm.d.ts.map +1 -1
- package/dist/hooks/show/useShow.d.ts +3 -3
- package/dist/hooks/show/useShow.d.ts.map +1 -1
- package/dist/hooks/useSelect/index.d.ts +3 -3
- package/dist/hooks/useSelect/index.d.ts.map +1 -1
- package/dist/iife/index.js +30 -49
- package/dist/iife/index.js.map +1 -1
- package/dist/index.js +30 -49
- package/dist/index.js.map +1 -1
- package/dist/interfaces/auth.d.ts +12 -0
- package/dist/interfaces/auth.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/authenticated/index.tsx +118 -139
- package/src/components/gh-banner/index.tsx +238 -55
- package/src/components/gh-banner/styles.ts +26 -46
- package/src/components/pages/auth/components/login/index.tsx +110 -84
- package/src/components/pages/auth/components/register/index.tsx +88 -65
- package/src/components/pages/welcome/index.tsx +125 -124
- package/src/hooks/auth/useLogin/index.ts +4 -4
- package/src/hooks/auth/useLogout/index.ts +4 -4
- package/src/hooks/auth/useRegister/index.ts +5 -4
- package/src/hooks/data/useMany.ts +1 -1
- package/src/hooks/data/useOne.ts +1 -1
- package/src/hooks/form/useForm.ts +1 -1
- package/src/hooks/show/useShow.ts +3 -3
- package/src/hooks/useSelect/index.ts +3 -2
- package/src/interfaces/auth.tsx +12 -0
|
@@ -62,6 +62,11 @@ export declare type AuthPageProps<TWrapperProps extends {} = Record<keyof any, u
|
|
|
62
62
|
* @optional
|
|
63
63
|
*/
|
|
64
64
|
rememberMe?: React.ReactNode;
|
|
65
|
+
/**
|
|
66
|
+
* @description Can be used to hide the form components
|
|
67
|
+
* @optional
|
|
68
|
+
*/
|
|
69
|
+
hideForm?: boolean;
|
|
65
70
|
}> | PropsWithChildren<{
|
|
66
71
|
/**
|
|
67
72
|
* @description The type of the auth page.
|
|
@@ -73,6 +78,11 @@ export declare type AuthPageProps<TWrapperProps extends {} = Record<keyof any, u
|
|
|
73
78
|
* @optional
|
|
74
79
|
*/
|
|
75
80
|
providers?: OAuthProvider[];
|
|
81
|
+
/**
|
|
82
|
+
* @description Can be used to hide the form components
|
|
83
|
+
* @optional
|
|
84
|
+
*/
|
|
85
|
+
hideForm?: boolean;
|
|
76
86
|
}> | PropsWithChildren<{
|
|
77
87
|
/**
|
|
78
88
|
* @description The type of the auth page.
|
|
@@ -130,6 +140,7 @@ export declare type LoginPageProps<TWrapperProps extends {} = Record<keyof any,
|
|
|
130
140
|
contentProps?: TContentProps;
|
|
131
141
|
formProps?: TFormProps;
|
|
132
142
|
title?: React.ReactNode;
|
|
143
|
+
hideForm?: boolean;
|
|
133
144
|
}>;
|
|
134
145
|
/**
|
|
135
146
|
* This should be the base type for `AuthPage` `Register` component implementations in UI integrations.
|
|
@@ -142,6 +153,7 @@ export declare type RegisterPageProps<TWrapperProps extends {} = Record<keyof an
|
|
|
142
153
|
contentProps?: TContentProps;
|
|
143
154
|
formProps?: TFormProps;
|
|
144
155
|
title?: React.ReactNode;
|
|
156
|
+
hideForm?: boolean;
|
|
145
157
|
}>;
|
|
146
158
|
/**
|
|
147
159
|
* This should be the base type for `AuthPage` `Reset Password` component implementations in UI integrations.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/interfaces/auth.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAEjD,oBAAY,aAAa,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,cAAc;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,uBAAuB;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,uBAAuB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,oBAAY,aAAa,CACrB,aAAa,SAAS,EAAE,GAAG,MAAM,CAAC,MAAM,GAAG,EAAE,OAAO,CAAC,EACrD,aAAa,SAAS,EAAE,GAAG,MAAM,CAAC,MAAM,GAAG,EAAE,OAAO,CAAC,EACrD,UAAU,SAAS,EAAE,GAAG,MAAM,CAAC,MAAM,GAAG,EAAE,OAAO,CAAC,IAClD,CACE,iBAAiB,CAAC;IACd;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;OAIG;IACH,SAAS,CAAC,EAAE,aAAa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,OAAO,CAAC,IAClD,iBAAiB,CAAC;IAClB,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,aAAa,CAAC,EAAE,CACZ,OAAO,EAAE,KAAK,CAAC,SAAS,EACxB,KAAK,EAAE,KAAK,CAAC,SAAS,KACrB,KAAK,CAAC,SAAS,CAAC;IACrB,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refinedev/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.46.0",
|
|
4
4
|
"description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -11,35 +11,13 @@ import {
|
|
|
11
11
|
import { useActiveAuthProvider } from "@definitions/index";
|
|
12
12
|
import { GoConfig } from "src/interfaces";
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* This hook is used to avoid React's invalid setState call warning.
|
|
16
|
-
* When `go` is called during the render phase, it's updating the internal router state before the render phase is finished.
|
|
17
|
-
* This causes React to throw an error. This hook is used to defer the `go` call to the effect calls.
|
|
18
|
-
*/
|
|
19
|
-
const useDeferredGo = () => {
|
|
20
|
-
const go = useGo();
|
|
21
|
-
|
|
22
|
-
const [config, setConfig] = React.useState<GoConfig | undefined>(undefined);
|
|
23
|
-
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
if (config) {
|
|
26
|
-
go(config);
|
|
27
|
-
}
|
|
28
|
-
}, [config]);
|
|
29
|
-
|
|
30
|
-
const cb = React.useCallback(
|
|
31
|
-
(props: GoConfig) => {
|
|
32
|
-
if (!config) {
|
|
33
|
-
setConfig(props);
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
[config],
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
return cb;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
14
|
export type AuthenticatedCommonProps = {
|
|
15
|
+
/**
|
|
16
|
+
* Unique key to identify the component.
|
|
17
|
+
* This is required if you have multiple `Authenticated` components at the same level.
|
|
18
|
+
* @required
|
|
19
|
+
*/
|
|
20
|
+
key: React.Key;
|
|
43
21
|
/**
|
|
44
22
|
* Whether to redirect user if not logged in or not.
|
|
45
23
|
* If not set, user will be redirected to `redirectTo` property of the `check` function's response.
|
|
@@ -79,17 +57,40 @@ export type AuthenticatedProps = {
|
|
|
79
57
|
v3LegacyAuthProviderCompatible?: false;
|
|
80
58
|
} & AuthenticatedCommonProps;
|
|
81
59
|
|
|
60
|
+
/**
|
|
61
|
+
* `<Authenticated>` is the component form of {@link https://refine.dev/docs/api-reference/core/hooks/auth/useAuthenticated `useAuthenticated`}. It internally uses `useAuthenticated` to provide it's functionality.
|
|
62
|
+
*
|
|
63
|
+
* @requires {@link https://react.dev/learn/rendering-lists#why-does-react-need-keys `key`} prop if you have multiple components at the same level.
|
|
64
|
+
* In React, components don't automatically unmount and remount with prop changes, which is generally good for performance. However, for specific cases this can cause issues like unwanted content rendering (`fallback` or `children`). To solve this, assigning unique `key` values to each instance of component is necessary, forcing React to unmount and remount the component, rather than just updating its props.
|
|
65
|
+
* @example
|
|
66
|
+
*```tsx
|
|
67
|
+
* <Authenticated key="dashboard">
|
|
68
|
+
* <h1>Dashboard Page</h1>
|
|
69
|
+
* </Authenticated>
|
|
70
|
+
*```
|
|
71
|
+
*
|
|
72
|
+
* @see {@link https://refine.dev/docs/core/components/auth/authenticated `<Authenticated>`} component for more details.
|
|
73
|
+
*/
|
|
82
74
|
export function Authenticated(
|
|
83
75
|
props: LegacyAuthenticatedProps,
|
|
84
76
|
): JSX.Element | null;
|
|
85
77
|
|
|
86
|
-
export function Authenticated(props: AuthenticatedProps): JSX.Element | null;
|
|
87
|
-
|
|
88
78
|
/**
|
|
89
79
|
* `<Authenticated>` is the component form of {@link https://refine.dev/docs/api-reference/core/hooks/auth/useAuthenticated `useAuthenticated`}. It internally uses `useAuthenticated` to provide it's functionality.
|
|
90
80
|
*
|
|
81
|
+
* @requires {@link https://react.dev/learn/rendering-lists#why-does-react-need-keys `key`} prop if you have multiple components at the same level.
|
|
82
|
+
* In React, components don't automatically unmount and remount with prop changes, which is generally good for performance. However, for specific cases this can cause issues like unwanted content rendering (`fallback` or `children`). To solve this, assigning unique `key` values to each instance of component is necessary, forcing React to unmount and remount the component, rather than just updating its props.
|
|
83
|
+
* @example
|
|
84
|
+
*```tsx
|
|
85
|
+
* <Authenticated key="dashboard">
|
|
86
|
+
* <h1>Dashboard Page</h1>
|
|
87
|
+
* </Authenticated>
|
|
88
|
+
*```
|
|
89
|
+
*
|
|
91
90
|
* @see {@link https://refine.dev/docs/core/components/auth/authenticated `<Authenticated>`} component for more details.
|
|
92
91
|
*/
|
|
92
|
+
export function Authenticated(props: AuthenticatedProps): JSX.Element | null;
|
|
93
|
+
|
|
93
94
|
export function Authenticated({
|
|
94
95
|
redirectOnFail = true,
|
|
95
96
|
appendCurrentPathToQuery = true,
|
|
@@ -106,138 +107,116 @@ export function Authenticated({
|
|
|
106
107
|
|
|
107
108
|
const parsed = useParsed();
|
|
108
109
|
const go = useGo();
|
|
109
|
-
const deferredGo = useDeferredGo();
|
|
110
|
-
const { replace } = useNavigation();
|
|
111
110
|
const { useLocation } = useRouterContext();
|
|
112
111
|
const legacyLocation = useLocation();
|
|
113
112
|
|
|
114
113
|
const {
|
|
115
|
-
isLoading,
|
|
116
114
|
isFetching,
|
|
117
|
-
// isRefetching,
|
|
118
115
|
isSuccess,
|
|
119
116
|
data: {
|
|
120
117
|
authenticated: isAuthenticatedStatus,
|
|
121
118
|
redirectTo: authenticatedRedirect,
|
|
122
119
|
} = {},
|
|
123
|
-
refetch,
|
|
124
120
|
} = useIsAuthenticated({
|
|
125
121
|
v3LegacyAuthProviderCompatible: isLegacyAuth,
|
|
126
122
|
});
|
|
127
123
|
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Refetch the authentication status if the content is changed (e.g. redirected or updated)
|
|
131
|
-
*
|
|
132
|
-
* This is done to avoid re-rendering the wrappers with the same content.
|
|
133
|
-
*/
|
|
134
|
-
|
|
135
|
-
refetch();
|
|
136
|
-
}, [children, fallbackContent]);
|
|
137
|
-
|
|
138
|
-
const state = React.useRef<{
|
|
139
|
-
status: "initial" | "pending" | "settled";
|
|
140
|
-
content: React.ReactNode;
|
|
141
|
-
}>({
|
|
142
|
-
status: isLoading ? "initial" : "pending",
|
|
143
|
-
content: loadingContent ?? null,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Update state when fetching the authentication response.
|
|
148
|
-
*/
|
|
149
|
-
if (isFetching) {
|
|
150
|
-
state.current.status = "pending";
|
|
151
|
-
} else if (!isFetching) {
|
|
152
|
-
state.current.status = "settled";
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Authentication status
|
|
157
|
-
*/
|
|
124
|
+
// Authentication status
|
|
158
125
|
const isAuthenticated = hasAuthProvider
|
|
159
126
|
? isLegacyAuth
|
|
160
127
|
? isSuccess
|
|
161
128
|
: isAuthenticatedStatus
|
|
162
129
|
: true;
|
|
163
130
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
*/
|
|
168
|
-
if (isAuthenticated) {
|
|
169
|
-
/**
|
|
170
|
-
* If user is authenticated, show the children.
|
|
171
|
-
*/
|
|
172
|
-
state.current.content = <>{children ?? null}</>;
|
|
173
|
-
} else if (typeof fallbackContent !== "undefined") {
|
|
174
|
-
/**
|
|
175
|
-
* If user is not authenticated, and `fallback` is present, show the fallback content.
|
|
176
|
-
*/
|
|
177
|
-
state.current.content = <>{fallbackContent}</>;
|
|
178
|
-
} else {
|
|
179
|
-
/**
|
|
180
|
-
* If there's no `fallback` content, redirect will be applied.
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Current pathname to append to the redirect url.
|
|
185
|
-
*/
|
|
186
|
-
const pathname = `${
|
|
187
|
-
isLegacyRouter ? legacyLocation?.pathname : parsed.pathname
|
|
188
|
-
}`.replace(/(\?.*|#.*)$/, "");
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Redirect url to use, if `redirectOnFail` is set to a string,
|
|
192
|
-
* it will be used instead of `redirectTo` property of the `check` function's response.
|
|
193
|
-
*/
|
|
194
|
-
const appliedRedirect = isLegacyAuth
|
|
195
|
-
? typeof redirectOnFail === "string"
|
|
196
|
-
? redirectOnFail
|
|
197
|
-
: "/login"
|
|
198
|
-
: typeof redirectOnFail === "string"
|
|
199
|
-
? redirectOnFail
|
|
200
|
-
: (authenticatedRedirect as string | undefined);
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Redirect if `appliedRedirect` is set.
|
|
204
|
-
*/
|
|
205
|
-
if (appliedRedirect) {
|
|
206
|
-
if (isLegacyRouter) {
|
|
207
|
-
const toQuery = appendCurrentPathToQuery
|
|
208
|
-
? `?to=${encodeURIComponent(pathname)}`
|
|
209
|
-
: "";
|
|
210
|
-
replace(`${appliedRedirect}${toQuery}`);
|
|
211
|
-
} else {
|
|
212
|
-
deferredGo({
|
|
213
|
-
to: appliedRedirect,
|
|
214
|
-
query: appendCurrentPathToQuery
|
|
215
|
-
? {
|
|
216
|
-
to: parsed.params?.to
|
|
217
|
-
? parsed.params.to
|
|
218
|
-
: go({
|
|
219
|
-
to: pathname,
|
|
220
|
-
options: { keepQuery: true },
|
|
221
|
-
type: "path",
|
|
222
|
-
}),
|
|
223
|
-
}
|
|
224
|
-
: undefined,
|
|
225
|
-
type: "replace",
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
131
|
+
// when there is no auth provider
|
|
132
|
+
if (!hasAuthProvider) {
|
|
133
|
+
return <>{children ?? null}</>;
|
|
230
134
|
}
|
|
231
135
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
136
|
+
// when checking authentication status
|
|
137
|
+
if (isFetching) {
|
|
138
|
+
return <>{loadingContent ?? null}</>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// when user is authenticated return children
|
|
142
|
+
if (isAuthenticated) {
|
|
236
143
|
return <>{children ?? null}</>;
|
|
237
144
|
}
|
|
145
|
+
// when user is not authenticated redirect or render fallbackContent
|
|
146
|
+
else {
|
|
147
|
+
// render fallbackContent if it is exist
|
|
148
|
+
if (typeof fallbackContent !== "undefined") {
|
|
149
|
+
return <>{fallbackContent ?? null}</>;
|
|
150
|
+
}
|
|
151
|
+
// if there is no fallbackContent, redirect page
|
|
238
152
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
153
|
+
// Redirect url to use. use redirectOnFail if it is set.
|
|
154
|
+
// Otherwise use redirectTo property of the check function's response.
|
|
155
|
+
// If both are not set, use `/login` as the default redirect url. (only for legacy auth providers)
|
|
156
|
+
const appliedRedirect = isLegacyAuth
|
|
157
|
+
? typeof redirectOnFail === "string"
|
|
158
|
+
? redirectOnFail
|
|
159
|
+
: "/login"
|
|
160
|
+
: typeof redirectOnFail === "string"
|
|
161
|
+
? redirectOnFail
|
|
162
|
+
: (authenticatedRedirect as string | undefined);
|
|
163
|
+
|
|
164
|
+
// Current pathname to append to the redirect url.
|
|
165
|
+
// User will be redirected to this url after successful mutation. (like login)
|
|
166
|
+
const pathname = `${
|
|
167
|
+
isLegacyRouter ? legacyLocation?.pathname : parsed.pathname
|
|
168
|
+
}`.replace(/(\?.*|#.*)$/, "");
|
|
169
|
+
// Redirect if appliedRedirect is set, otherwise return null.
|
|
170
|
+
// Uses `replace` for legacy router and `go` for new router.
|
|
171
|
+
if (appliedRedirect) {
|
|
172
|
+
if (isLegacyRouter) {
|
|
173
|
+
const toQuery = appendCurrentPathToQuery
|
|
174
|
+
? `?to=${encodeURIComponent(pathname)}`
|
|
175
|
+
: "";
|
|
176
|
+
return <RedirectLegacy to={`${appliedRedirect}${toQuery}`} />;
|
|
177
|
+
} else {
|
|
178
|
+
return (
|
|
179
|
+
<Redirect
|
|
180
|
+
config={{
|
|
181
|
+
to: appliedRedirect,
|
|
182
|
+
query: appendCurrentPathToQuery
|
|
183
|
+
? {
|
|
184
|
+
to: parsed.params?.to
|
|
185
|
+
? parsed.params.to
|
|
186
|
+
: go({
|
|
187
|
+
to: pathname,
|
|
188
|
+
options: { keepQuery: true },
|
|
189
|
+
type: "path",
|
|
190
|
+
}),
|
|
191
|
+
}
|
|
192
|
+
: undefined,
|
|
193
|
+
type: "replace",
|
|
194
|
+
}}
|
|
195
|
+
/>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
243
202
|
}
|
|
203
|
+
|
|
204
|
+
const Redirect = ({ config }: { config: GoConfig }) => {
|
|
205
|
+
const go = useGo();
|
|
206
|
+
|
|
207
|
+
React.useEffect(() => {
|
|
208
|
+
go(config);
|
|
209
|
+
}, [go, config]);
|
|
210
|
+
|
|
211
|
+
return null;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const RedirectLegacy = ({ to }: { to: string }) => {
|
|
215
|
+
const { replace } = useNavigation();
|
|
216
|
+
|
|
217
|
+
React.useEffect(() => {
|
|
218
|
+
replace(to);
|
|
219
|
+
}, [replace, to]);
|
|
220
|
+
|
|
221
|
+
return null;
|
|
222
|
+
};
|