@greatapps/common 1.1.59 → 1.1.61
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/modules/auth/actions/verify-two-factor.action.mjs +2 -2
- package/dist/modules/auth/actions/verify-two-factor.action.mjs.map +1 -1
- package/dist/modules/auth/hooks/useUserQuery.mjs +2 -14
- package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -1
- package/package.json +1 -1
- package/src/modules/auth/actions/verify-two-factor.action.ts +2 -2
- package/src/modules/auth/hooks/useUserQuery.ts +2 -14
- package/dist/modules/auth/actions/is-two-factor-pending.action.mjs +0 -9
- package/dist/modules/auth/actions/is-two-factor-pending.action.mjs.map +0 -1
- package/src/modules/auth/actions/is-two-factor-pending.action.ts +0 -7
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { authService } from "../services/auth.service";
|
|
3
3
|
import { ApiError } from "../../../infra/api/types";
|
|
4
4
|
import { getClientInfoFromRequest } from "../../../infra/utils/client-info";
|
|
5
|
-
async function verifyTwoFactorAction(code) {
|
|
5
|
+
async function verifyTwoFactorAction(cookie, code) {
|
|
6
6
|
if (!Number.isInteger(code) || code < 0 || code > 999999) {
|
|
7
7
|
throw new ApiError("C\xF3digo inv\xE1lido", "INVALID_CODE", 400);
|
|
8
8
|
}
|
|
9
9
|
const clientInfo = await getClientInfoFromRequest();
|
|
10
|
-
await authService.verifyTwoFactor(code, clientInfo);
|
|
10
|
+
await authService.verifyTwoFactor(cookie, code, clientInfo);
|
|
11
11
|
return { success: true };
|
|
12
12
|
}
|
|
13
13
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/actions/verify-two-factor.action.ts"],"sourcesContent":["'use server';\r\n\r\nimport { authService } from '../services/auth.service';\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { getClientInfoFromRequest } from '../../../infra/utils/client-info';\r\n\r\nexport async function verifyTwoFactorAction(code: number): Promise<{ success: boolean }> {\r\n if (!Number.isInteger(code) || code < 0 || code > 999999) {\r\n throw new ApiError('Código inválido', 'INVALID_CODE', 400);\r\n }\r\n\r\n const clientInfo = await getClientInfoFromRequest();\r\n await authService.verifyTwoFactor(code, clientInfo);\r\n return { success: true };\r\n}\r\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAAS,gCAAgC;AAEzC,eAAsB,sBAAsB,MAA6C;
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/auth/actions/verify-two-factor.action.ts"],"sourcesContent":["'use server';\r\n\r\nimport { authService } from '../services/auth.service';\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { getClientInfoFromRequest } from '../../../infra/utils/client-info';\r\n\r\nexport async function verifyTwoFactorAction(cookie: string, code: number): Promise<{ success: boolean }> {\r\n if (!Number.isInteger(code) || code < 0 || code > 999999) {\r\n throw new ApiError('Código inválido', 'INVALID_CODE', 400);\r\n }\r\n\r\n const clientInfo = await getClientInfoFromRequest();\r\n await authService.verifyTwoFactor(cookie, code, clientInfo);\r\n return { success: true };\r\n}\r\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAAS,gCAAgC;AAEzC,eAAsB,sBAAsB,QAAgB,MAA6C;AACvG,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,OAAO,KAAK,OAAO,QAAQ;AACxD,UAAM,IAAI,SAAS,yBAAmB,gBAAgB,GAAG;AAAA,EAC3D;AAEA,QAAM,aAAa,MAAM,yBAAyB;AAClD,QAAM,YAAY,gBAAgB,QAAQ,MAAM,UAAU;AAC1D,SAAO,EAAE,SAAS,KAAK;AACzB;","names":[]}
|
|
@@ -33,9 +33,9 @@ function useUserValidateSession(options) {
|
|
|
33
33
|
function useTwoFactorVerify() {
|
|
34
34
|
const queryClient = useQueryClient();
|
|
35
35
|
return useMutation({
|
|
36
|
-
mutationFn: async (code) => {
|
|
36
|
+
mutationFn: async ({ cookie, code }) => {
|
|
37
37
|
const { verifyTwoFactorAction } = await import("../actions/verify-two-factor.action");
|
|
38
|
-
return verifyTwoFactorAction(code);
|
|
38
|
+
return verifyTwoFactorAction(cookie, code);
|
|
39
39
|
},
|
|
40
40
|
onSuccess: () => {
|
|
41
41
|
queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
@@ -43,17 +43,6 @@ function useTwoFactorVerify() {
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
function useTwoFactorPending() {
|
|
47
|
-
return useQuery({
|
|
48
|
-
queryKey: ["two-factor-pending"],
|
|
49
|
-
queryFn: async () => {
|
|
50
|
-
const { isTwoFactorPendingAction } = await import("../actions/is-two-factor-pending.action");
|
|
51
|
-
return isTwoFactorPendingAction();
|
|
52
|
-
},
|
|
53
|
-
staleTime: 10 * 1e3,
|
|
54
|
-
retry: false
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
46
|
function useInvalidateUser() {
|
|
58
47
|
const queryClient = useQueryClient();
|
|
59
48
|
return () => queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
@@ -66,7 +55,6 @@ export {
|
|
|
66
55
|
USER_QUERY_KEY,
|
|
67
56
|
useInvalidateUser,
|
|
68
57
|
useSetUserData,
|
|
69
|
-
useTwoFactorPending,
|
|
70
58
|
useTwoFactorVerify,
|
|
71
59
|
useUserQuery,
|
|
72
60
|
useUserValidateSession
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/hooks/useUserQuery.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useMutation, useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query';\r\nimport { User } from '../../users/schema';\r\n\r\nexport const USER_QUERY_KEY = ['user'];\r\n\r\nasync function fetchUser(): Promise<User | null> {\r\n const { findUserById: getUserDataAction } = await import('../../users/action/find-user-by-id.action');\r\n const result = await getUserDataAction();\r\n return result.success && result.data ? result.data : null;\r\n}\r\n\r\nasync function validateUserSession(): Promise<boolean> {\r\n const { validateSessionAction } = await import('../actions/validate-session.action');\r\n return await validateSessionAction();\r\n}\r\n\r\nexport function useUserQuery() {\r\n return useQuery({\r\n queryKey: USER_QUERY_KEY,\r\n queryFn: fetchUser,\r\n staleTime: 5 * 60 * 1000,\r\n gcTime: 10 * 60 * 1000,\r\n retry: false,\r\n });\r\n}\r\n\r\nexport function useUserValidateSession(options?: UseQueryOptions) {\r\n return useQuery({\r\n queryKey: ['user-validate-session'],\r\n queryFn: validateUserSession,\r\n retry: false,\r\n staleTime: 5 * 60 * 1000,\r\n ...options,\r\n refetchOnMount: 'always',\r\n refetchOnWindowFocus: true,\r\n });\r\n}\r\n\r\nexport function useTwoFactorVerify() {\r\n const queryClient = useQueryClient();\r\n\r\n return useMutation({\r\n mutationFn: async (code: number) => {\r\n const { verifyTwoFactorAction } = await import('../actions/verify-two-factor.action');\r\n return verifyTwoFactorAction(code);\r\n },\r\n onSuccess: () => {\r\n queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });\r\n queryClient.invalidateQueries({ queryKey: ['two-factor-pending'] });\r\n },\r\n });\r\n}\r\n\r\nexport function
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/auth/hooks/useUserQuery.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useMutation, useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query';\r\nimport { User } from '../../users/schema';\r\n\r\nexport const USER_QUERY_KEY = ['user'];\r\n\r\nasync function fetchUser(): Promise<User | null> {\r\n const { findUserById: getUserDataAction } = await import('../../users/action/find-user-by-id.action');\r\n const result = await getUserDataAction();\r\n return result.success && result.data ? result.data : null;\r\n}\r\n\r\nasync function validateUserSession(): Promise<boolean> {\r\n const { validateSessionAction } = await import('../actions/validate-session.action');\r\n return await validateSessionAction();\r\n}\r\n\r\nexport function useUserQuery() {\r\n return useQuery({\r\n queryKey: USER_QUERY_KEY,\r\n queryFn: fetchUser,\r\n staleTime: 5 * 60 * 1000,\r\n gcTime: 10 * 60 * 1000,\r\n retry: false,\r\n });\r\n}\r\n\r\nexport function useUserValidateSession(options?: UseQueryOptions) {\r\n return useQuery({\r\n queryKey: ['user-validate-session'],\r\n queryFn: validateUserSession,\r\n retry: false,\r\n staleTime: 5 * 60 * 1000,\r\n ...options,\r\n refetchOnMount: 'always',\r\n refetchOnWindowFocus: true,\r\n });\r\n}\r\n\r\nexport function useTwoFactorVerify() {\r\n const queryClient = useQueryClient();\r\n\r\n return useMutation({\r\n mutationFn: async ({ cookie, code }: { cookie: string; code: number }) => {\r\n const { verifyTwoFactorAction } = await import('../actions/verify-two-factor.action');\r\n return verifyTwoFactorAction(cookie, code);\r\n },\r\n onSuccess: () => {\r\n queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });\r\n queryClient.invalidateQueries({ queryKey: ['two-factor-pending'] });\r\n },\r\n });\r\n}\r\n\r\nexport function useInvalidateUser() {\r\n const queryClient = useQueryClient();\r\n return () => queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });\r\n}\r\n\r\nexport function useSetUserData() {\r\n const queryClient = useQueryClient();\r\n return (user: User | null) => queryClient.setQueryData(USER_QUERY_KEY, user);\r\n}\r\n"],"mappings":";AAEA,SAAS,aAAa,UAAU,sBAAuC;AAGhE,MAAM,iBAAiB,CAAC,MAAM;AAErC,eAAe,YAAkC;AAC/C,QAAM,EAAE,cAAc,kBAAkB,IAAI,MAAM,OAAO,2CAA2C;AACpG,QAAM,SAAS,MAAM,kBAAkB;AACvC,SAAO,OAAO,WAAW,OAAO,OAAO,OAAO,OAAO;AACvD;AAEA,eAAe,sBAAwC;AACrD,QAAM,EAAE,sBAAsB,IAAI,MAAM,OAAO,oCAAoC;AACnF,SAAO,MAAM,sBAAsB;AACrC;AAEO,SAAS,eAAe;AAC7B,SAAO,SAAS;AAAA,IACd,UAAU;AAAA,IACV,SAAS;AAAA,IACT,WAAW,IAAI,KAAK;AAAA,IACpB,QAAQ,KAAK,KAAK;AAAA,IAClB,OAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,uBAAuB,SAA2B;AAChE,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,uBAAuB;AAAA,IAClC,SAAS;AAAA,IACT,OAAO;AAAA,IACP,WAAW,IAAI,KAAK;AAAA,IACpB,GAAG;AAAA,IACH,gBAAgB;AAAA,IAChB,sBAAsB;AAAA,EACxB,CAAC;AACH;AAEO,SAAS,qBAAqB;AACnC,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,EAAE,QAAQ,KAAK,MAAwC;AACxE,YAAM,EAAE,sBAAsB,IAAI,MAAM,OAAO,qCAAqC;AACpF,aAAO,sBAAsB,QAAQ,IAAI;AAAA,IAC3C;AAAA,IACA,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,eAAe,CAAC;AAC1D,kBAAY,kBAAkB,EAAE,UAAU,CAAC,oBAAoB,EAAE,CAAC;AAAA,IACpE;AAAA,EACF,CAAC;AACH;AAEO,SAAS,oBAAoB;AAClC,QAAM,cAAc,eAAe;AACnC,SAAO,MAAM,YAAY,kBAAkB,EAAE,UAAU,eAAe,CAAC;AACzE;AAEO,SAAS,iBAAiB;AAC/B,QAAM,cAAc,eAAe;AACnC,SAAO,CAAC,SAAsB,YAAY,aAAa,gBAAgB,IAAI;AAC7E;","names":[]}
|
package/package.json
CHANGED
|
@@ -4,12 +4,12 @@ import { authService } from '../services/auth.service';
|
|
|
4
4
|
import { ApiError } from '../../../infra/api/types';
|
|
5
5
|
import { getClientInfoFromRequest } from '../../../infra/utils/client-info';
|
|
6
6
|
|
|
7
|
-
export async function verifyTwoFactorAction(code: number): Promise<{ success: boolean }> {
|
|
7
|
+
export async function verifyTwoFactorAction(cookie: string, code: number): Promise<{ success: boolean }> {
|
|
8
8
|
if (!Number.isInteger(code) || code < 0 || code > 999999) {
|
|
9
9
|
throw new ApiError('Código inválido', 'INVALID_CODE', 400);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const clientInfo = await getClientInfoFromRequest();
|
|
13
|
-
await authService.verifyTwoFactor(code, clientInfo);
|
|
13
|
+
await authService.verifyTwoFactor(cookie, code, clientInfo);
|
|
14
14
|
return { success: true };
|
|
15
15
|
}
|
|
@@ -42,9 +42,9 @@ export function useTwoFactorVerify() {
|
|
|
42
42
|
const queryClient = useQueryClient();
|
|
43
43
|
|
|
44
44
|
return useMutation({
|
|
45
|
-
mutationFn: async (code: number) => {
|
|
45
|
+
mutationFn: async ({ cookie, code }: { cookie: string; code: number }) => {
|
|
46
46
|
const { verifyTwoFactorAction } = await import('../actions/verify-two-factor.action');
|
|
47
|
-
return verifyTwoFactorAction(code);
|
|
47
|
+
return verifyTwoFactorAction(cookie, code);
|
|
48
48
|
},
|
|
49
49
|
onSuccess: () => {
|
|
50
50
|
queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
@@ -53,18 +53,6 @@ export function useTwoFactorVerify() {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export function useTwoFactorPending() {
|
|
57
|
-
return useQuery({
|
|
58
|
-
queryKey: ['two-factor-pending'],
|
|
59
|
-
queryFn: async () => {
|
|
60
|
-
const { isTwoFactorPendingAction } = await import('../actions/is-two-factor-pending.action');
|
|
61
|
-
return isTwoFactorPendingAction();
|
|
62
|
-
},
|
|
63
|
-
staleTime: 10 * 1000,
|
|
64
|
-
retry: false,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
56
|
export function useInvalidateUser() {
|
|
69
57
|
const queryClient = useQueryClient();
|
|
70
58
|
return () => queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
import { authService } from "../services/auth.service";
|
|
3
|
-
async function isTwoFactorPendingAction() {
|
|
4
|
-
return authService.isTwoFactorPending();
|
|
5
|
-
}
|
|
6
|
-
export {
|
|
7
|
-
isTwoFactorPendingAction
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=is-two-factor-pending.action.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/actions/is-two-factor-pending.action.ts"],"sourcesContent":["'use server';\r\n\r\nimport { authService } from '../services/auth.service';\r\n\r\nexport async function isTwoFactorPendingAction(): Promise<boolean> {\r\n return authService.isTwoFactorPending();\r\n}\r\n"],"mappings":";AAEA,SAAS,mBAAmB;AAE5B,eAAsB,2BAA6C;AACjE,SAAO,YAAY,mBAAmB;AACxC;","names":[]}
|