@solidxai/core-ui 0.1.7-beta.6 → 0.1.7-beta.8
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/adapters/auth/helper.d.ts +9 -0
- package/dist/adapters/auth/helper.d.ts.map +1 -0
- package/dist/adapters/auth/helper.js +37 -0
- package/dist/adapters/auth/helper.js.map +1 -0
- package/dist/adapters/auth/helper.ts +45 -0
- package/dist/adapters/auth/signInWithOtp.d.ts.map +1 -1
- package/dist/adapters/auth/signInWithOtp.js +3 -27
- package/dist/adapters/auth/signInWithOtp.js.map +1 -1
- package/dist/adapters/auth/signInWithOtp.ts +3 -23
- package/dist/components/auth/SolidOTPVerify.d.ts +3 -0
- package/dist/components/auth/SolidOTPVerify.d.ts.map +1 -0
- package/dist/components/auth/SolidOTPVerify.js +67 -0
- package/dist/components/auth/SolidOTPVerify.js.map +1 -0
- package/dist/components/auth/SolidOTPVerify.tsx +133 -0
- package/dist/components/common/AuthBanner.js.map +1 -1
- package/dist/components/core/common/LoadDynamicJsxComponent.d.ts +2 -0
- package/dist/components/core/common/LoadDynamicJsxComponent.d.ts.map +1 -0
- package/dist/components/core/common/LoadDynamicJsxComponent.js +50 -0
- package/dist/components/core/common/LoadDynamicJsxComponent.js.map +1 -0
- package/dist/components/core/common/LoadDynamicJsxComponent.tsx +70 -0
- package/dist/components/core/kanban/SolidManyToOneFilterElement.d.ts.map +1 -1
- package/dist/components/core/kanban/SolidManyToOneFilterElement.js.map +1 -1
- package/dist/components/core/kanban/SolidManyToOneFilterElement.tsx +2 -1
- package/dist/components/core/kanban/kanban-fields/SolidMediaMultipleKanbanField.d.ts.map +1 -1
- package/dist/components/core/kanban/kanban-fields/SolidMediaMultipleKanbanField.js +2 -2
- package/dist/components/core/kanban/kanban-fields/SolidMediaMultipleKanbanField.js.map +1 -1
- package/dist/components/core/kanban/kanban-fields/SolidMediaMultipleKanbanField.tsx +10 -21
- package/dist/components/core/kanban/kanban-fields/SolidMediaSingleKanbanField.d.ts.map +1 -1
- package/dist/components/core/kanban/kanban-fields/SolidMediaSingleKanbanField.js +2 -2
- package/dist/components/core/kanban/kanban-fields/SolidMediaSingleKanbanField.js.map +1 -1
- package/dist/components/core/kanban/kanban-fields/SolidMediaSingleKanbanField.tsx +10 -18
- package/dist/components/core/kanban/kanban-fields/SolidShortTextKanbanField.d.ts.map +1 -1
- package/dist/components/core/kanban/kanban-fields/SolidShortTextKanbanField.js +6 -3
- package/dist/components/core/kanban/kanban-fields/SolidShortTextKanbanField.js.map +1 -1
- package/dist/components/core/kanban/kanban-fields/SolidShortTextKanbanField.tsx +24 -30
- package/dist/components/core/kanban/kanban-fields/relations/SolidRelationManyToOneKanbanField.js.map +1 -1
- package/dist/components/core/kanban/kanban-fields/relations/SolidRelationManyToOneKanbanField.tsx +2 -2
- package/dist/components/core/list/SolidListViewRowButtonContextMenu.d.ts +1 -1
- package/dist/components/core/list/SolidListViewRowButtonContextMenu.d.ts.map +1 -1
- package/dist/components/core/list/SolidListViewRowButtonContextMenu.js +7 -6
- package/dist/components/core/list/SolidListViewRowButtonContextMenu.js.map +1 -1
- package/dist/components/core/list/SolidListViewRowButtonContextMenu.tsx +10 -9
- package/dist/components/core/users/ApiKeysTab/ApiKeysTab.d.ts +7 -0
- package/dist/components/core/users/ApiKeysTab/ApiKeysTab.d.ts.map +1 -0
- package/dist/components/core/users/ApiKeysTab/ApiKeysTab.js +138 -0
- package/dist/components/core/users/ApiKeysTab/ApiKeysTab.js.map +1 -0
- package/dist/components/core/users/ApiKeysTab/ApiKeysTab.tsx +246 -0
- package/dist/components/core/users/ApiKeysTab/GenerateApiKeyModal.d.ts +8 -0
- package/dist/components/core/users/ApiKeysTab/GenerateApiKeyModal.d.ts.map +1 -0
- package/dist/components/core/users/ApiKeysTab/GenerateApiKeyModal.js +156 -0
- package/dist/components/core/users/ApiKeysTab/GenerateApiKeyModal.js.map +1 -0
- package/dist/components/core/users/ApiKeysTab/GenerateApiKeyModal.tsx +184 -0
- package/dist/components/core/users/ApiKeysTab/RevealApiKeyModal.d.ts +9 -0
- package/dist/components/core/users/ApiKeysTab/RevealApiKeyModal.d.ts.map +1 -0
- package/dist/components/core/users/ApiKeysTab/RevealApiKeyModal.js +37 -0
- package/dist/components/core/users/ApiKeysTab/RevealApiKeyModal.js.map +1 -0
- package/dist/components/core/users/ApiKeysTab/RevealApiKeyModal.tsx +111 -0
- package/dist/components/core/users/ApiKeysTab/index.d.ts +4 -0
- package/dist/components/core/users/ApiKeysTab/index.d.ts.map +1 -0
- package/dist/components/core/users/ApiKeysTab/index.js +4 -0
- package/dist/components/core/users/ApiKeysTab/index.js.map +1 -0
- package/dist/components/core/users/ApiKeysTab/index.ts +3 -0
- package/dist/helpers/# no such endpoints exist, need to calle +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/index.ts +1 -0
- package/dist/nextAuth/authProviders.d.ts +4 -0
- package/dist/nextAuth/authProviders.d.ts.map +1 -0
- package/dist/nextAuth/authProviders.js +198 -0
- package/dist/nextAuth/authProviders.js.map +1 -0
- package/dist/nextAuth/authProviders.tsx +232 -0
- package/dist/nextAuth/handleLogout.d.ts +2 -0
- package/dist/nextAuth/handleLogout.d.ts.map +1 -0
- package/dist/nextAuth/handleLogout.js +36 -0
- package/dist/nextAuth/handleLogout.js.map +1 -0
- package/dist/nextAuth/handleLogout.tsx +39 -0
- package/dist/nextAuth/refreshAccessToken.d.ts +2 -0
- package/dist/nextAuth/refreshAccessToken.d.ts.map +1 -0
- package/dist/nextAuth/refreshAccessToken.js +24 -0
- package/dist/nextAuth/refreshAccessToken.js.map +1 -0
- package/dist/nextAuth/refreshAccessToken.tsx +28 -0
- package/dist/redux/api/apiKeyApi.d.ts +40 -0
- package/dist/redux/api/apiKeyApi.d.ts.map +1 -0
- package/dist/redux/api/apiKeyApi.js +36 -0
- package/dist/redux/api/apiKeyApi.js.map +1 -0
- package/dist/redux/api/apiKeyApi.ts +60 -0
- package/dist/redux/features/settingsSlice.d.ts +20 -0
- package/dist/redux/features/settingsSlice.d.ts.map +1 -0
- package/dist/redux/features/settingsSlice.js +39 -0
- package/dist/redux/features/settingsSlice.js.map +1 -0
- package/dist/redux/features/settingsSlice.ts +60 -0
- package/dist/routes/guards/AuthGuard.d.ts +5 -1
- package/dist/routes/guards/AuthGuard.d.ts.map +1 -1
- package/dist/routes/guards/AuthGuard.js +13 -2
- package/dist/routes/guards/AuthGuard.js.map +1 -1
- package/dist/routes/guards/AuthGuard.tsx +27 -3
- package/package.json +1 -1
- package/dist/components/core/list/SolidDataTablePagination.d.ts +0 -15
- package/dist/components/core/list/SolidDataTablePagination.d.ts.map +0 -1
- package/dist/components/core/list/SolidDataTablePagination.js +0 -22
- package/dist/components/core/list/SolidDataTablePagination.js.map +0 -1
- package/dist/components/core/list/SolidDataTablePagination.tsx +0 -71
- package/dist/components/solid-ui/SolidButton.d.ts +0 -14
- package/dist/components/solid-ui/SolidButton.d.ts.map +0 -1
- package/dist/components/solid-ui/SolidButton.js +0 -36
- package/dist/components/solid-ui/SolidButton.js.map +0 -1
- package/dist/components/solid-ui/SolidButton.tsx +0 -54
- package/dist/components/solid-ui/SolidTabs.d.ts +0 -18
- package/dist/components/solid-ui/SolidTabs.d.ts.map +0 -1
- package/dist/components/solid-ui/SolidTabs.js +0 -22
- package/dist/components/solid-ui/SolidTabs.js.map +0 -1
- package/dist/components/solid-ui/SolidTabs.tsx +0 -73
- package/dist/components/solid-ui/index.d.ts +0 -3
- package/dist/components/solid-ui/index.d.ts.map +0 -1
- package/dist/components/solid-ui/index.js +0 -3
- package/dist/components/solid-ui/index.js.map +0 -1
- package/dist/components/solid-ui/index.ts +0 -2
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import CredentialsProvider from "next-auth/providers/credentials";
|
|
2
|
+
import GoogleProvider from "next-auth/providers/google";
|
|
3
|
+
import { NextRequest } from "next/server";
|
|
4
|
+
import { jwtDecode } from "jwt-decode";
|
|
5
|
+
import { JWT } from "next-auth/jwt";
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
import { signOut } from "next-auth/react";
|
|
8
|
+
import { refreshAccessToken } from "./refreshAccessToken";
|
|
9
|
+
import { NextAuthOptions } from "next-auth";
|
|
10
|
+
|
|
11
|
+
type Credentials = {
|
|
12
|
+
username: string,
|
|
13
|
+
email: string,
|
|
14
|
+
password: string,
|
|
15
|
+
identifier:string,
|
|
16
|
+
accessToken: string,
|
|
17
|
+
accessCode: string,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const authProviders: NextAuthOptions = {
|
|
21
|
+
session: {
|
|
22
|
+
strategy: "jwt",
|
|
23
|
+
},
|
|
24
|
+
providers: [
|
|
25
|
+
GoogleProvider({
|
|
26
|
+
clientId: process.env.GOOGLE_ID!,
|
|
27
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET!
|
|
28
|
+
}),
|
|
29
|
+
CredentialsProvider({
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
async authorize(credentials: Credentials, req: any) {
|
|
32
|
+
const userAgent = req.headers['user-agent'];
|
|
33
|
+
|
|
34
|
+
const { username, email, password, identifier, accessToken, accessCode } = credentials;
|
|
35
|
+
try {
|
|
36
|
+
if (accessCode) {
|
|
37
|
+
let config = {
|
|
38
|
+
method: 'get',
|
|
39
|
+
url: `${process.env.API_URL}/api/iam/google/authenticate?accessCode=${accessCode}`,
|
|
40
|
+
headers: {
|
|
41
|
+
'User-Agent': userAgent,
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const loginResponse = await axios.request(config);
|
|
45
|
+
if (loginResponse.status == 400) {
|
|
46
|
+
throw new Error(loginResponse.data.message);
|
|
47
|
+
}
|
|
48
|
+
if (loginResponse.status == 401) {
|
|
49
|
+
throw new Error(loginResponse.data.message);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let base64decoded = jwtDecode(loginResponse.data.data.accessToken);
|
|
53
|
+
// let accessTokenExpires = base64decoded.exp;
|
|
54
|
+
let accessTokenExpires = base64decoded.exp && base64decoded.exp * 1000;
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
accessToken: loginResponse.data.data.accessToken,
|
|
58
|
+
refreshToken: loginResponse.data.data.refreshToken,
|
|
59
|
+
accessTokenExpires: accessTokenExpires,
|
|
60
|
+
...loginResponse.data.data,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
} else {
|
|
64
|
+
if (accessToken) {
|
|
65
|
+
let data = JSON.stringify({
|
|
66
|
+
username: identifier,
|
|
67
|
+
email: identifier.includes('@')? identifier : null,
|
|
68
|
+
password: password
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
let config = {
|
|
72
|
+
method: 'get',
|
|
73
|
+
url: `${process.env.API_URL}/api/iam/me`,
|
|
74
|
+
headers: {
|
|
75
|
+
'accept': '*/*',
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
'Authorization': `Bearer ${accessToken}`
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const loginResponse = await axios.request(config);
|
|
83
|
+
|
|
84
|
+
if (loginResponse.status == 400) {
|
|
85
|
+
throw new Error(loginResponse.data.message);
|
|
86
|
+
}
|
|
87
|
+
if (loginResponse.status == 401) {
|
|
88
|
+
throw new Error(loginResponse.data.message);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let base64decoded = jwtDecode(accessToken);
|
|
92
|
+
// let accessTokenExpires = base64decoded.exp;
|
|
93
|
+
let accessTokenExpires = base64decoded.exp && base64decoded.exp * 1000;
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
accessToken: accessToken,
|
|
97
|
+
refreshToken: loginResponse.data.data.refreshToken,
|
|
98
|
+
accessTokenExpires: accessTokenExpires,
|
|
99
|
+
...loginResponse.data.data,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
} else {
|
|
103
|
+
|
|
104
|
+
let data = JSON.stringify({
|
|
105
|
+
username: identifier,
|
|
106
|
+
email: identifier.includes('@')? identifier : null,
|
|
107
|
+
password: password
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
let config = {
|
|
111
|
+
method: 'post',
|
|
112
|
+
maxBodyLength: Infinity,
|
|
113
|
+
url: `${process.env.API_URL}/api/iam/authenticate`,
|
|
114
|
+
headers: {
|
|
115
|
+
'accept': '*/*',
|
|
116
|
+
'Content-Type': 'application/json',
|
|
117
|
+
'User-Agent': userAgent,
|
|
118
|
+
},
|
|
119
|
+
data: data
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
const loginResponse = await axios.request(config);
|
|
124
|
+
|
|
125
|
+
// const authenticateResponse = await fetch(
|
|
126
|
+
// `${process.env.API_URL}/api/iam/authenticate`,
|
|
127
|
+
// {
|
|
128
|
+
// method: "Post",
|
|
129
|
+
// headers: {
|
|
130
|
+
// 'accept': '*/*',
|
|
131
|
+
// "Content-Type": "application/json"
|
|
132
|
+
// },
|
|
133
|
+
// body: JSON.stringify({
|
|
134
|
+
// username: email,
|
|
135
|
+
// email: email,
|
|
136
|
+
// password: password
|
|
137
|
+
// })
|
|
138
|
+
// }
|
|
139
|
+
// );
|
|
140
|
+
|
|
141
|
+
// const loginResponse = await authenticateResponse.json();
|
|
142
|
+
|
|
143
|
+
// const response = await fetch(
|
|
144
|
+
// `${process.env.API_URL}/api/iam/me`,
|
|
145
|
+
// {
|
|
146
|
+
// method: "Get",
|
|
147
|
+
// headers: {
|
|
148
|
+
// "Content-Type": "application/json",
|
|
149
|
+
// "Authorization": `Bearer ${loginResponse.data.accessToken}`,
|
|
150
|
+
// },
|
|
151
|
+
// }
|
|
152
|
+
// );
|
|
153
|
+
|
|
154
|
+
// const responseData = await response.json();
|
|
155
|
+
|
|
156
|
+
if (loginResponse.status == 400) {
|
|
157
|
+
throw new Error(loginResponse.data.message);
|
|
158
|
+
}
|
|
159
|
+
if (loginResponse.status == 401) {
|
|
160
|
+
throw new Error(loginResponse.data.data.message);
|
|
161
|
+
}
|
|
162
|
+
let base64decoded = jwtDecode(loginResponse.data.data.accessToken);
|
|
163
|
+
// let accessTokenExpires = base64decoded.exp;
|
|
164
|
+
let accessTokenExpires = base64decoded.exp && base64decoded.exp * 1000;
|
|
165
|
+
const returnResponse = {
|
|
166
|
+
accessToken: loginResponse.data.data.accessToken,
|
|
167
|
+
refreshToken: loginResponse.data.data.refreshToken,
|
|
168
|
+
accessTokenExpires: accessTokenExpires,
|
|
169
|
+
...loginResponse.data.data,
|
|
170
|
+
}
|
|
171
|
+
return returnResponse;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} catch (error: any) {
|
|
175
|
+
throw new Error(error?.response?.data?.message);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
],
|
|
180
|
+
callbacks: {
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
jwt: async ({ token, user }) => {
|
|
183
|
+
// console.log("JWT callback called");
|
|
184
|
+
const bufferTime = 60000;
|
|
185
|
+
if (Date.now() >= (token.accessTokenExpires as number - bufferTime)) {
|
|
186
|
+
// Call the refresh token function
|
|
187
|
+
return await refreshAccessToken(token);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// If there is no user (first time login or session), we return the user data
|
|
191
|
+
if (user) {
|
|
192
|
+
// const base64decoded = jwtDecode(user.accessToken);
|
|
193
|
+
// Convert from seconds to milliseconds
|
|
194
|
+
// const accessTokenExpires = base64decoded.exp && base64decoded.exp * 1000;
|
|
195
|
+
// const accessTokenExpires = user.accessTokenExpires * 1000;
|
|
196
|
+
return {
|
|
197
|
+
...token,
|
|
198
|
+
accessToken: user.accessToken,
|
|
199
|
+
refreshToken: user.refreshToken,
|
|
200
|
+
accessTokenExpires: user.accessTokenExpires,
|
|
201
|
+
user: user, // Include the user data here
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return token; // If no update needed, just return the existing token
|
|
206
|
+
},
|
|
207
|
+
// @ts-ignore
|
|
208
|
+
session: async ({ session, token }) => {
|
|
209
|
+
// console.log("Session callback called");
|
|
210
|
+
|
|
211
|
+
const user = token.user || {}; // Default to an empty object if user is undefined or null
|
|
212
|
+
session.error = token.error ? token.error : null;
|
|
213
|
+
// if (token.error) {
|
|
214
|
+
// return null
|
|
215
|
+
// }
|
|
216
|
+
session.user = {
|
|
217
|
+
...user, // Include the user info from the token
|
|
218
|
+
accessToken: token?.accessToken, // Add the access token to session for client use
|
|
219
|
+
refreshToken: token?.refreshToken, // Add refresh token to session for future use
|
|
220
|
+
accessTokenExpires: token?.accessTokenExpires && token?.accessTokenExpires, // Store the expiry time
|
|
221
|
+
};
|
|
222
|
+
return session;
|
|
223
|
+
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
pages: {
|
|
227
|
+
signIn: "/auth/login",
|
|
228
|
+
},
|
|
229
|
+
secret: process.env.NEXTAUTH_SECRET,
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export default authProviders
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleLogout.d.ts","sourceRoot":"./","sources":["nextAuth/handleLogout.tsx"],"names":[],"mappings":"AAIA,wBAAsB,YAAY,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,iBAkChD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ERROR_MESSAGES } from '../constants/error-messages';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { getSession, signOut } from 'next-auth/react';
|
|
4
|
+
export async function handleLogout({ toast }) {
|
|
5
|
+
const session = await getSession();
|
|
6
|
+
// const token = session?.user?.accessToken;
|
|
7
|
+
const refreshToken = session?.user?.refreshToken;
|
|
8
|
+
try {
|
|
9
|
+
const response = await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/iam/logout`, {
|
|
10
|
+
refreshToken: refreshToken, // Pass refresh token in body
|
|
11
|
+
});
|
|
12
|
+
console.log("logout response", response);
|
|
13
|
+
if (response?.data?.statusCode === 200) {
|
|
14
|
+
await signOut({ callbackUrl: '/auth/login' });
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
toast?.current?.show({
|
|
18
|
+
severity: 'error',
|
|
19
|
+
summary: ERROR_MESSAGES.LOGOUT_FAILED,
|
|
20
|
+
detail: `${response?.data?.data?.status}`,
|
|
21
|
+
life: 3000,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
const err = error;
|
|
27
|
+
const message = err.response?.data?.data?.message || err.message || ERROR_MESSAGES.LOGOUT_FAILED;
|
|
28
|
+
toast?.current?.show({
|
|
29
|
+
severity: 'error',
|
|
30
|
+
summary: ERROR_MESSAGES.LOGOUT_FAILED,
|
|
31
|
+
detail: message,
|
|
32
|
+
life: 3000,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=handleLogout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleLogout.js","sourceRoot":"./","sources":["nextAuth/handleLogout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAqB,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,EAAE,KAAK,EAAO;IAC7C,MAAM,OAAO,GAAG,MAAM,UAAU,EAAE,CAAC;IACnC,4CAA4C;IAC5C,MAAM,YAAY,GAAG,OAAO,EAAE,IAAI,EAAE,YAAY,CAAC;IACjD,IAAI;QACA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,2BAA2B,iBAAiB,EAC7F;YACI,YAAY,EAAE,YAAY,EAAE,6BAA6B;SAC5D,CACA,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QAEzC,IAAI,QAAQ,EAAE,IAAI,EAAE,UAAU,KAAK,GAAG,EAAE;YACpC,MAAM,OAAO,CAAC,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,CAAC;SACjD;aAAM;YACH,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC;gBACjB,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,cAAc,CAAC,aAAa;gBACrC,MAAM,EAAE,GAAG,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;gBACzC,IAAI,EAAE,IAAI;aACb,CAAC,CAAC;SACN;KACJ;IAAC,OAAO,KAAK,EAAE;QACZ,MAAM,GAAG,GAAG,KAAY,CAAC;QACzB,MAAM,OAAO,GACT,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,IAAI,GAAG,CAAC,OAAO,IAAI,cAAc,CAAC,aAAa,CAAC;QAErF,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC;YACjB,QAAQ,EAAE,OAAO;YACjB,OAAO,EAAE,cAAc,CAAC,aAAa;YACrC,MAAM,EAAE,OAAO;YACf,IAAI,EAAE,IAAI;SACb,CAAC,CAAC;KACN;AACL,CAAC","sourcesContent":["import { ERROR_MESSAGES } from '../constants/error-messages';\nimport axios, { AxiosError } from 'axios';\nimport { getSession, signOut } from 'next-auth/react';\n\nexport async function handleLogout({ toast }: any) {\n const session = await getSession();\n // const token = session?.user?.accessToken;\n const refreshToken = session?.user?.refreshToken; \n try {\n const response = await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/iam/logout`, \n {\n refreshToken: refreshToken, // Pass refresh token in body\n }\n );\n console.log(\"logout response\", response);\n\n if (response?.data?.statusCode === 200) {\n await signOut({ callbackUrl: '/auth/login' });\n } else {\n toast?.current?.show({\n severity: 'error',\n summary: ERROR_MESSAGES.LOGOUT_FAILED,\n detail: `${response?.data?.data?.status}`,\n life: 3000,\n });\n }\n } catch (error) {\n const err = error as any;\n const message =\n err.response?.data?.data?.message || err.message || ERROR_MESSAGES.LOGOUT_FAILED;\n\n toast?.current?.show({\n severity: 'error',\n summary: ERROR_MESSAGES.LOGOUT_FAILED,\n detail: message,\n life: 3000,\n });\n }\n}"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ERROR_MESSAGES } from '../constants/error-messages';
|
|
2
|
+
import axios, { AxiosError } from 'axios';
|
|
3
|
+
import { getSession, signOut } from 'next-auth/react';
|
|
4
|
+
|
|
5
|
+
export async function handleLogout({ toast }: any) {
|
|
6
|
+
const session = await getSession();
|
|
7
|
+
// const token = session?.user?.accessToken;
|
|
8
|
+
const refreshToken = session?.user?.refreshToken;
|
|
9
|
+
try {
|
|
10
|
+
const response = await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/iam/logout`,
|
|
11
|
+
{
|
|
12
|
+
refreshToken: refreshToken, // Pass refresh token in body
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
console.log("logout response", response);
|
|
16
|
+
|
|
17
|
+
if (response?.data?.statusCode === 200) {
|
|
18
|
+
await signOut({ callbackUrl: '/auth/login' });
|
|
19
|
+
} else {
|
|
20
|
+
toast?.current?.show({
|
|
21
|
+
severity: 'error',
|
|
22
|
+
summary: ERROR_MESSAGES.LOGOUT_FAILED,
|
|
23
|
+
detail: `${response?.data?.data?.status}`,
|
|
24
|
+
life: 3000,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
} catch (error) {
|
|
28
|
+
const err = error as any;
|
|
29
|
+
const message =
|
|
30
|
+
err.response?.data?.data?.message || err.message || ERROR_MESSAGES.LOGOUT_FAILED;
|
|
31
|
+
|
|
32
|
+
toast?.current?.show({
|
|
33
|
+
severity: 'error',
|
|
34
|
+
summary: ERROR_MESSAGES.LOGOUT_FAILED,
|
|
35
|
+
detail: message,
|
|
36
|
+
life: 3000,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refreshAccessToken.d.ts","sourceRoot":"./","sources":["nextAuth/refreshAccessToken.tsx"],"names":[],"mappings":"AAIA,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,GAAG,gBAuBhD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ERROR_MESSAGES } from "../constants/error-messages";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { jwtDecode } from "jwt-decode";
|
|
4
|
+
export async function refreshAccessToken(token) {
|
|
5
|
+
try {
|
|
6
|
+
const response = await axios.post(`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/iam/refresh-tokens`, { refreshToken: token.refreshToken });
|
|
7
|
+
const { accessToken, refreshToken } = response.data.data;
|
|
8
|
+
const { exp: accessTokenExpires } = jwtDecode(accessToken);
|
|
9
|
+
return {
|
|
10
|
+
...token,
|
|
11
|
+
accessToken,
|
|
12
|
+
refreshToken,
|
|
13
|
+
accessTokenExpires: accessTokenExpires * 1000, // Convert seconds to milliseconds
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.error(ERROR_MESSAGES.FAILED_REFRESH_TOKEN, error.message || error.response?.data);
|
|
18
|
+
return {
|
|
19
|
+
// ...token,
|
|
20
|
+
error: "RefreshAccessTokenError",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=refreshAccessToken.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refreshAccessToken.js","sourceRoot":"./","sources":["nextAuth/refreshAccessToken.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,KAAU;IAC/C,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAC/B,GAAG,OAAO,CAAC,GAAG,CAAC,2BAA2B,yBAAyB,EACnE,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CACrC,CAAC;QAEF,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;QACzD,MAAM,EAAE,GAAG,EAAE,kBAAkB,EAAE,GAAG,SAAS,CAAkB,WAAW,CAAC,CAAC;QAE5E,OAAO;YACL,GAAG,KAAK;YACR,WAAW;YACX,YAAY;YACZ,kBAAkB,EAAE,kBAAkB,GAAG,IAAI,EAAE,kCAAkC;SAClF,CAAC;KACH;IAAC,OAAO,KAAU,EAAE;QACnB,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,oBAAoB,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC1F,OAAO;YACL,YAAY;YACZ,KAAK,EAAE,yBAAyB;SACjC,CAAC;KACH;AACH,CAAC","sourcesContent":["import { ERROR_MESSAGES } from \"../constants/error-messages\";\nimport axios from \"axios\";\nimport { jwtDecode } from \"jwt-decode\";\n\nexport async function refreshAccessToken(token: any) {\n try {\n const response = await axios.post(\n `${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/iam/refresh-tokens`,\n { refreshToken: token.refreshToken }\n );\n \n const { accessToken, refreshToken } = response.data.data;\n const { exp: accessTokenExpires } = jwtDecode<{ exp: number }>(accessToken);\n \n return {\n ...token,\n accessToken,\n refreshToken,\n accessTokenExpires: accessTokenExpires * 1000, // Convert seconds to milliseconds\n };\n } catch (error: any) {\n console.error(ERROR_MESSAGES.FAILED_REFRESH_TOKEN, error.message || error.response?.data);\n return {\n // ...token,\n error: \"RefreshAccessTokenError\",\n };\n }\n }"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ERROR_MESSAGES } from "../constants/error-messages";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { jwtDecode } from "jwt-decode";
|
|
4
|
+
|
|
5
|
+
export async function refreshAccessToken(token: any) {
|
|
6
|
+
try {
|
|
7
|
+
const response = await axios.post(
|
|
8
|
+
`${process.env.NEXT_PUBLIC_BACKEND_API_URL}/api/iam/refresh-tokens`,
|
|
9
|
+
{ refreshToken: token.refreshToken }
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const { accessToken, refreshToken } = response.data.data;
|
|
13
|
+
const { exp: accessTokenExpires } = jwtDecode<{ exp: number }>(accessToken);
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
...token,
|
|
17
|
+
accessToken,
|
|
18
|
+
refreshToken,
|
|
19
|
+
accessTokenExpires: accessTokenExpires * 1000, // Convert seconds to milliseconds
|
|
20
|
+
};
|
|
21
|
+
} catch (error: any) {
|
|
22
|
+
console.error(ERROR_MESSAGES.FAILED_REFRESH_TOKEN, error.message || error.response?.data);
|
|
23
|
+
return {
|
|
24
|
+
// ...token,
|
|
25
|
+
error: "RefreshAccessTokenError",
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface ApiKeyRecord {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
maskedKey: string;
|
|
5
|
+
isActive: boolean;
|
|
6
|
+
expiresAt: string | null;
|
|
7
|
+
lastUsedAt: string | null;
|
|
8
|
+
createdAt: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CreateApiKeyBody {
|
|
11
|
+
name: string;
|
|
12
|
+
expiresAt?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CreateApiKeyResponse {
|
|
15
|
+
data: {
|
|
16
|
+
apiKey: string;
|
|
17
|
+
record: ApiKeyRecord;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare const apiKeyApi: import("@reduxjs/toolkit/query/react").Api<import("@reduxjs/toolkit/query/react").BaseQueryFn<string | import("@reduxjs/toolkit/query/react").FetchArgs, unknown, import("@reduxjs/toolkit/query/react").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query/react").FetchBaseQueryMeta>, {
|
|
21
|
+
getUserApiKeys: import("@reduxjs/toolkit/query/react").QueryDefinition<string, import("@reduxjs/toolkit/query/react").BaseQueryFn<string | import("@reduxjs/toolkit/query/react").FetchArgs, unknown, import("@reduxjs/toolkit/query/react").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query/react").FetchBaseQueryMeta>, "ApiKey", {
|
|
22
|
+
data: {
|
|
23
|
+
apiKeys: ApiKeyRecord[];
|
|
24
|
+
};
|
|
25
|
+
}, "apiKeyApi">;
|
|
26
|
+
createApiKey: import("@reduxjs/toolkit/query/react").MutationDefinition<CreateApiKeyBody, import("@reduxjs/toolkit/query/react").BaseQueryFn<string | import("@reduxjs/toolkit/query/react").FetchArgs, unknown, import("@reduxjs/toolkit/query/react").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query/react").FetchBaseQueryMeta>, "ApiKey", CreateApiKeyResponse, "apiKeyApi">;
|
|
27
|
+
updateApiKey: import("@reduxjs/toolkit/query/react").MutationDefinition<{
|
|
28
|
+
id: string;
|
|
29
|
+
isActive: boolean;
|
|
30
|
+
}, import("@reduxjs/toolkit/query/react").BaseQueryFn<string | import("@reduxjs/toolkit/query/react").FetchArgs, unknown, import("@reduxjs/toolkit/query/react").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query/react").FetchBaseQueryMeta>, "ApiKey", void, "apiKeyApi">;
|
|
31
|
+
}, "apiKeyApi", "ApiKey", typeof import("@reduxjs/toolkit/query/react").coreModuleName | typeof import("@reduxjs/toolkit/query/react").reactHooksModuleName>;
|
|
32
|
+
export declare const useGetUserApiKeysQuery: import("@reduxjs/toolkit/dist/query/react/buildHooks").UseQuery<import("@reduxjs/toolkit/query/react").QueryDefinition<string, import("@reduxjs/toolkit/query/react").BaseQueryFn<string | import("@reduxjs/toolkit/query/react").FetchArgs, unknown, import("@reduxjs/toolkit/query/react").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query/react").FetchBaseQueryMeta>, "ApiKey", {
|
|
33
|
+
data: {
|
|
34
|
+
apiKeys: ApiKeyRecord[];
|
|
35
|
+
};
|
|
36
|
+
}, "apiKeyApi">>, useCreateApiKeyMutation: import("@reduxjs/toolkit/dist/query/react/buildHooks").UseMutation<import("@reduxjs/toolkit/query/react").MutationDefinition<CreateApiKeyBody, import("@reduxjs/toolkit/query/react").BaseQueryFn<string | import("@reduxjs/toolkit/query/react").FetchArgs, unknown, import("@reduxjs/toolkit/query/react").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query/react").FetchBaseQueryMeta>, "ApiKey", CreateApiKeyResponse, "apiKeyApi">>, useUpdateApiKeyMutation: import("@reduxjs/toolkit/dist/query/react/buildHooks").UseMutation<import("@reduxjs/toolkit/query/react").MutationDefinition<{
|
|
37
|
+
id: string;
|
|
38
|
+
isActive: boolean;
|
|
39
|
+
}, import("@reduxjs/toolkit/query/react").BaseQueryFn<string | import("@reduxjs/toolkit/query/react").FetchArgs, unknown, import("@reduxjs/toolkit/query/react").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query/react").FetchBaseQueryMeta>, "ApiKey", void, "apiKeyApi">>;
|
|
40
|
+
//# sourceMappingURL=apiKeyApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiKeyApi.d.ts","sourceRoot":"","sources":["../../../src/redux/api/apiKeyApi.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE;QACJ,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,YAAY,CAAC;KACtB,CAAC;CACH;AAED,eAAO,MAAM,SAAS;;cAOoB;YAAE,OAAO,EAAE,YAAY,EAAE,CAAA;SAAE;;;;YAYtB,MAAM;kBAAY,OAAO;;4JAStE,CAAC;AAEH,eAAO,MACL,sBAAsB;UAxBkB;QAAE,OAAO,EAAE,YAAY,EAAE,CAAA;KAAE;kBAyBnE,uBAAuB,mbACvB,uBAAuB;QAdsB,MAAM;cAAY,OAAO;mRAe3D,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createApi } from "@reduxjs/toolkit/query/react";
|
|
2
|
+
import { baseQueryWithAuth } from "./fetchBaseQuery";
|
|
3
|
+
export var apiKeyApi = createApi({
|
|
4
|
+
reducerPath: "apiKeyApi",
|
|
5
|
+
baseQuery: baseQueryWithAuth,
|
|
6
|
+
tagTypes: ["ApiKey"],
|
|
7
|
+
endpoints: function (builder) { return ({
|
|
8
|
+
// Fetch user record with apiKeys populated.
|
|
9
|
+
// Always called with a userId — the backend enforces access rules.
|
|
10
|
+
getUserApiKeys: builder.query({
|
|
11
|
+
query: function (userId) { return "/user/".concat(userId, "?populate[0]=apiKeys"); },
|
|
12
|
+
providesTags: ["ApiKey"],
|
|
13
|
+
}),
|
|
14
|
+
createApiKey: builder.mutation({
|
|
15
|
+
query: function (body) { return ({
|
|
16
|
+
url: "/iam/api-keys",
|
|
17
|
+
method: "POST",
|
|
18
|
+
body: body,
|
|
19
|
+
}); },
|
|
20
|
+
invalidatesTags: ["ApiKey"],
|
|
21
|
+
}),
|
|
22
|
+
updateApiKey: builder.mutation({
|
|
23
|
+
query: function (_a) {
|
|
24
|
+
var id = _a.id, isActive = _a.isActive;
|
|
25
|
+
return ({
|
|
26
|
+
url: "/iam/api-keys/".concat(id),
|
|
27
|
+
method: "PATCH",
|
|
28
|
+
body: { isActive: isActive },
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
invalidatesTags: ["ApiKey"],
|
|
32
|
+
}),
|
|
33
|
+
}); },
|
|
34
|
+
});
|
|
35
|
+
export var useGetUserApiKeysQuery = apiKeyApi.useGetUserApiKeysQuery, useCreateApiKeyMutation = apiKeyApi.useCreateApiKeyMutation, useUpdateApiKeyMutation = apiKeyApi.useUpdateApiKeyMutation;
|
|
36
|
+
//# sourceMappingURL=apiKeyApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apiKeyApi.js","sourceRoot":"","sources":["../../../src/redux/api/apiKeyApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAwBrD,MAAM,CAAC,IAAM,SAAS,GAAG,SAAS,CAAC;IACjC,WAAW,EAAE,WAAW;IACxB,SAAS,EAAE,iBAAiB;IAC5B,QAAQ,EAAE,CAAC,QAAQ,CAAC;IACpB,SAAS,EAAE,UAAC,OAAO,IAAK,OAAA,CAAC;QACvB,4CAA4C;QAC5C,mEAAmE;QACnE,cAAc,EAAE,OAAO,CAAC,KAAK,CAAgD;YAC3E,KAAK,EAAE,UAAC,MAAM,IAAK,OAAA,gBAAS,MAAM,yBAAsB,EAArC,CAAqC;YACxD,YAAY,EAAE,CAAC,QAAQ,CAAC;SACzB,CAAC;QACF,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAyC;YACrE,KAAK,EAAE,UAAC,IAAI,IAAK,OAAA,CAAC;gBAChB,GAAG,EAAE,eAAe;gBACpB,MAAM,EAAE,MAAM;gBACd,IAAI,MAAA;aACL,CAAC,EAJe,CAIf;YACF,eAAe,EAAE,CAAC,QAAQ,CAAC;SAC5B,CAAC;QACF,YAAY,EAAE,OAAO,CAAC,QAAQ,CAA0C;YACtE,KAAK,EAAE,UAAC,EAAgB;oBAAd,EAAE,QAAA,EAAE,QAAQ,cAAA;gBAAO,OAAA,CAAC;oBAC5B,GAAG,EAAE,wBAAiB,EAAE,CAAE;oBAC1B,MAAM,EAAE,OAAO;oBACf,IAAI,EAAE,EAAE,QAAQ,UAAA,EAAE;iBACnB,CAAC;YAJ2B,CAI3B;YACF,eAAe,EAAE,CAAC,QAAQ,CAAC;SAC5B,CAAC;KACH,CAAC,EAvBsB,CAuBtB;CACH,CAAC,CAAC;AAEH,MAAM,CACJ,IAAA,sBAAsB,GAGpB,SAAS,uBAHW,EACtB,uBAAuB,GAErB,SAAS,wBAFY,EACvB,uBAAuB,GACrB,SAAS,wBADY,CACX","sourcesContent":["import { createApi } from \"@reduxjs/toolkit/query/react\";\nimport { baseQueryWithAuth } from \"./fetchBaseQuery\";\n\nexport interface ApiKeyRecord {\n id: string;\n name: string;\n maskedKey: string;\n isActive: boolean;\n expiresAt: string | null;\n lastUsedAt: string | null;\n createdAt: string;\n}\n\nexport interface CreateApiKeyBody {\n name: string;\n expiresAt?: string;\n}\n\nexport interface CreateApiKeyResponse {\n data: {\n apiKey: string;\n record: ApiKeyRecord;\n };\n}\n\nexport const apiKeyApi = createApi({\n reducerPath: \"apiKeyApi\",\n baseQuery: baseQueryWithAuth,\n tagTypes: [\"ApiKey\"],\n endpoints: (builder) => ({\n // Fetch user record with apiKeys populated.\n // Always called with a userId — the backend enforces access rules.\n getUserApiKeys: builder.query<{ data: { apiKeys: ApiKeyRecord[] } }, string>({\n query: (userId) => `/user/${userId}?populate[0]=apiKeys`,\n providesTags: [\"ApiKey\"],\n }),\n createApiKey: builder.mutation<CreateApiKeyResponse, CreateApiKeyBody>({\n query: (body) => ({\n url: \"/iam/api-keys\",\n method: \"POST\",\n body,\n }),\n invalidatesTags: [\"ApiKey\"],\n }),\n updateApiKey: builder.mutation<void, { id: string; isActive: boolean }>({\n query: ({ id, isActive }) => ({\n url: `/iam/api-keys/${id}`,\n method: \"PATCH\",\n body: { isActive },\n }),\n invalidatesTags: [\"ApiKey\"],\n }),\n }),\n});\n\nexport const {\n useGetUserApiKeysQuery,\n useCreateApiKeyMutation,\n useUpdateApiKeyMutation,\n} = apiKeyApi;\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { createApi } from "@reduxjs/toolkit/query/react";
|
|
2
|
+
import { baseQueryWithAuth } from "./fetchBaseQuery";
|
|
3
|
+
|
|
4
|
+
export interface ApiKeyRecord {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
maskedKey: string;
|
|
8
|
+
isActive: boolean;
|
|
9
|
+
expiresAt: string | null;
|
|
10
|
+
lastUsedAt: string | null;
|
|
11
|
+
createdAt: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CreateApiKeyBody {
|
|
15
|
+
name: string;
|
|
16
|
+
expiresAt?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CreateApiKeyResponse {
|
|
20
|
+
data: {
|
|
21
|
+
apiKey: string;
|
|
22
|
+
record: ApiKeyRecord;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const apiKeyApi = createApi({
|
|
27
|
+
reducerPath: "apiKeyApi",
|
|
28
|
+
baseQuery: baseQueryWithAuth,
|
|
29
|
+
tagTypes: ["ApiKey"],
|
|
30
|
+
endpoints: (builder) => ({
|
|
31
|
+
// Fetch user record with apiKeys populated.
|
|
32
|
+
// Always called with a userId — the backend enforces access rules.
|
|
33
|
+
getUserApiKeys: builder.query<{ data: { apiKeys: ApiKeyRecord[] } }, string>({
|
|
34
|
+
query: (userId) => `/user/${userId}?populate[0]=apiKeys`,
|
|
35
|
+
providesTags: ["ApiKey"],
|
|
36
|
+
}),
|
|
37
|
+
createApiKey: builder.mutation<CreateApiKeyResponse, CreateApiKeyBody>({
|
|
38
|
+
query: (body) => ({
|
|
39
|
+
url: "/iam/api-keys",
|
|
40
|
+
method: "POST",
|
|
41
|
+
body,
|
|
42
|
+
}),
|
|
43
|
+
invalidatesTags: ["ApiKey"],
|
|
44
|
+
}),
|
|
45
|
+
updateApiKey: builder.mutation<void, { id: string; isActive: boolean }>({
|
|
46
|
+
query: ({ id, isActive }) => ({
|
|
47
|
+
url: `/iam/api-keys/${id}`,
|
|
48
|
+
method: "PATCH",
|
|
49
|
+
body: { isActive },
|
|
50
|
+
}),
|
|
51
|
+
invalidatesTags: ["ApiKey"],
|
|
52
|
+
}),
|
|
53
|
+
}),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const {
|
|
57
|
+
useGetUserApiKeysQuery,
|
|
58
|
+
useCreateApiKeyMutation,
|
|
59
|
+
useUpdateApiKeyMutation,
|
|
60
|
+
} = apiKeyApi;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PayloadAction } from "@reduxjs/toolkit";
|
|
2
|
+
export interface ISettingsState {
|
|
3
|
+
authSettings: Record<string, any>;
|
|
4
|
+
solidSettings: Record<string, any>;
|
|
5
|
+
}
|
|
6
|
+
export declare const settingsSlice: import("@reduxjs/toolkit").Slice<ISettingsState, {
|
|
7
|
+
setSolidSettings: (state: import("immer/dist/internal.js").WritableDraft<ISettingsState>, action: PayloadAction<Record<string, any>>) => void;
|
|
8
|
+
updateSolidSetting: (state: import("immer/dist/internal.js").WritableDraft<ISettingsState>, action: PayloadAction<{
|
|
9
|
+
key: string;
|
|
10
|
+
value: any;
|
|
11
|
+
}>) => void;
|
|
12
|
+
resetSettings: () => ISettingsState;
|
|
13
|
+
}, "settingsSlice">;
|
|
14
|
+
declare const _default: import("@reduxjs/toolkit").Reducer<ISettingsState>;
|
|
15
|
+
export default _default;
|
|
16
|
+
export declare const setSolidSettings: import("@reduxjs/toolkit").ActionCreatorWithPayload<Record<string, any>, "settingsSlice/setSolidSettings">, updateSolidSetting: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
|
|
17
|
+
key: string;
|
|
18
|
+
value: any;
|
|
19
|
+
}, "settingsSlice/updateSolidSetting">, resetSettings: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"settingsSlice/resetSettings">;
|
|
20
|
+
//# sourceMappingURL=settingsSlice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settingsSlice.d.ts","sourceRoot":"./","sources":["redux/features/settingsSlice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,kBAAkB,CAAC;AAE9D,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpC;AAOD,eAAO,MAAM,aAAa;sGAsBZ,cAAc,OAAO,MAAM,EAAE,GAAG,CAAC,CAAC;wGAOlC,cAAc;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,CAAC;;mBAQtD,CAAC;;AAEH,wBAAqC;AAErC,eAAO,MAGL,gBAAgB,8GAChB,kBAAkB;SAhBe,MAAM;WAAS,GAAG;wCAiBnD,aAAa,uFACU,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createSlice } from "@reduxjs/toolkit";
|
|
2
|
+
const initialState = {
|
|
3
|
+
authSettings: {},
|
|
4
|
+
solidSettings: {},
|
|
5
|
+
};
|
|
6
|
+
export const settingsSlice = createSlice({
|
|
7
|
+
name: "settingsSlice",
|
|
8
|
+
initialState,
|
|
9
|
+
reducers: {
|
|
10
|
+
// // -------- AUTH SETTINGS --------
|
|
11
|
+
// setAuthSettings: (
|
|
12
|
+
// state,
|
|
13
|
+
// action: PayloadAction<Record<string, any>>
|
|
14
|
+
// ) => {
|
|
15
|
+
// state.authSettings = action.payload;
|
|
16
|
+
// },
|
|
17
|
+
// updateAuthSetting: (
|
|
18
|
+
// state,
|
|
19
|
+
// action: PayloadAction<{ key: string; value: any }>
|
|
20
|
+
// ) => {
|
|
21
|
+
// state.authSettings[action.payload.key] = action.payload.value;
|
|
22
|
+
// },
|
|
23
|
+
// -------- SOLID SETTINGS --------
|
|
24
|
+
setSolidSettings: (state, action) => {
|
|
25
|
+
state.solidSettings = action.payload;
|
|
26
|
+
},
|
|
27
|
+
updateSolidSetting: (state, action) => {
|
|
28
|
+
state.solidSettings[action.payload.key] = action.payload.value;
|
|
29
|
+
},
|
|
30
|
+
// -------- RESET --------
|
|
31
|
+
resetSettings: () => initialState,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
export default settingsSlice.reducer;
|
|
35
|
+
export const {
|
|
36
|
+
// setAuthSettings,
|
|
37
|
+
// updateAuthSetting,
|
|
38
|
+
setSolidSettings, updateSolidSetting, resetSettings, } = settingsSlice.actions;
|
|
39
|
+
//# sourceMappingURL=settingsSlice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settingsSlice.js","sourceRoot":"./","sources":["redux/features/settingsSlice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAO9D,MAAM,YAAY,GAAmB;IACnC,YAAY,EAAE,EAAE;IAChB,aAAa,EAAE,EAAE;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAC;IACvC,IAAI,EAAE,eAAe;IACrB,YAAY;IACZ,QAAQ,EAAE;QACR,qCAAqC;QACrC,qBAAqB;QACrB,WAAW;QACX,+CAA+C;QAC/C,SAAS;QACT,yCAAyC;QACzC,KAAK;QAEL,uBAAuB;QACvB,WAAW;QACX,uDAAuD;QACvD,SAAS;QACT,mEAAmE;QACnE,KAAK;QAEL,mCAAmC;QACnC,gBAAgB,EAAE,CAChB,KAAK,EACL,MAA0C,EAC1C,EAAE;YACF,KAAK,CAAC,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC;QACvC,CAAC;QAED,kBAAkB,EAAE,CAClB,KAAK,EACL,MAAkD,EAClD,EAAE;YACF,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QACjE,CAAC;QAED,0BAA0B;QAC1B,aAAa,EAAE,GAAG,EAAE,CAAC,YAAY;KAClC;CACF,CAAC,CAAC;AAEH,eAAe,aAAa,CAAC,OAAO,CAAC;AAErC,MAAM,CAAC,MAAM;AACX,mBAAmB;AACnB,qBAAqB;AACrB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,GACd,GAAG,aAAa,CAAC,OAAO,CAAC","sourcesContent":["import { PayloadAction, createSlice } from \"@reduxjs/toolkit\";\n\nexport interface ISettingsState {\n authSettings: Record<string, any>;\n solidSettings: Record<string, any>;\n}\n\nconst initialState: ISettingsState = {\n authSettings: {},\n solidSettings: {},\n};\n\nexport const settingsSlice = createSlice({\n name: \"settingsSlice\",\n initialState,\n reducers: {\n // // -------- AUTH SETTINGS --------\n // setAuthSettings: (\n // state,\n // action: PayloadAction<Record<string, any>>\n // ) => {\n // state.authSettings = action.payload;\n // },\n\n // updateAuthSetting: (\n // state,\n // action: PayloadAction<{ key: string; value: any }>\n // ) => {\n // state.authSettings[action.payload.key] = action.payload.value;\n // },\n\n // -------- SOLID SETTINGS --------\n setSolidSettings: (\n state,\n action: PayloadAction<Record<string, any>>\n ) => {\n state.solidSettings = action.payload;\n },\n\n updateSolidSetting: (\n state,\n action: PayloadAction<{ key: string; value: any }>\n ) => {\n state.solidSettings[action.payload.key] = action.payload.value;\n },\n\n // -------- RESET --------\n resetSettings: () => initialState,\n },\n});\n\nexport default settingsSlice.reducer;\n\nexport const {\n // setAuthSettings,\n // updateAuthSetting,\n setSolidSettings,\n updateSolidSetting,\n resetSettings,\n} = settingsSlice.actions;\n"]}
|