@opensourceframework/react-query-auth 2.4.3
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/LICENSE +21 -0
- package/README.md +169 -0
- package/dist/index.cjs +95 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Alan Alickovic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# @opensourceframework/react-query-auth
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@opensourceframework/react-query-auth)
|
|
4
|
+
|
|
5
|
+
Authenticate your react applications easily with [React Query](https://tanstack.com/query/v4/docs/react).
|
|
6
|
+
|
|
7
|
+
## Introduction
|
|
8
|
+
|
|
9
|
+
Using React Query has allowed us to significantly reduce the size of our codebase by caching server state. However, we still need to consider where to store user data, which is a type of global application state that we need to access from many parts of the app, but is also a server state since it is obtained from a server. This library makes it easy to manage user authentication, and can be adapted to work with any API or authentication method.
|
|
10
|
+
|
|
11
|
+
### Attribution
|
|
12
|
+
|
|
13
|
+
- **Original Author**: Unknown
|
|
14
|
+
- **Original Repository**: https://github.com/alan2207/react-query-auth
|
|
15
|
+
- **Original License**: MIT
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
$ npm install @tanstack/react-query @opensourceframework/react-query-auth
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or if you use Yarn:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
$ yarn add @tanstack/react-query @opensourceframework/react-query-auth
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
To use this library, you will need to provide it with functions for fetching the current user, logging in, registering, and logging out. You can do this using the `configureAuth` function:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { configureAuth } from '@opensourceframework/react-query-auth';
|
|
35
|
+
|
|
36
|
+
const { useUser, useLogin, useRegister, useLogout } = configureAuth({
|
|
37
|
+
userFn: () => api.get('/me'),
|
|
38
|
+
loginFn: (credentials) => api.post('/login', credentials),
|
|
39
|
+
registerFn: (credentials) => api.post('/register', credentials),
|
|
40
|
+
logoutFn: () => api.post('/logout'),
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
With these hooks, you can then add authentication functionality to your app. For example, you could use the `useUser` hook to access the authenticated user in a component.
|
|
45
|
+
|
|
46
|
+
You can also use the `useLogin`, `useRegister`, and `useLogout` hooks to allow users to authenticate and log out.
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
function UserInfo() {
|
|
50
|
+
const user = useUser();
|
|
51
|
+
const logout = useLogout();
|
|
52
|
+
|
|
53
|
+
if (user.isLoading) {
|
|
54
|
+
return <div>Loading ...</div>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (user.error) {
|
|
58
|
+
return <div>{JSON.stringify(user.error, null, 2)}</div>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!user.data) {
|
|
62
|
+
return <div>Not logged in</div>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div>
|
|
67
|
+
<div>Logged in as {user.data.email}</div>
|
|
68
|
+
<button disabled={logout.isLoading} onClick={logout.mutate({})}>
|
|
69
|
+
Log out
|
|
70
|
+
</button>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The library also provides the `AuthLoader` component that can be used to handle loading states when fetching the authenticated user. You can use it like this:
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
function MyApp() {
|
|
80
|
+
return (
|
|
81
|
+
<AuthLoader
|
|
82
|
+
renderLoading={() => <div>Loading ...</div>}
|
|
83
|
+
renderUnauthenticated={() => <AuthScreen />}
|
|
84
|
+
>
|
|
85
|
+
<UserInfo />
|
|
86
|
+
</AuthLoader>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**NOTE: All hooks and components must be used within `QueryClientProvider`.**
|
|
92
|
+
|
|
93
|
+
## API Reference:
|
|
94
|
+
|
|
95
|
+
### `configureAuth`:
|
|
96
|
+
|
|
97
|
+
The `configureAuth` function takes in a configuration object and returns a set of custom hooks for handling authentication.
|
|
98
|
+
|
|
99
|
+
#### The `configureAuth` configuration object:
|
|
100
|
+
|
|
101
|
+
A configuration object that specifies the functions and keys to be used for various authentication actions. It accepts the following properties:
|
|
102
|
+
|
|
103
|
+
- **`userFn`:**
|
|
104
|
+
A function that is used to retrieve the authenticated user. It should return a Promise that resolves to the user object, or null if the user is not authenticated.
|
|
105
|
+
|
|
106
|
+
- **`loginFn`:**
|
|
107
|
+
A function that is used to log the user in. It should accept login credentials as its argument and return a Promise that resolves to the user object.
|
|
108
|
+
|
|
109
|
+
- **`registerFn`:**
|
|
110
|
+
A function that is used to register a new user. It should accept registration credentials as its argument and return a Promise that resolves to the new user object.
|
|
111
|
+
|
|
112
|
+
- **`logoutFn`:**
|
|
113
|
+
A function that is used to log the user out. It should return a Promise that resolves when the logout action is complete.
|
|
114
|
+
|
|
115
|
+
- **`userKey`:**
|
|
116
|
+
An optional key that is used to store the authenticated user in the react-query cache. The default value is `['authenticated-user']`.
|
|
117
|
+
|
|
118
|
+
#### The `configureAuth` returned object:
|
|
119
|
+
|
|
120
|
+
`configureAuth` returns an object with the following properties:
|
|
121
|
+
|
|
122
|
+
- **`useUser`:**
|
|
123
|
+
A custom hook that retrieves the authenticated user. It is a wrapper around [useQuery](https://tanstack.com/query/v4/docs/react/reference/useQuery) that uses the `userFn` and `userKey` specified in the `configAuth` configuration. The hook accepts the same options as [useQuery](https://tanstack.com/query/v4/docs/react/reference/useQuery), except for `queryKey` and `queryFn`, which are predefined by the configuration.
|
|
124
|
+
|
|
125
|
+
- **`useLogin`:**
|
|
126
|
+
A custom hook that logs the user in. It is a wrapper around [useMutation](https://tanstack.com/query/v4/docs/react/reference/useMutation) that uses the `loginFn` specified in the configuration. The hook accepts the same options as [useMutation](https://tanstack.com/query/v4/docs/react/reference/useMutation), except for `mutationFn`, which is set by the configuration. On success, the hook updates the authenticated user in the React Query cache using the `userKey` specified in the configuration.
|
|
127
|
+
|
|
128
|
+
- **`useRegister`:**
|
|
129
|
+
A custom hook that registers a new user. It is a wrapper around [useMutation](https://tanstack.com/query/v4/docs/react/reference/useMutation) that uses the `registerFn` specified in the configuration. The hook accepts the same options as [useMutation](https://tanstack.com/query/v4/docs/react/reference/useMutation), except for `mutationFn`, which is set by the configuration. On success, the hook updates the authenticated user in the React Query cache using the `userKey` specified in the configuration.
|
|
130
|
+
|
|
131
|
+
- **`useLogout`:**
|
|
132
|
+
A custom hook that logs the user out. It is a wrapper around [useMutation](https://tanstack.com/query/v4/docs/react/reference/useMutation) that uses the `logoutFn` specified in the configuration. The hook accepts the same options as [useMutation](https://tanstack.com/query/v4/docs/react/reference/useMutation), except for `mutationFn`, which is set by the configuration. On success, the hook removes the authenticated user from the React Query cache using the `userKey` specified in the configuration.
|
|
133
|
+
|
|
134
|
+
- **`AuthLoader`:**
|
|
135
|
+
|
|
136
|
+
A component that can be used to handle loading states when fetching the authenticated user. It accepts the following props:
|
|
137
|
+
|
|
138
|
+
- **`renderLoading`**:
|
|
139
|
+
A function that is called when the authenticated user is being fetched. It should return a React node that is rendered while the user is being fetched.
|
|
140
|
+
|
|
141
|
+
- **`renderUnauthenticated`**:
|
|
142
|
+
A function that is called when the authenticated user is not authenticated. It should return a React node that is rendered when the user is not authenticated.
|
|
143
|
+
|
|
144
|
+
- **`renderError`**:
|
|
145
|
+
A function that is called when an error is thrown during the authentication request. It should return a React node that is rendered when the error occurs. It receives the `Error` object which can be used during rendering. Defaults to `(error: Error) => <>{JSON.stringify(error)}</>`.
|
|
146
|
+
|
|
147
|
+
- **`children`**:
|
|
148
|
+
A React node that is rendered when the authenticated user is successfully fetched.
|
|
149
|
+
|
|
150
|
+
If you need a more custom loading implementation, you can create your own `AuthLoader` component and use the `useUser` hook to fetch the authenticated user and handle the loading and error states yourself.
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
If none of the provided hooks or components meet your needs, feel free to copy the source code into your project and modify it to your liking.
|
|
154
|
+
|
|
155
|
+
## Examples:
|
|
156
|
+
|
|
157
|
+
To try out the library, check out the `examples` folder.
|
|
158
|
+
|
|
159
|
+
## Contributing
|
|
160
|
+
|
|
161
|
+
1. Clone this repo
|
|
162
|
+
2. Create a branch: `git checkout -b your-feature`
|
|
163
|
+
3. Make some changes
|
|
164
|
+
4. Test your changes
|
|
165
|
+
5. Push your branch and open a Pull Request
|
|
166
|
+
|
|
167
|
+
## LICENSE
|
|
168
|
+
|
|
169
|
+
[MIT](/LICENSE)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactQuery = require('@tanstack/react-query');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @opensourceframework/react-query-auth
|
|
13
|
+
* Authenticate your react applications easily with react-query
|
|
14
|
+
*
|
|
15
|
+
* @original-author Alan (alan2207)
|
|
16
|
+
* @original-repo https://github.com/alan2207/react-query-auth
|
|
17
|
+
* @license MIT
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function configureAuth(config) {
|
|
21
|
+
const { userFn, userKey = ["authenticated-user"], loginFn, registerFn, logoutFn } = config;
|
|
22
|
+
const useUser = (options) => reactQuery.useQuery({
|
|
23
|
+
queryKey: userKey,
|
|
24
|
+
queryFn: userFn,
|
|
25
|
+
...options
|
|
26
|
+
});
|
|
27
|
+
const useLogin = (options) => {
|
|
28
|
+
const queryClient = reactQuery.useQueryClient();
|
|
29
|
+
const setUser = React__default.default.useCallback((data) => queryClient.setQueryData(userKey, data), [queryClient]);
|
|
30
|
+
return reactQuery.useMutation({
|
|
31
|
+
mutationFn: loginFn,
|
|
32
|
+
...options,
|
|
33
|
+
onSuccess: (user, ...rest) => {
|
|
34
|
+
setUser(user);
|
|
35
|
+
options?.onSuccess?.(user, ...rest);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const useRegister = (options) => {
|
|
40
|
+
const queryClient = reactQuery.useQueryClient();
|
|
41
|
+
const setUser = React__default.default.useCallback((data) => queryClient.setQueryData(userKey, data), [queryClient]);
|
|
42
|
+
return reactQuery.useMutation({
|
|
43
|
+
mutationFn: registerFn,
|
|
44
|
+
...options,
|
|
45
|
+
onSuccess: (user, ...rest) => {
|
|
46
|
+
setUser(user);
|
|
47
|
+
options?.onSuccess?.(user, ...rest);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const useLogout = (options) => {
|
|
52
|
+
const queryClient = reactQuery.useQueryClient();
|
|
53
|
+
const setUser = React__default.default.useCallback((data) => queryClient.setQueryData(userKey, data), [queryClient]);
|
|
54
|
+
return reactQuery.useMutation({
|
|
55
|
+
mutationFn: logoutFn,
|
|
56
|
+
...options,
|
|
57
|
+
onSuccess: (...args) => {
|
|
58
|
+
setUser(null);
|
|
59
|
+
options?.onSuccess?.(...args);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
function AuthLoader({
|
|
64
|
+
children,
|
|
65
|
+
renderLoading,
|
|
66
|
+
renderUnauthenticated,
|
|
67
|
+
renderError = (error) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: JSON.stringify(error) })
|
|
68
|
+
}) {
|
|
69
|
+
const { isSuccess, isFetched, status, data, error } = useUser();
|
|
70
|
+
if (isSuccess) {
|
|
71
|
+
if (renderUnauthenticated && !data) {
|
|
72
|
+
return renderUnauthenticated();
|
|
73
|
+
}
|
|
74
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
75
|
+
}
|
|
76
|
+
if (!isFetched) {
|
|
77
|
+
return renderLoading();
|
|
78
|
+
}
|
|
79
|
+
if (status === "error") {
|
|
80
|
+
return renderError(error);
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
useUser,
|
|
86
|
+
useLogin,
|
|
87
|
+
useRegister,
|
|
88
|
+
useLogout,
|
|
89
|
+
AuthLoader
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
exports.configureAuth = configureAuth;
|
|
94
|
+
//# sourceMappingURL=index.cjs.map
|
|
95
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["useQuery","useQueryClient","React","useMutation"],"mappings":"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","file":"index.cjs","sourcesContent":["import {\n\ttype MutationFunction,\n\ttype QueryFunction,\n\ttype QueryKey,\n\ttype UseMutationOptions,\n\ttype UseQueryOptions,\n\tuseMutation,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query'\nimport React from 'react'\n\nexport interface ReactQueryAuthConfig<User, LoginCredentials, RegisterCredentials> {\n\tuserFn: QueryFunction<User, QueryKey>\n\tloginFn: MutationFunction<User, LoginCredentials>\n\tregisterFn: MutationFunction<User, RegisterCredentials>\n\tlogoutFn: MutationFunction<unknown, unknown>\n\tuserKey?: QueryKey\n}\n\nexport interface AuthProviderProps {\n\tchildren: React.ReactNode\n}\n\nexport function configureAuth<User, Error, LoginCredentials, RegisterCredentials>(\n\tconfig: ReactQueryAuthConfig<User, LoginCredentials, RegisterCredentials>\n) {\n\tconst { userFn, userKey = ['authenticated-user'], loginFn, registerFn, logoutFn } = config\n\n\tconst useUser = (options?: Omit<UseQueryOptions<User, Error, User, QueryKey>, 'queryKey' | 'queryFn'>) =>\n\t\tuseQuery({\n\t\t\tqueryKey: userKey,\n\t\t\tqueryFn: userFn,\n\t\t\t...options,\n\t\t})\n\n\tconst useLogin = (options?: Omit<UseMutationOptions<User, Error, LoginCredentials>, 'mutationFn'>) => {\n\t\tconst queryClient = useQueryClient()\n\n\t\tconst setUser = React.useCallback((data: User) => queryClient.setQueryData(userKey, data), [queryClient])\n\n\t\treturn useMutation({\n\t\t\tmutationFn: loginFn,\n\t\t\t...options,\n\t\t\tonSuccess: (user, ...rest) => {\n\t\t\t\tsetUser(user)\n\t\t\t\toptions?.onSuccess?.(user, ...rest)\n\t\t\t},\n\t\t})\n\t}\n\n\tconst useRegister = (options?: Omit<UseMutationOptions<User, Error, RegisterCredentials>, 'mutationFn'>) => {\n\t\tconst queryClient = useQueryClient()\n\n\t\tconst setUser = React.useCallback((data: User) => queryClient.setQueryData(userKey, data), [queryClient])\n\n\t\treturn useMutation({\n\t\t\tmutationFn: registerFn,\n\t\t\t...options,\n\t\t\tonSuccess: (user, ...rest) => {\n\t\t\t\tsetUser(user)\n\t\t\t\toptions?.onSuccess?.(user, ...rest)\n\t\t\t},\n\t\t})\n\t}\n\n\tconst useLogout = (options?: UseMutationOptions<unknown, Error, unknown>) => {\n\t\tconst queryClient = useQueryClient()\n\n\t\tconst setUser = React.useCallback((data: User | null) => queryClient.setQueryData(userKey, data), [queryClient])\n\n\t\treturn useMutation({\n\t\t\tmutationFn: logoutFn,\n\t\t\t...options,\n\t\t\tonSuccess: (...args) => {\n\t\t\t\tsetUser(null)\n\t\t\t\toptions?.onSuccess?.(...args)\n\t\t\t},\n\t\t})\n\t}\n\n\tfunction AuthLoader({\n\t\tchildren,\n\t\trenderLoading,\n\t\trenderUnauthenticated,\n\t\trenderError = (error: Error) => <>{JSON.stringify(error)}</>,\n\t}: {\n\t\tchildren: React.ReactNode\n\t\trenderLoading: () => React.ReactElement | null\n\t\trenderUnauthenticated?: () => React.ReactElement | null\n\t\trenderError?: (error: Error) => React.ReactElement | null\n\t}) {\n\t\tconst { isSuccess, isFetched, status, data, error } = useUser()\n\n\t\tif (isSuccess) {\n\t\t\tif (renderUnauthenticated && !data) {\n\t\t\t\treturn renderUnauthenticated()\n\t\t\t}\n\t\t\treturn <>{children}</>\n\t\t}\n\n\t\tif (!isFetched) {\n\t\t\treturn renderLoading()\n\t\t}\n\n\t\tif (status === 'error') {\n\t\t\treturn renderError(error)\n\t\t}\n\n\t\treturn null\n\t}\n\n\treturn {\n\t\tuseUser,\n\t\tuseLogin,\n\t\tuseRegister,\n\t\tuseLogout,\n\t\tAuthLoader,\n\t}\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
3
|
+
import { QueryFunction, QueryKey, MutationFunction, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
interface ReactQueryAuthConfig<User, LoginCredentials, RegisterCredentials> {
|
|
7
|
+
userFn: QueryFunction<User, QueryKey>;
|
|
8
|
+
loginFn: MutationFunction<User, LoginCredentials>;
|
|
9
|
+
registerFn: MutationFunction<User, RegisterCredentials>;
|
|
10
|
+
logoutFn: MutationFunction<unknown, unknown>;
|
|
11
|
+
userKey?: QueryKey;
|
|
12
|
+
}
|
|
13
|
+
interface AuthProviderProps {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
declare function configureAuth<User, Error, LoginCredentials, RegisterCredentials>(config: ReactQueryAuthConfig<User, LoginCredentials, RegisterCredentials>): {
|
|
17
|
+
useUser: (options?: Omit<UseQueryOptions<User, Error, User, QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<_tanstack_react_query.NoInfer<User>, Error>;
|
|
18
|
+
useLogin: (options?: Omit<UseMutationOptions<User, Error, LoginCredentials>, "mutationFn">) => _tanstack_react_query.UseMutationResult<User, Error, LoginCredentials, unknown>;
|
|
19
|
+
useRegister: (options?: Omit<UseMutationOptions<User, Error, RegisterCredentials>, "mutationFn">) => _tanstack_react_query.UseMutationResult<User, Error, RegisterCredentials, unknown>;
|
|
20
|
+
useLogout: (options?: UseMutationOptions<unknown, Error, unknown>) => _tanstack_react_query.UseMutationResult<unknown, Error, unknown, unknown>;
|
|
21
|
+
AuthLoader: ({ children, renderLoading, renderUnauthenticated, renderError, }: {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
renderLoading: () => React.ReactElement | null;
|
|
24
|
+
renderUnauthenticated?: () => React.ReactElement | null;
|
|
25
|
+
renderError?: (error: Error) => React.ReactElement | null;
|
|
26
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { type AuthProviderProps, type ReactQueryAuthConfig, configureAuth };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
3
|
+
import { QueryFunction, QueryKey, MutationFunction, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
interface ReactQueryAuthConfig<User, LoginCredentials, RegisterCredentials> {
|
|
7
|
+
userFn: QueryFunction<User, QueryKey>;
|
|
8
|
+
loginFn: MutationFunction<User, LoginCredentials>;
|
|
9
|
+
registerFn: MutationFunction<User, RegisterCredentials>;
|
|
10
|
+
logoutFn: MutationFunction<unknown, unknown>;
|
|
11
|
+
userKey?: QueryKey;
|
|
12
|
+
}
|
|
13
|
+
interface AuthProviderProps {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
declare function configureAuth<User, Error, LoginCredentials, RegisterCredentials>(config: ReactQueryAuthConfig<User, LoginCredentials, RegisterCredentials>): {
|
|
17
|
+
useUser: (options?: Omit<UseQueryOptions<User, Error, User, QueryKey>, "queryKey" | "queryFn">) => _tanstack_react_query.UseQueryResult<_tanstack_react_query.NoInfer<User>, Error>;
|
|
18
|
+
useLogin: (options?: Omit<UseMutationOptions<User, Error, LoginCredentials>, "mutationFn">) => _tanstack_react_query.UseMutationResult<User, Error, LoginCredentials, unknown>;
|
|
19
|
+
useRegister: (options?: Omit<UseMutationOptions<User, Error, RegisterCredentials>, "mutationFn">) => _tanstack_react_query.UseMutationResult<User, Error, RegisterCredentials, unknown>;
|
|
20
|
+
useLogout: (options?: UseMutationOptions<unknown, Error, unknown>) => _tanstack_react_query.UseMutationResult<unknown, Error, unknown, unknown>;
|
|
21
|
+
AuthLoader: ({ children, renderLoading, renderUnauthenticated, renderError, }: {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
renderLoading: () => React.ReactElement | null;
|
|
24
|
+
renderUnauthenticated?: () => React.ReactElement | null;
|
|
25
|
+
renderError?: (error: Error) => React.ReactElement | null;
|
|
26
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { type AuthProviderProps, type ReactQueryAuthConfig, configureAuth };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @opensourceframework/react-query-auth
|
|
7
|
+
* Authenticate your react applications easily with react-query
|
|
8
|
+
*
|
|
9
|
+
* @original-author Alan (alan2207)
|
|
10
|
+
* @original-repo https://github.com/alan2207/react-query-auth
|
|
11
|
+
* @license MIT
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
function configureAuth(config) {
|
|
15
|
+
const { userFn, userKey = ["authenticated-user"], loginFn, registerFn, logoutFn } = config;
|
|
16
|
+
const useUser = (options) => useQuery({
|
|
17
|
+
queryKey: userKey,
|
|
18
|
+
queryFn: userFn,
|
|
19
|
+
...options
|
|
20
|
+
});
|
|
21
|
+
const useLogin = (options) => {
|
|
22
|
+
const queryClient = useQueryClient();
|
|
23
|
+
const setUser = React.useCallback((data) => queryClient.setQueryData(userKey, data), [queryClient]);
|
|
24
|
+
return useMutation({
|
|
25
|
+
mutationFn: loginFn,
|
|
26
|
+
...options,
|
|
27
|
+
onSuccess: (user, ...rest) => {
|
|
28
|
+
setUser(user);
|
|
29
|
+
options?.onSuccess?.(user, ...rest);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
const useRegister = (options) => {
|
|
34
|
+
const queryClient = useQueryClient();
|
|
35
|
+
const setUser = React.useCallback((data) => queryClient.setQueryData(userKey, data), [queryClient]);
|
|
36
|
+
return useMutation({
|
|
37
|
+
mutationFn: registerFn,
|
|
38
|
+
...options,
|
|
39
|
+
onSuccess: (user, ...rest) => {
|
|
40
|
+
setUser(user);
|
|
41
|
+
options?.onSuccess?.(user, ...rest);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const useLogout = (options) => {
|
|
46
|
+
const queryClient = useQueryClient();
|
|
47
|
+
const setUser = React.useCallback((data) => queryClient.setQueryData(userKey, data), [queryClient]);
|
|
48
|
+
return useMutation({
|
|
49
|
+
mutationFn: logoutFn,
|
|
50
|
+
...options,
|
|
51
|
+
onSuccess: (...args) => {
|
|
52
|
+
setUser(null);
|
|
53
|
+
options?.onSuccess?.(...args);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
function AuthLoader({
|
|
58
|
+
children,
|
|
59
|
+
renderLoading,
|
|
60
|
+
renderUnauthenticated,
|
|
61
|
+
renderError = (error) => /* @__PURE__ */ jsx(Fragment, { children: JSON.stringify(error) })
|
|
62
|
+
}) {
|
|
63
|
+
const { isSuccess, isFetched, status, data, error } = useUser();
|
|
64
|
+
if (isSuccess) {
|
|
65
|
+
if (renderUnauthenticated && !data) {
|
|
66
|
+
return renderUnauthenticated();
|
|
67
|
+
}
|
|
68
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
69
|
+
}
|
|
70
|
+
if (!isFetched) {
|
|
71
|
+
return renderLoading();
|
|
72
|
+
}
|
|
73
|
+
if (status === "error") {
|
|
74
|
+
return renderError(error);
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
useUser,
|
|
80
|
+
useLogin,
|
|
81
|
+
useRegister,
|
|
82
|
+
useLogout,
|
|
83
|
+
AuthLoader
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { configureAuth };
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
89
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":"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","file":"index.js","sourcesContent":["import {\n\ttype MutationFunction,\n\ttype QueryFunction,\n\ttype QueryKey,\n\ttype UseMutationOptions,\n\ttype UseQueryOptions,\n\tuseMutation,\n\tuseQuery,\n\tuseQueryClient,\n} from '@tanstack/react-query'\nimport React from 'react'\n\nexport interface ReactQueryAuthConfig<User, LoginCredentials, RegisterCredentials> {\n\tuserFn: QueryFunction<User, QueryKey>\n\tloginFn: MutationFunction<User, LoginCredentials>\n\tregisterFn: MutationFunction<User, RegisterCredentials>\n\tlogoutFn: MutationFunction<unknown, unknown>\n\tuserKey?: QueryKey\n}\n\nexport interface AuthProviderProps {\n\tchildren: React.ReactNode\n}\n\nexport function configureAuth<User, Error, LoginCredentials, RegisterCredentials>(\n\tconfig: ReactQueryAuthConfig<User, LoginCredentials, RegisterCredentials>\n) {\n\tconst { userFn, userKey = ['authenticated-user'], loginFn, registerFn, logoutFn } = config\n\n\tconst useUser = (options?: Omit<UseQueryOptions<User, Error, User, QueryKey>, 'queryKey' | 'queryFn'>) =>\n\t\tuseQuery({\n\t\t\tqueryKey: userKey,\n\t\t\tqueryFn: userFn,\n\t\t\t...options,\n\t\t})\n\n\tconst useLogin = (options?: Omit<UseMutationOptions<User, Error, LoginCredentials>, 'mutationFn'>) => {\n\t\tconst queryClient = useQueryClient()\n\n\t\tconst setUser = React.useCallback((data: User) => queryClient.setQueryData(userKey, data), [queryClient])\n\n\t\treturn useMutation({\n\t\t\tmutationFn: loginFn,\n\t\t\t...options,\n\t\t\tonSuccess: (user, ...rest) => {\n\t\t\t\tsetUser(user)\n\t\t\t\toptions?.onSuccess?.(user, ...rest)\n\t\t\t},\n\t\t})\n\t}\n\n\tconst useRegister = (options?: Omit<UseMutationOptions<User, Error, RegisterCredentials>, 'mutationFn'>) => {\n\t\tconst queryClient = useQueryClient()\n\n\t\tconst setUser = React.useCallback((data: User) => queryClient.setQueryData(userKey, data), [queryClient])\n\n\t\treturn useMutation({\n\t\t\tmutationFn: registerFn,\n\t\t\t...options,\n\t\t\tonSuccess: (user, ...rest) => {\n\t\t\t\tsetUser(user)\n\t\t\t\toptions?.onSuccess?.(user, ...rest)\n\t\t\t},\n\t\t})\n\t}\n\n\tconst useLogout = (options?: UseMutationOptions<unknown, Error, unknown>) => {\n\t\tconst queryClient = useQueryClient()\n\n\t\tconst setUser = React.useCallback((data: User | null) => queryClient.setQueryData(userKey, data), [queryClient])\n\n\t\treturn useMutation({\n\t\t\tmutationFn: logoutFn,\n\t\t\t...options,\n\t\t\tonSuccess: (...args) => {\n\t\t\t\tsetUser(null)\n\t\t\t\toptions?.onSuccess?.(...args)\n\t\t\t},\n\t\t})\n\t}\n\n\tfunction AuthLoader({\n\t\tchildren,\n\t\trenderLoading,\n\t\trenderUnauthenticated,\n\t\trenderError = (error: Error) => <>{JSON.stringify(error)}</>,\n\t}: {\n\t\tchildren: React.ReactNode\n\t\trenderLoading: () => React.ReactElement | null\n\t\trenderUnauthenticated?: () => React.ReactElement | null\n\t\trenderError?: (error: Error) => React.ReactElement | null\n\t}) {\n\t\tconst { isSuccess, isFetched, status, data, error } = useUser()\n\n\t\tif (isSuccess) {\n\t\t\tif (renderUnauthenticated && !data) {\n\t\t\t\treturn renderUnauthenticated()\n\t\t\t}\n\t\t\treturn <>{children}</>\n\t\t}\n\n\t\tif (!isFetched) {\n\t\t\treturn renderLoading()\n\t\t}\n\n\t\tif (status === 'error') {\n\t\t\treturn renderError(error)\n\t\t}\n\n\t\treturn null\n\t}\n\n\treturn {\n\t\tuseUser,\n\t\tuseLogin,\n\t\tuseRegister,\n\t\tuseLogout,\n\t\tAuthLoader,\n\t}\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "@opensourceframework/react-query-auth",
|
|
4
|
+
"version": "2.4.3",
|
|
5
|
+
"description": "Authenticate your react applications easily with react-query",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react",
|
|
8
|
+
"reactjs",
|
|
9
|
+
"react-query",
|
|
10
|
+
"auth",
|
|
11
|
+
"authentication"
|
|
12
|
+
],
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"dev": "tsup --watch",
|
|
29
|
+
"lint": "biome check src",
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"test": "vitest run --passWithNoTests",
|
|
32
|
+
"test:watch": "vitest",
|
|
33
|
+
"test:coverage": "vitest run --coverage"
|
|
34
|
+
},
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/riceharvest/opensourceframework.git",
|
|
38
|
+
"directory": "packages/react-query-auth"
|
|
39
|
+
},
|
|
40
|
+
"author": "OpenSource Framework Contributors (fork), Original: Alan (alan2207)",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/riceharvest/opensourceframework/issues?q=is%3Aissue+is%3Aopen+react-query-auth"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/riceharvest/opensourceframework/tree/main/packages/react-query-auth#readme",
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@tanstack/react-query": "^5.0.0",
|
|
48
|
+
"@testing-library/react": "^16.0.0",
|
|
49
|
+
"@types/node": "^22.0.0",
|
|
50
|
+
"@types/react": "^19.0.0",
|
|
51
|
+
"@types/react-dom": "^19.0.0",
|
|
52
|
+
"react": "^19.0.0",
|
|
53
|
+
"react-dom": "^19.0.0",
|
|
54
|
+
"tsup": "^8.0.0",
|
|
55
|
+
"typescript": "^5.0.0",
|
|
56
|
+
"vitest": "^2.0.0"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@tanstack/react-query": ">=4.0.0",
|
|
60
|
+
"react": ">=16.8.0"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=18.0.0"
|
|
64
|
+
},
|
|
65
|
+
"contributors": [
|
|
66
|
+
{
|
|
67
|
+
"name": "Alan (alan2207)",
|
|
68
|
+
"url": "https://github.com/alan2207/react-query-auth"
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
},
|
|
74
|
+
"funding": {
|
|
75
|
+
"type": "GitHub",
|
|
76
|
+
"url": "https://github.com/sponsors/riceharvest"
|
|
77
|
+
}
|
|
78
|
+
}
|