@greatapps/common 1.1.632 → 1.1.633
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/components/account/sections/SecuritySection.mjs +2 -38
- package/dist/components/account/sections/SecuritySection.mjs.map +1 -1
- package/dist/components/navigation/SubscriptionBanner.mjs +1 -0
- package/dist/components/navigation/SubscriptionBanner.mjs.map +1 -1
- package/dist/index.mjs +0 -6
- package/dist/index.mjs.map +1 -1
- package/dist/modules/auth/services/auth.service.mjs +0 -165
- package/dist/modules/auth/services/auth.service.mjs.map +1 -1
- package/dist/modules/auth/utils/assert-management-subscription.mjs +3 -1
- package/dist/modules/auth/utils/assert-management-subscription.mjs.map +1 -1
- package/dist/modules/auth/utils/assert-paid-subscription.mjs +3 -1
- package/dist/modules/auth/utils/assert-paid-subscription.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/use-cancelled-subscription-guard.mjs +2 -1
- package/dist/modules/subscriptions/hooks/use-cancelled-subscription-guard.mjs.map +1 -1
- package/dist/modules/users/schema.mjs.map +1 -1
- package/dist/providers/auth.provider.mjs +3 -63
- package/dist/providers/auth.provider.mjs.map +1 -1
- package/dist/server.mjs +0 -6
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/account/sections/SecuritySection.tsx +3 -50
- package/src/components/navigation/SubscriptionBanner.tsx +2 -0
- package/src/index.ts +0 -3
- package/src/modules/auth/schema.ts +0 -74
- package/src/modules/auth/services/auth.service.ts +0 -207
- package/src/modules/auth/utils/assert-management-subscription.ts +6 -1
- package/src/modules/auth/utils/assert-paid-subscription.ts +6 -1
- package/src/modules/subscriptions/hooks/use-cancelled-subscription-guard.ts +4 -1
- package/src/modules/users/schema.ts +0 -2
- package/src/providers/auth.provider.tsx +1 -86
- package/src/server.ts +0 -3
- package/dist/modules/auth/actions/social-google-login.action.mjs +0 -14
- package/dist/modules/auth/actions/social-google-login.action.mjs.map +0 -1
- package/dist/modules/auth/actions/social-google-onboarding.action.mjs +0 -14
- package/dist/modules/auth/actions/social-google-onboarding.action.mjs.map +0 -1
- package/dist/modules/auth/actions/unlink-google.action.mjs +0 -10
- package/dist/modules/auth/actions/unlink-google.action.mjs.map +0 -1
- package/dist/modules/auth/hooks/social-google-login.hook.mjs +0 -13
- package/dist/modules/auth/hooks/social-google-login.hook.mjs.map +0 -1
- package/dist/modules/auth/hooks/social-google-onboarding.hook.mjs +0 -13
- package/dist/modules/auth/hooks/social-google-onboarding.hook.mjs.map +0 -1
- package/dist/modules/auth/hooks/unlink-google.hook.mjs +0 -13
- package/dist/modules/auth/hooks/unlink-google.hook.mjs.map +0 -1
- package/src/modules/auth/actions/social-google-login.action.ts +0 -12
- package/src/modules/auth/actions/social-google-onboarding.action.ts +0 -13
- package/src/modules/auth/actions/unlink-google.action.ts +0 -8
- package/src/modules/auth/hooks/social-google-login.hook.tsx +0 -13
- package/src/modules/auth/hooks/social-google-onboarding.hook.tsx +0 -13
- package/src/modules/auth/hooks/unlink-google.hook.tsx +0 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/utils/assert-paid-subscription.ts"],"sourcesContent":["import \"server-only\";\n\nimport { ApiError } from \"../../../infra/api/types\";\nimport { listSubscriptionsAction } from \"../../subscriptions/actions/list-subscriptions.action\";\nimport { hasSubscriptionExpired } from \"../../subscriptions/utils/has-subscription-expired\";\n\nexport async function assertPaidSubscription() {\n const result = await listSubscriptionsAction({ active: true });\n\n if (!result.success) {\n throw new ApiError(\n result.error || \"Não foi possível validar a assinatura atual\",\n \"SUBSCRIPTION_CONTEXT_FAILED\",\n 403,\n );\n }\n\n const subscription = result.data?.data?.[0];\n\n if (!subscription) {\n throw new ApiError(\n \"Nenhuma assinatura ativa encontrada. Assine um plano para continuar.\",\n \"SUBSCRIPTION_NOT_FOUND\",\n 403,\n );\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/auth/utils/assert-paid-subscription.ts"],"sourcesContent":["import \"server-only\";\n\nimport { ApiError } from \"../../../infra/api/types\";\nimport { listSubscriptionsAction } from \"../../subscriptions/actions/list-subscriptions.action\";\nimport { hasSubscriptionExpired } from \"../../subscriptions/utils/has-subscription-expired\";\n\nexport async function assertPaidSubscription() {\n const result = await listSubscriptionsAction({ active: true });\n\n if (!result.success) {\n throw new ApiError(\n result.error || \"Não foi possível validar a assinatura atual\",\n \"SUBSCRIPTION_CONTEXT_FAILED\",\n 403,\n );\n }\n\n const subscription = result.data?.data?.[0];\n\n if (!subscription) {\n throw new ApiError(\n \"Nenhuma assinatura ativa encontrada. Assine um plano para continuar.\",\n \"SUBSCRIPTION_NOT_FOUND\",\n 403,\n );\n }\n\n const isWhitelabelType = subscription.type === 'whitelabel';\n const isExpired = isWhitelabelType\n ? !!subscription.date_cancellation && new Date() >= new Date(subscription.date_cancellation)\n : hasSubscriptionExpired(subscription.date_due);\n\n if (isExpired) {\n throw new ApiError(\n \"Sua assinatura está vencida. Assine um novo plano para continuar.\",\n \"SUBSCRIPTION_EXPIRED\",\n 403,\n );\n }\n\n \n if (subscription.type === 'free' || subscription.id_plan === 5) {\n throw new ApiError(\n \"Este recurso está disponível apenas para planos pagos. Faça upgrade do seu plano para continuar.\",\n \"PAID_SUBSCRIPTION_REQUIRED\",\n 403,\n );\n }\n}\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AAEvC,eAAsB,yBAAyB;AAC7C,QAAM,SAAS,MAAM,wBAAwB,EAAE,QAAQ,KAAK,CAAC;AAE7D,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,IAAI;AAAA,MACR,OAAO,SAAS;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,eAAe,OAAO,MAAM,OAAO,CAAC;AAE1C,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,mBAAmB,aAAa,SAAS;AAC/C,QAAM,YAAY,mBACd,CAAC,CAAC,aAAa,qBAAqB,oBAAI,KAAK,KAAK,IAAI,KAAK,aAAa,iBAAiB,IACzF,uBAAuB,aAAa,QAAQ;AAEhD,MAAI,WAAW;AACb,UAAM,IAAI;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAGA,MAAI,aAAa,SAAS,UAAU,aAAa,YAAY,GAAG;AAC9D,UAAM,IAAI;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -12,7 +12,8 @@ function useCancelledSubscriptionGuard() {
|
|
|
12
12
|
data: { data: [subscription] = [] } = {}
|
|
13
13
|
} = useActiveSubscription();
|
|
14
14
|
const isViewer = user?.profile === UserProfile.viewer;
|
|
15
|
-
const
|
|
15
|
+
const isWhitelabelType = subscription?.type === "whitelabel";
|
|
16
|
+
const isCancelledSubscription = isWhitelabelType ? !!subscription?.date_cancellation && /* @__PURE__ */ new Date() >= new Date(subscription.date_cancellation) : hasSubscriptionExpired(subscription?.date_due);
|
|
16
17
|
const shouldBlockManagementAction = !isViewer && isCancelledSubscription;
|
|
17
18
|
const guardAction = useCallback(
|
|
18
19
|
(action) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/use-cancelled-subscription-guard.ts"],"sourcesContent":["'use client';\n\nimport { useCallback } from 'react';\nimport { UserProfile } from '../../users/schema';\nimport { useAuth } from '../../../providers/auth.provider';\nimport { useModalManager } from '../../../store/useModalManager';\nimport { useActiveSubscription } from './find-active-subscription.hook';\nimport { hasSubscriptionExpired } from '../utils/has-subscription-expired';\n\nexport function useCancelledSubscriptionGuard() {\n const { user } = useAuth();\n const { openModal } = useModalManager();\n const {\n data: { data: [subscription] = [] } = {},\n } = useActiveSubscription();\n\n const isViewer = user?.profile === UserProfile.viewer;\n const isCancelledSubscription = hasSubscriptionExpired(subscription?.date_due);\n const shouldBlockManagementAction = !isViewer && isCancelledSubscription;\n\n const guardAction = useCallback(\n (action?: () => void) => {\n if (shouldBlockManagementAction) {\n openModal('subscriptionExpiredModal');\n return false;\n }\n\n action?.();\n return true;\n },\n [openModal, shouldBlockManagementAction]\n );\n\n return {\n isCancelledSubscription,\n shouldBlockManagementAction,\n guardAction,\n };\n}\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,8BAA8B;AAEhC,SAAS,gCAAgC;AAC9C,QAAM,EAAE,KAAK,IAAI,QAAQ;AACzB,QAAM,EAAE,UAAU,IAAI,gBAAgB;AACtC,QAAM;AAAA,IACJ,MAAM,EAAE,MAAM,CAAC,YAAY,IAAI,CAAC,EAAE,IAAI,CAAC;AAAA,EACzC,IAAI,sBAAsB;AAE1B,QAAM,WAAW,MAAM,YAAY,YAAY;AAC/C,QAAM,0BAA0B,uBAAuB,cAAc,QAAQ;
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/use-cancelled-subscription-guard.ts"],"sourcesContent":["'use client';\n\nimport { useCallback } from 'react';\nimport { UserProfile } from '../../users/schema';\nimport { useAuth } from '../../../providers/auth.provider';\nimport { useModalManager } from '../../../store/useModalManager';\nimport { useActiveSubscription } from './find-active-subscription.hook';\nimport { hasSubscriptionExpired } from '../utils/has-subscription-expired';\n\nexport function useCancelledSubscriptionGuard() {\n const { user } = useAuth();\n const { openModal } = useModalManager();\n const {\n data: { data: [subscription] = [] } = {},\n } = useActiveSubscription();\n\n const isViewer = user?.profile === UserProfile.viewer;\n const isWhitelabelType = subscription?.type === 'whitelabel';\n const isCancelledSubscription = isWhitelabelType\n ? !!subscription?.date_cancellation && new Date() >= new Date(subscription.date_cancellation)\n : hasSubscriptionExpired(subscription?.date_due);\n const shouldBlockManagementAction = !isViewer && isCancelledSubscription;\n\n const guardAction = useCallback(\n (action?: () => void) => {\n if (shouldBlockManagementAction) {\n openModal('subscriptionExpiredModal');\n return false;\n }\n\n action?.();\n return true;\n },\n [openModal, shouldBlockManagementAction]\n );\n\n return {\n isCancelledSubscription,\n shouldBlockManagementAction,\n guardAction,\n };\n}\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,8BAA8B;AAEhC,SAAS,gCAAgC;AAC9C,QAAM,EAAE,KAAK,IAAI,QAAQ;AACzB,QAAM,EAAE,UAAU,IAAI,gBAAgB;AACtC,QAAM;AAAA,IACJ,MAAM,EAAE,MAAM,CAAC,YAAY,IAAI,CAAC,EAAE,IAAI,CAAC;AAAA,EACzC,IAAI,sBAAsB;AAE1B,QAAM,WAAW,MAAM,YAAY,YAAY;AAC/C,QAAM,mBAAmB,cAAc,SAAS;AAChD,QAAM,0BAA0B,mBAC5B,CAAC,CAAC,cAAc,qBAAqB,oBAAI,KAAK,KAAK,IAAI,KAAK,aAAa,iBAAiB,IAC1F,uBAAuB,cAAc,QAAQ;AACjD,QAAM,8BAA8B,CAAC,YAAY;AAEjD,QAAM,cAAc;AAAA,IAClB,CAAC,WAAwB;AACvB,UAAI,6BAA6B;AAC/B,kBAAU,0BAA0B;AACpC,eAAO;AAAA,MACT;AAEA,eAAS;AACT,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,2BAA2B;AAAA,EACzC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/modules/users/schema.ts"],"sourcesContent":["export enum UserProfile {\r\n viewer = 'viewer',\r\n collaborator = 'collaborator',\r\n admin = 'admin',\r\n owner = 'owner',\r\n}\r\n\r\nexport interface User {\r\n // Identificação\r\n id: number;\r\n id_wl: number;\r\n id_account: number;\r\n id_api: number;\r\n\r\n // Dados pessoais\r\n name: string;\r\n last_name: string;\r\n email: string;\r\n ddi: string;\r\n phone: string;\r\n rg: string | null;\r\n cpf: string | null;\r\n gender: number;\r\n\r\n // Autenticação e segurança\r\n two_factor_authentication: boolean;\r\n
|
|
1
|
+
{"version":3,"sources":["../../../src/modules/users/schema.ts"],"sourcesContent":["export enum UserProfile {\r\n viewer = 'viewer',\r\n collaborator = 'collaborator',\r\n admin = 'admin',\r\n owner = 'owner',\r\n}\r\n\r\nexport interface User {\r\n // Identificação\r\n id: number;\r\n id_wl: number;\r\n id_account: number;\r\n id_api: number;\r\n\r\n // Dados pessoais\r\n name: string;\r\n last_name: string;\r\n email: string;\r\n ddi: string;\r\n phone: string;\r\n rg: string | null;\r\n cpf: string | null;\r\n gender: number;\r\n\r\n // Autenticação e segurança\r\n two_factor_authentication: boolean;\r\n\r\n // Perfil e permissões\r\n profile: UserProfile;\r\n\r\n // Preferências\r\n language: string;\r\n receive_sms: boolean;\r\n receive_email: boolean;\r\n photo: string | null;\r\n\r\n // Metadados\r\n deleted: number;\r\n datetime_alt: string;\r\n datetime_del: string | null;\r\n datetime_add: string;\r\n\r\n total_projects: number;\r\n projects: { id: number; title: string }[];\r\n\r\n initials?: string;\r\n emailVerified?: boolean;\r\n createdAt?: string;\r\n updatedAt?: string;\r\n}\r\n\r\nexport interface GetUserDataResponse {\r\n status: 0 | 1;\r\n total: number;\r\n data: User[];\r\n}\r\n\r\nexport interface JWTPayload {\r\n session: {\r\n location: {\r\n continent: string;\r\n country: string;\r\n region: string;\r\n city: string;\r\n latitude: string;\r\n longitude: string;\r\n };\r\n ip: string;\r\n timezone: string;\r\n agent: string;\r\n code: string | null;\r\n };\r\n id_wl: string;\r\n id_account: number;\r\n id_user: number;\r\n iss: string;\r\n aud: string;\r\n iat: number;\r\n}\r\n"],"mappings":"AAAO,IAAK,cAAL,kBAAKA,iBAAL;AACL,EAAAA,aAAA,YAAS;AACT,EAAAA,aAAA,kBAAe;AACf,EAAAA,aAAA,WAAQ;AACR,EAAAA,aAAA,WAAQ;AAJE,SAAAA;AAAA,GAAA;","names":["UserProfile"]}
|
|
@@ -15,8 +15,6 @@ import {
|
|
|
15
15
|
import { useLogin } from "../modules/auth/hooks/login.hook";
|
|
16
16
|
import { useRegister } from "../modules/auth/hooks/register.hook";
|
|
17
17
|
import { useLogout } from "../modules/auth/hooks/logout.hook";
|
|
18
|
-
import { useSocialGoogleLogin } from "../modules/auth/hooks/social-google-login.hook";
|
|
19
|
-
import { useSocialGoogleOnboarding } from "../modules/auth/hooks/social-google-onboarding.hook";
|
|
20
18
|
import {
|
|
21
19
|
useCurrentAccount,
|
|
22
20
|
ACCOUNT_QUERY_KEY
|
|
@@ -37,10 +35,8 @@ function AuthProvider({ children }) {
|
|
|
37
35
|
const { mutateAsync: loginMutate, isPending: isLogging } = useLogin();
|
|
38
36
|
const { mutateAsync: registerMutate, isPending: isRegistering } = useRegister();
|
|
39
37
|
const { mutateAsync: logoutMutate, isPending: isLoggingOut } = useLogout();
|
|
40
|
-
const { mutateAsync: googleLoginMutate, isPending: isGoogleLogging } = useSocialGoogleLogin();
|
|
41
|
-
const { mutateAsync: googleOnboardingMutate, isPending: isGoogleOnboarding } = useSocialGoogleOnboarding();
|
|
42
38
|
const isAuthenticated = !!user;
|
|
43
|
-
const isLoading = isLogging || isRegistering || isLoggingOut ||
|
|
39
|
+
const isLoading = isLogging || isRegistering || isLoggingOut || isQueryLoading || isAccountLoading || isSessionLoading;
|
|
44
40
|
const login = useCallback(
|
|
45
41
|
async (credentials) => {
|
|
46
42
|
try {
|
|
@@ -71,50 +67,6 @@ function AuthProvider({ children }) {
|
|
|
71
67
|
},
|
|
72
68
|
[queryClient, setUserData, accountKey]
|
|
73
69
|
);
|
|
74
|
-
const loginWithGoogle = useCallback(
|
|
75
|
-
async (idToken) => {
|
|
76
|
-
try {
|
|
77
|
-
const data = await googleLoginMutate(idToken);
|
|
78
|
-
if (data.result === "two_factor_required") {
|
|
79
|
-
return {
|
|
80
|
-
result: "two_factor_required",
|
|
81
|
-
cookie: data.cookie,
|
|
82
|
-
twoFactorMode: data.twoFactorMode
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
if (data.result === "needs_onboarding") {
|
|
86
|
-
return {
|
|
87
|
-
result: "needs_onboarding",
|
|
88
|
-
onboardingToken: data.onboardingToken,
|
|
89
|
-
partial: data.partial
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
if (data.result === "link_requires_password") {
|
|
93
|
-
return { result: "link_requires_password", message: data.message };
|
|
94
|
-
}
|
|
95
|
-
queryClient.clear();
|
|
96
|
-
setUserData(data.user);
|
|
97
|
-
queryClient.setQueryData(accountKey, data.account);
|
|
98
|
-
return { result: "success" };
|
|
99
|
-
} catch (error) {
|
|
100
|
-
const message = error instanceof Error ? error.message : "Ocorreu um erro ao fazer login com Google. Tente novamente.";
|
|
101
|
-
return { result: "error", message };
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
[googleLoginMutate, queryClient, setUserData, accountKey]
|
|
105
|
-
);
|
|
106
|
-
const completeGoogleOnboarding = useCallback(
|
|
107
|
-
async (data) => {
|
|
108
|
-
await googleOnboardingMutate(data, {
|
|
109
|
-
onSuccess: (data2) => {
|
|
110
|
-
queryClient.clear();
|
|
111
|
-
setUserData(data2.user);
|
|
112
|
-
queryClient.setQueryData(accountKey, data2.account);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
},
|
|
116
|
-
[googleOnboardingMutate, queryClient, setUserData, accountKey]
|
|
117
|
-
);
|
|
118
70
|
const resolveLogoutRedirect = useCallback(() => {
|
|
119
71
|
try {
|
|
120
72
|
const currentOrigin = window.location.origin;
|
|
@@ -143,21 +95,9 @@ function AuthProvider({ children }) {
|
|
|
143
95
|
isLoading,
|
|
144
96
|
login,
|
|
145
97
|
register,
|
|
146
|
-
logout
|
|
147
|
-
loginWithGoogle,
|
|
148
|
-
completeGoogleOnboarding
|
|
98
|
+
logout
|
|
149
99
|
}),
|
|
150
|
-
[
|
|
151
|
-
user,
|
|
152
|
-
account,
|
|
153
|
-
isAuthenticated,
|
|
154
|
-
isLoading,
|
|
155
|
-
login,
|
|
156
|
-
register,
|
|
157
|
-
logout,
|
|
158
|
-
loginWithGoogle,
|
|
159
|
-
completeGoogleOnboarding
|
|
160
|
-
]
|
|
100
|
+
[user, account, isAuthenticated, isLoading, login, register, logout]
|
|
161
101
|
);
|
|
162
102
|
return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
|
|
163
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/providers/auth.provider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n ReactNode,\n useCallback,\n useContext,\n useMemo,\n} from \"react\";\nimport { useQueryClient } from \"@tanstack/react-query\";\nimport {\n useUserQuery,\n useSetUserData,\n useUserValidateSession,\n} from \"../modules/auth/hooks/useUserQuery\";\nimport { useLogin } from \"../modules/auth/hooks/login.hook\";\nimport { useRegister } from \"../modules/auth/hooks/register.hook\";\nimport { useLogout } from \"../modules/auth/hooks/logout.hook\";\nimport { useSocialGoogleLogin } from \"../modules/auth/hooks/social-google-login.hook\";\nimport { useSocialGoogleOnboarding } from \"../modules/auth/hooks/social-google-onboarding.hook\";\nimport {\n AuthState,\n LoginRequest,\n RegisterRequest,\n SocialGooglePartial,\n SocialOnboardingRequest,\n} from \"../modules/auth/schema\";\n\nexport type LoginResult =\n | { result: \"success\" }\n | { result: \"two_factor_required\"; cookie: string; twoFactorMode: \"verify\" | \"setup\" }\n | { result: \"error\"; message: string };\n\nexport type GoogleLoginResult =\n | { result: \"success\" }\n | { result: \"two_factor_required\"; cookie: string; twoFactorMode: \"verify\" | \"setup\" }\n | { result: \"needs_onboarding\"; onboardingToken: string; partial: SocialGooglePartial }\n | { result: \"link_requires_password\"; message: string }\n | { result: \"error\"; message: string };\nimport {\n useCurrentAccount,\n ACCOUNT_QUERY_KEY,\n} from \"../modules/accounts/hooks/current-account.hook\";\nimport { useWhitelabelUrls } from \"./whitelabel.provider\";\nimport { useWlQueryKey } from \"../hooks/useAuthQueryKey\";\n\ninterface AuthContextProps extends AuthState {\n login: (credentials: LoginRequest) => Promise<LoginResult>;\n register: (data: RegisterRequest) => Promise<void>;\n logout: () => Promise<void>;\n loginWithGoogle: (idToken: string) => Promise<GoogleLoginResult>;\n completeGoogleOnboarding: (data: SocialOnboardingRequest) => Promise<void>;\n}\n\nexport const AuthContext = createContext<AuthContextProps | undefined>(\n undefined,\n);\n\ninterface AuthProviderProps {\n children: ReactNode;\n}\n\nexport function AuthProvider({ children }: AuthProviderProps) {\n const { data: user, isLoading: isQueryLoading } = useUserQuery();\n const { data: account, isLoading: isAccountLoading } = useCurrentAccount();\n const { isLoading: isSessionLoading } = useUserValidateSession();\n\n const queryClient = useQueryClient();\n const setUserData = useSetUserData();\n const { accountsUrl, pagesUrl } = useWhitelabelUrls();\n const accountKey = useWlQueryKey([...ACCOUNT_QUERY_KEY]);\n\n const { mutateAsync: loginMutate, isPending: isLogging } = useLogin();\n const { mutateAsync: registerMutate, isPending: isRegistering } =\n useRegister();\n const { mutateAsync: logoutMutate, isPending: isLoggingOut } = useLogout();\n const { mutateAsync: googleLoginMutate, isPending: isGoogleLogging } =\n useSocialGoogleLogin();\n const { mutateAsync: googleOnboardingMutate, isPending: isGoogleOnboarding } =\n useSocialGoogleOnboarding();\n\n const isAuthenticated = !!user;\n const isLoading =\n isLogging ||\n isRegistering ||\n isLoggingOut ||\n isGoogleLogging ||\n isGoogleOnboarding ||\n isQueryLoading ||\n isAccountLoading ||\n isSessionLoading;\n\n const login = useCallback(\n async (credentials: LoginRequest): Promise<LoginResult> => {\n try {\n const data = await loginMutate(credentials);\n\n if (data.result === \"two_factor_required\") {\n return { result: \"two_factor_required\", cookie: data.cookie, twoFactorMode: data.twoFactorMode };\n }\n\n queryClient.clear();\n setUserData(data.user);\n queryClient.setQueryData(accountKey, data.account);\n\n return { result: \"success\" };\n } catch (error) {\n const message =\n error instanceof Error\n ? error.message\n : \"Ocorreu um erro ao fazer login. Tente novamente.\";\n return { result: \"error\", message };\n }\n },\n [queryClient, setUserData, accountKey],\n );\n\n const register = useCallback(\n async (data: RegisterRequest): Promise<void> => {\n await registerMutate(data, {\n onSuccess: (data) => {\n queryClient.clear();\n setUserData(data.user);\n queryClient.setQueryData(accountKey, data.account);\n },\n });\n },\n [queryClient, setUserData, accountKey],\n );\n\n const loginWithGoogle = useCallback(\n async (idToken: string): Promise<GoogleLoginResult> => {\n try {\n const data = await googleLoginMutate(idToken);\n\n if (data.result === \"two_factor_required\") {\n return {\n result: \"two_factor_required\",\n cookie: data.cookie,\n twoFactorMode: data.twoFactorMode,\n };\n }\n\n if (data.result === \"needs_onboarding\") {\n return {\n result: \"needs_onboarding\",\n onboardingToken: data.onboardingToken,\n partial: data.partial,\n };\n }\n\n if (data.result === \"link_requires_password\") {\n return { result: \"link_requires_password\", message: data.message };\n }\n\n queryClient.clear();\n setUserData(data.user);\n queryClient.setQueryData(accountKey, data.account);\n\n return { result: \"success\" };\n } catch (error) {\n const message =\n error instanceof Error\n ? error.message\n : \"Ocorreu um erro ao fazer login com Google. Tente novamente.\";\n return { result: \"error\", message };\n }\n },\n [googleLoginMutate, queryClient, setUserData, accountKey],\n );\n\n const completeGoogleOnboarding = useCallback(\n async (data: SocialOnboardingRequest): Promise<void> => {\n await googleOnboardingMutate(data, {\n onSuccess: (data) => {\n queryClient.clear();\n setUserData(data.user);\n queryClient.setQueryData(accountKey, data.account);\n },\n });\n },\n [googleOnboardingMutate, queryClient, setUserData, accountKey],\n );\n\n const resolveLogoutRedirect = useCallback(() => {\n try {\n const currentOrigin = window.location.origin;\n const pagesOrigin = pagesUrl ? new URL(pagesUrl).origin : \"\";\n\n if (pagesOrigin && currentOrigin === pagesOrigin) {\n return `${accountsUrl}/login?redirect=${encodeURIComponent(pagesUrl)}`;\n }\n } catch {\n // fallback below\n }\n\n return `${accountsUrl}/login?redirect=${encodeURIComponent(pagesUrl || \"/\")}`;\n }, [accountsUrl, pagesUrl]);\n\n const logout = useCallback(async (): Promise<void> => {\n try {\n await logoutMutate(undefined);\n } catch {\n // cookie já removido no servidor mesmo se a API falhou\n } finally {\n queryClient.clear();\n window.location.assign(resolveLogoutRedirect());\n }\n }, [queryClient, logoutMutate, resolveLogoutRedirect]);\n\n const value: AuthContextProps = useMemo(\n () => ({\n user: user ?? null,\n account: account ?? null,\n isAuthenticated,\n isLoading,\n login,\n register,\n logout,\n loginWithGoogle,\n completeGoogleOnboarding,\n }),\n [\n user,\n account,\n isAuthenticated,\n isLoading,\n login,\n register,\n logout,\n loginWithGoogle,\n completeGoogleOnboarding,\n ],\n );\n\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;\n}\n\nexport function useAuth(): AuthContextProps {\n const context = useContext(AuthContext);\n\n if (context === undefined) {\n throw new Error(\"useAuth deve ser usado dentro de um AuthProvider\");\n }\n\n return context;\n}\n"],"mappings":";AA2OS;AAzOT;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,4BAA4B;AACrC,SAAS,iCAAiC;AAoB1C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAUvB,MAAM,cAAc;AAAA,EACzB;AACF;AAMO,SAAS,aAAa,EAAE,SAAS,GAAsB;AAC5D,QAAM,EAAE,MAAM,MAAM,WAAW,eAAe,IAAI,aAAa;AAC/D,QAAM,EAAE,MAAM,SAAS,WAAW,iBAAiB,IAAI,kBAAkB;AACzE,QAAM,EAAE,WAAW,iBAAiB,IAAI,uBAAuB;AAE/D,QAAM,cAAc,eAAe;AACnC,QAAM,cAAc,eA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ChD,eAAO,GAAG,WAAW,mBAAmB,mBAAmB,QAAQ,CAAC;AAAA,MACtE;AAAA,IACF,QAAQ;AAAA,IAER;AAEA,WAAO,GAAG,WAAW,mBAAmB,mBAAmB,YAAY,GAAG,CAAC;AAAA,EAC7E,GAAG,CAAC,aAAa,QAAQ,CAAC;AAE1B,QAAM,SAAS,YAAY,YAA2B;AACpD,QAAI;AACF,YAAM,aAAa,MAAS;AAAA,IAC9B,QAAQ;AAAA,IAER,UAAE;AACA,kBAAY,MAAM;AAClB,aAAO,SAAS,OAAO,sBAAsB,CAAC;AAAA,IAChD;AAAA,EACF,GAAG,CAAC,aAAa,cAAc,qBAAqB,CAAC;AAErD,QAAM,QAA0B;AAAA,IAC9B,OAAO;AAAA,MACL,MAAM,QAAQ;AAAA,MACd,SAAS,WAAW;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,oBAAC,YAAY,UAAZ,EAAqB,OAAe,UAAS;AACvD;AAEO,SAAS,UAA4B;AAC1C,QAAM,UAAU,WAAW,WAAW;AAEtC,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AAEA,SAAO;AACT;","names":["data"]}
|
|
1
|
+
{"version":3,"sources":["../../src/providers/auth.provider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n ReactNode,\n useCallback,\n useContext,\n useMemo,\n} from \"react\";\nimport { useQueryClient } from \"@tanstack/react-query\";\nimport {\n useUserQuery,\n useSetUserData,\n useUserValidateSession,\n} from \"../modules/auth/hooks/useUserQuery\";\nimport { useLogin } from \"../modules/auth/hooks/login.hook\";\nimport { useRegister } from \"../modules/auth/hooks/register.hook\";\nimport { useLogout } from \"../modules/auth/hooks/logout.hook\";\nimport {\n AuthState,\n LoginRequest,\n RegisterRequest,\n} from \"../modules/auth/schema\";\n\nexport type LoginResult =\n | { result: \"success\" }\n | { result: \"two_factor_required\"; cookie: string; twoFactorMode: \"verify\" | \"setup\" }\n | { result: \"error\"; message: string };\nimport {\n useCurrentAccount,\n ACCOUNT_QUERY_KEY,\n} from \"../modules/accounts/hooks/current-account.hook\";\nimport { useWhitelabelUrls } from \"./whitelabel.provider\";\nimport { useWlQueryKey } from \"../hooks/useAuthQueryKey\";\n\ninterface AuthContextProps extends AuthState {\n login: (credentials: LoginRequest) => Promise<LoginResult>;\n register: (data: RegisterRequest) => Promise<void>;\n logout: () => Promise<void>;\n}\n\nexport const AuthContext = createContext<AuthContextProps | undefined>(\n undefined,\n);\n\ninterface AuthProviderProps {\n children: ReactNode;\n}\n\nexport function AuthProvider({ children }: AuthProviderProps) {\n const { data: user, isLoading: isQueryLoading } = useUserQuery();\n const { data: account, isLoading: isAccountLoading } = useCurrentAccount();\n const { isLoading: isSessionLoading } = useUserValidateSession();\n\n const queryClient = useQueryClient();\n const setUserData = useSetUserData();\n const { accountsUrl, pagesUrl } = useWhitelabelUrls();\n const accountKey = useWlQueryKey([...ACCOUNT_QUERY_KEY]);\n\n const { mutateAsync: loginMutate, isPending: isLogging } = useLogin();\n const { mutateAsync: registerMutate, isPending: isRegistering } =\n useRegister();\n const { mutateAsync: logoutMutate, isPending: isLoggingOut } = useLogout();\n\n const isAuthenticated = !!user;\n const isLoading =\n isLogging ||\n isRegistering ||\n isLoggingOut ||\n isQueryLoading ||\n isAccountLoading ||\n isSessionLoading;\n\n const login = useCallback(\n async (credentials: LoginRequest): Promise<LoginResult> => {\n try {\n const data = await loginMutate(credentials);\n\n if (data.result === \"two_factor_required\") {\n return { result: \"two_factor_required\", cookie: data.cookie, twoFactorMode: data.twoFactorMode };\n }\n\n queryClient.clear();\n setUserData(data.user);\n queryClient.setQueryData(accountKey, data.account);\n\n return { result: \"success\" };\n } catch (error) {\n const message =\n error instanceof Error\n ? error.message\n : \"Ocorreu um erro ao fazer login. Tente novamente.\";\n return { result: \"error\", message };\n }\n },\n [queryClient, setUserData, accountKey],\n );\n\n const register = useCallback(\n async (data: RegisterRequest): Promise<void> => {\n await registerMutate(data, {\n onSuccess: (data) => {\n queryClient.clear();\n setUserData(data.user);\n queryClient.setQueryData(accountKey, data.account);\n },\n });\n },\n [queryClient, setUserData, accountKey],\n );\n\n const resolveLogoutRedirect = useCallback(() => {\n try {\n const currentOrigin = window.location.origin;\n const pagesOrigin = pagesUrl ? new URL(pagesUrl).origin : \"\";\n\n if (pagesOrigin && currentOrigin === pagesOrigin) {\n return `${accountsUrl}/login?redirect=${encodeURIComponent(pagesUrl)}`;\n }\n } catch {\n // fallback below\n }\n\n return `${accountsUrl}/login?redirect=${encodeURIComponent(pagesUrl || \"/\")}`;\n }, [accountsUrl, pagesUrl]);\n\n const logout = useCallback(async (): Promise<void> => {\n try {\n await logoutMutate(undefined);\n } catch {\n // cookie já removido no servidor mesmo se a API falhou\n } finally {\n queryClient.clear();\n window.location.assign(resolveLogoutRedirect());\n }\n }, [queryClient, logoutMutate, resolveLogoutRedirect]);\n\n const value: AuthContextProps = useMemo(\n () => ({\n user: user ?? null,\n account: account ?? null,\n isAuthenticated,\n isLoading,\n login,\n register,\n logout,\n }),\n [user, account, isAuthenticated, isLoading, login, register, logout],\n );\n\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;\n}\n\nexport function useAuth(): AuthContextProps {\n const context = useContext(AuthContext);\n\n if (context === undefined) {\n throw new Error(\"useAuth deve ser usado dentro de um AuthProvider\");\n }\n\n return context;\n}\n"],"mappings":";AAsJS;AApJT;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAC5B,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kD;AAAA,EACpE;AAEA,SAAO;AACT;","names":["data"]}
|
package/dist/server.mjs
CHANGED
|
@@ -14,9 +14,6 @@ import { chargesService } from "./modules/charges/services/charges.service";
|
|
|
14
14
|
import { iaCreditsService } from "./modules/ia-credits/services/ia-credits.service";
|
|
15
15
|
import { findWhitelabel } from "./modules/whitelabel/actions/find-whitelabel.action";
|
|
16
16
|
import { validateSessionAction } from "./modules/auth/actions/validate-session.action";
|
|
17
|
-
import { socialGoogleLoginAction } from "./modules/auth/actions/social-google-login.action";
|
|
18
|
-
import { socialGoogleOnboardingAction } from "./modules/auth/actions/social-google-onboarding.action";
|
|
19
|
-
import { unlinkGoogleAction } from "./modules/auth/actions/unlink-google.action";
|
|
20
17
|
import { findUserById } from "./modules/users/action/find-user-by-id.action";
|
|
21
18
|
import { findCurrentAccount } from "./modules/accounts/actions/find-current-account.action";
|
|
22
19
|
import { getAccountTokenAction } from "./modules/accounts/actions/get-account-token.action";
|
|
@@ -140,11 +137,8 @@ export {
|
|
|
140
137
|
revalidateWhitelabelAction,
|
|
141
138
|
safeMutationAction,
|
|
142
139
|
safeServerAction,
|
|
143
|
-
socialGoogleLoginAction,
|
|
144
|
-
socialGoogleOnboardingAction,
|
|
145
140
|
subscriptionsService,
|
|
146
141
|
twoFactorService,
|
|
147
|
-
unlinkGoogleAction,
|
|
148
142
|
updateAccountAction,
|
|
149
143
|
updateAccountUserByIdAction,
|
|
150
144
|
updateProjectAction,
|
package/dist/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import 'server-only';\r\n\r\n// API Client\r\nexport { ApiClient, api, apiClient } from './infra/api/client';\r\n\r\n// Services\r\nexport { authService } from './modules/auth/services/auth.service';\r\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\r\nexport { revalidateWhitelabelAction } from './modules/whitelabel/actions/revalidate-whitelabel.action';\r\nexport { assertManagementPermission } from './modules/auth/utils/assert-management-permission';\r\nexport { assertManagementSubscription } from './modules/auth/utils/assert-management-subscription';\r\nexport { assertSubscriptionAddon } from './modules/auth/utils/assert-subscription-addon';\r\nexport { assertPaidSubscription } from './modules/auth/utils/assert-paid-subscription';\r\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';\r\nexport { plansService } from './modules/plans/services/plans.service';\r\nexport { cardsService } from './modules/cards/services/cards.service';\r\nexport { chargesService } from './modules/charges/services/charges.service';\r\nexport { iaCreditsService } from './modules/ia-credits/services/ia-credits.service';\r\n\r\n// Actions\r\nexport { findWhitelabel } from './modules/whitelabel/actions/find-whitelabel.action';\r\nexport { validateSessionAction } from './modules/auth/actions/validate-session.action';\r\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import 'server-only';\r\n\r\n// API Client\r\nexport { ApiClient, api, apiClient } from './infra/api/client';\r\n\r\n// Services\r\nexport { authService } from './modules/auth/services/auth.service';\r\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\r\nexport { revalidateWhitelabelAction } from './modules/whitelabel/actions/revalidate-whitelabel.action';\r\nexport { assertManagementPermission } from './modules/auth/utils/assert-management-permission';\r\nexport { assertManagementSubscription } from './modules/auth/utils/assert-management-subscription';\r\nexport { assertSubscriptionAddon } from './modules/auth/utils/assert-subscription-addon';\r\nexport { assertPaidSubscription } from './modules/auth/utils/assert-paid-subscription';\r\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';\r\nexport { plansService } from './modules/plans/services/plans.service';\r\nexport { cardsService } from './modules/cards/services/cards.service';\r\nexport { chargesService } from './modules/charges/services/charges.service';\r\nexport { iaCreditsService } from './modules/ia-credits/services/ia-credits.service';\r\n\r\n// Actions\r\nexport { findWhitelabel } from './modules/whitelabel/actions/find-whitelabel.action';\r\nexport { validateSessionAction } from './modules/auth/actions/validate-session.action';\r\nexport { findUserById } from './modules/users/action/find-user-by-id.action';\r\nexport { findCurrentAccount } from './modules/accounts/actions/find-current-account.action';\r\nexport { getAccountTokenAction } from './modules/accounts/actions/get-account-token.action';\r\nexport { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';\r\nexport { findPlanByIdAction } from './modules/plans/actions/find-plan-by-id.action';\r\nexport { listPlansAction } from './modules/plans/actions/list-plans.action';\r\nexport { calculateSubscriptionAction } from './modules/subscriptions/actions/calculate-subscription.action';\r\nexport { updateSubscriptionPlanAction } from './modules/subscriptions/actions/update-subscription-plan.action';\r\nexport { updateSubscriptionPaymentAction } from './modules/subscriptions/actions/update-subscription-payment.action';\r\nexport { listCardsAction } from './modules/cards/actions/list-cards.action';\r\nexport { createCardAction } from './modules/cards/actions/create-card.action';\r\nexport { createSetupIntentAction } from './modules/cards/actions/create-setup-intent.action';\r\nexport { listChargesAction } from './modules/charges/actions/list-charges.action';\r\nexport { findChargeByIdAction } from './modules/charges/actions/find-charge-by-id.action';\r\nexport { chargeActionAction } from './modules/charges/actions/charge-action.action';\r\nexport { resolvePlanExtrasPrices } from './modules/subscriptions/utils/resolve-plan-extras-prices';\r\nexport { hasSubscriptionExpired } from './modules/subscriptions/utils/has-subscription-expired';\r\nexport { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';\r\nexport { countPagesAction } from './modules/pages/actions/count-pages.action';\r\n\r\n// Project Services & Actions (server-only)\r\nexport { projectsService } from './modules/projects/services/projects.service';\r\nexport { listProjectsAction } from './modules/projects/actions/list-projects.action';\r\nexport { findProjectAction } from './modules/projects/actions/find-project.action';\r\nexport { createProjectAction } from './modules/projects/actions/create-project.action';\r\nexport { updateProjectAction } from './modules/projects/actions/update-project.action';\r\nexport { deleteProjectAction } from './modules/projects/actions/delete-project.action';\r\n\r\n// Project Users Services & Actions (server-only)\r\nexport { projectUsersService } from './modules/projects/services/project-users.service';\r\nexport { listProjectUsersAction } from './modules/projects/actions/list-project-users.action';\r\nexport { listAvailableUsersAction } from './modules/projects/actions/list-available-users.action';\r\nexport { addProjectUserAction } from './modules/projects/actions/add-project-user.action';\r\nexport { removeProjectUserAction } from './modules/projects/actions/remove-project-user.action';\r\n\r\n// Account Services & Actions (server-only)\r\nexport { accountService } from './modules/accounts/services/account.service';\r\nexport { twoFactorService } from './modules/accounts/services/two-factor.service';\r\nexport {\r\n listAccountUsersAction,\r\n updateUserAction,\r\n updateAccountAction,\r\n updateAccountUserByIdAction,\r\n deleteAccountUserAction,\r\n deleteAccountAction,\r\n createAccountUserAction,\r\n changePasswordAction,\r\n requestEmailChangeAction,\r\n confirmEmailChangeAction,\r\n requestPhoneChangeAction,\r\n confirmPhoneChangeAction,\r\n generateTwoFactorAction,\r\n confirmTwoFactorAction,\r\n disableTwoFactorAction,\r\n} from './modules/accounts/actions/account-management.action';\r\n\r\n// Server Utils\r\nexport { getClientInfoFromRequest } from './infra/utils/client-info';\r\nexport { getUserContext } from './modules/auth/utils/get-user-context';\r\nexport { requireValidSession } from './modules/auth/utils/require-valid-session';\r\nexport { requireTokenNotExpired } from './modules/auth/utils/require-token-not-expired';\r\nexport { buildWlOverride, buildWlOverrideFromJwt } from './modules/auth/utils/build-wl-override';\r\nexport { safeServerAction } from './utils/safeServerAction';\r\nexport { safeMutationAction } from './utils/safeMutationAction';\r\n\r\n// Image Processing (server-side)\r\nexport { processImageAction } from './modules/images/actions/process-image.action';\r\nexport { processImage } from './modules/images/services/image-processing.service';\r\nexport type {\r\n ProcessImageInput,\r\n ProcessImageOutput,\r\n ProcessImageActionInput,\r\n ProcessImageActionOutput,\r\n} from './modules/images/types/image.type';\r\n"],"mappings":"AAAA,OAAO;AAGP,SAAS,WAAW,KAAK,iBAAiB;AAG1C,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,kCAAkC;AAC3C,SAAS,kCAAkC;AAC3C,SAAS,oCAAoC;AAC7C,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AACvC,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAGjC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,mCAAmC;AAC5C,SAAS,oCAAoC;AAC7C,SAAS,uCAAuC;AAChD,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AACxC,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AACrC,SAAS,0BAA0B;AACnC,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AAGjC,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AAGpC,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,gCAAgC;AACzC,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AAGxC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,gCAAgC;AACzC,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,iBAAiB,8BAA8B;AACxD,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AAGnC,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { IconAlertTriangle
|
|
4
|
-
import {
|
|
5
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { IconAlertTriangle } from '@tabler/icons-react';
|
|
4
|
+
import { Button } from '../../ui/buttons/Button';
|
|
6
5
|
import { useAuth } from '../../../providers/auth.provider';
|
|
7
6
|
import { AccountSectionType } from '../../../enums/AccountSectionType';
|
|
8
|
-
import { useUnlinkGoogle } from '../../../modules/auth/hooks/unlink-google.hook';
|
|
9
|
-
import { USER_QUERY_KEY } from '../../../modules/auth/hooks/useUserQuery';
|
|
10
|
-
import { Toast } from '../../ui/feedback/Toast';
|
|
11
7
|
|
|
12
8
|
interface SecuritySectionProps {
|
|
13
9
|
setActiveSection: (section: AccountSectionType) => void;
|
|
@@ -16,56 +12,13 @@ interface SecuritySectionProps {
|
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
export function SecuritySection({
|
|
15
|
+
onClose,
|
|
19
16
|
onDeleteAccount,
|
|
20
17
|
}: SecuritySectionProps) {
|
|
21
|
-
const { user } = useAuth();
|
|
22
|
-
const queryClient = useQueryClient();
|
|
23
|
-
const { mutateAsync: unlinkGoogle, isPending: isUnlinking } = useUnlinkGoogle();
|
|
24
|
-
const hasGoogleLinked = !!user?.google_sub;
|
|
25
|
-
|
|
26
|
-
const handleUnlinkGoogle = async () => {
|
|
27
|
-
try {
|
|
28
|
-
const result = await unlinkGoogle();
|
|
29
|
-
toast.custom((t) => (
|
|
30
|
-
<Toast variant="success" message={result.message} toastId={t} />
|
|
31
|
-
));
|
|
32
|
-
queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
33
|
-
} catch (error) {
|
|
34
|
-
const message =
|
|
35
|
-
error instanceof Error ? error.message : 'Erro ao desvincular conta Google.';
|
|
36
|
-
toast.custom((t) => <Toast variant="error" message={message} toastId={t} />);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
18
|
return (
|
|
41
19
|
<div className="h-full overflow-y-auto overscroll-contain px-4 pb-20 lg:p-5 lg:pt-5 flex flex-col gap-5 lg:gap-6 lg:pb-31 lg:overscroll-auto">
|
|
42
20
|
<span className="paragraph-medium-semibold text-gray-950 hidden lg:block">Segurança</span>
|
|
43
21
|
|
|
44
|
-
{hasGoogleLinked && (
|
|
45
|
-
<div className="flex flex-col items-center lg:items-start gap-4">
|
|
46
|
-
<div className="size-10 rounded-lg bg-blue-50 flex items-center justify-center">
|
|
47
|
-
<IconBrandGoogleFilled size={20} className="text-blue-500" />
|
|
48
|
-
</div>
|
|
49
|
-
|
|
50
|
-
<div className="flex flex-col gap-2">
|
|
51
|
-
<span className="paragraph-medium-semibold text-gray-950">Conta Google vinculada</span>
|
|
52
|
-
<span className="paragraph-small-regular text-gray-600">
|
|
53
|
-
Sua conta está vinculada ao Google. Se desvincular, use "Esqueci minha senha" para
|
|
54
|
-
redefinir uma senha de acesso por e-mail.
|
|
55
|
-
</span>
|
|
56
|
-
</div>
|
|
57
|
-
|
|
58
|
-
<button
|
|
59
|
-
type="button"
|
|
60
|
-
disabled={isUnlinking}
|
|
61
|
-
className="paragraph-small-semibold text-zinc-700 bg-zinc-100 rounded-lg px-3 py-2 cursor-pointer hover:bg-zinc-200 transition-colors w-fit disabled:opacity-50 disabled:cursor-not-allowed"
|
|
62
|
-
onClick={handleUnlinkGoogle}
|
|
63
|
-
>
|
|
64
|
-
{isUnlinking ? 'Desvinculando...' : 'Desvincular Google'}
|
|
65
|
-
</button>
|
|
66
|
-
</div>
|
|
67
|
-
)}
|
|
68
|
-
|
|
69
22
|
<div className="flex flex-col items-center lg:items-start gap-4">
|
|
70
23
|
<div className="size-10 rounded-lg bg-red-50 flex items-center justify-center">
|
|
71
24
|
<IconAlertTriangle size={20} className="text-red-500" />
|
|
@@ -42,6 +42,8 @@ export function SubscriptionBanner({ onReactivate, onDetails }: SubscriptionBann
|
|
|
42
42
|
return <CancelledSubscriptionBanner onReactivate={onReactivate} />;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
if (subscription.type === 'whitelabel') return null;
|
|
46
|
+
|
|
45
47
|
if (daysSinceDue > 0 && daysSinceDue <= SUBSCRIPTION_GRACE_PERIOD_DAYS) {
|
|
46
48
|
return <OverdueInvoiceBanner onDetails={onDetails} />;
|
|
47
49
|
}
|
package/src/index.ts
CHANGED
|
@@ -62,9 +62,6 @@ export {
|
|
|
62
62
|
} from "./modules/auth/hooks/useUserQuery";
|
|
63
63
|
export { useManagementPermissions } from "./modules/auth/hooks/useManagementPermissions";
|
|
64
64
|
export type { ManagementPermission } from "./modules/auth/types/management-permission.type";
|
|
65
|
-
export { useSocialGoogleLogin } from "./modules/auth/hooks/social-google-login.hook";
|
|
66
|
-
export { useSocialGoogleOnboarding } from "./modules/auth/hooks/social-google-onboarding.hook";
|
|
67
|
-
export { useUnlinkGoogle } from "./modules/auth/hooks/unlink-google.hook";
|
|
68
65
|
export { useSubscriptions } from "./modules/subscriptions/hooks/list-subscriptions.hook";
|
|
69
66
|
export {
|
|
70
67
|
SUBSCRIPTIONS_QUERY_KEY,
|
|
@@ -279,77 +279,3 @@ export interface LogoutApiResponse {
|
|
|
279
279
|
export interface LogoutResponse {
|
|
280
280
|
success: boolean;
|
|
281
281
|
}
|
|
282
|
-
|
|
283
|
-
export interface SocialGooglePartial {
|
|
284
|
-
name?: string;
|
|
285
|
-
last_name?: string;
|
|
286
|
-
email: string;
|
|
287
|
-
picture?: string;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export interface SocialGoogleApiResponse {
|
|
291
|
-
status: 0 | 1;
|
|
292
|
-
message?: string;
|
|
293
|
-
code?: string;
|
|
294
|
-
cookie?: string;
|
|
295
|
-
two_factor_required?: 'verify' | 'setup';
|
|
296
|
-
needs_onboarding?: boolean;
|
|
297
|
-
onboarding_token?: string;
|
|
298
|
-
partial?: SocialGooglePartial;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
export type SocialGoogleResponse =
|
|
302
|
-
| { result: 'success'; user: User; account: Account; accessToken: string; expiresAt: string }
|
|
303
|
-
| { result: 'two_factor_required'; cookie: string; twoFactorMode: 'verify' | 'setup' }
|
|
304
|
-
| { result: 'needs_onboarding'; onboardingToken: string; partial: SocialGooglePartial }
|
|
305
|
-
| { result: 'link_requires_password'; message: string };
|
|
306
|
-
|
|
307
|
-
export interface SocialOnboardingUserPayload {
|
|
308
|
-
name?: string;
|
|
309
|
-
last_name?: string;
|
|
310
|
-
ddi?: string;
|
|
311
|
-
phone?: string;
|
|
312
|
-
gender?: number;
|
|
313
|
-
rg?: string;
|
|
314
|
-
cpf?: string;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export interface SocialOnboardingRequest {
|
|
318
|
-
onboardingToken: string;
|
|
319
|
-
user: SocialOnboardingUserPayload;
|
|
320
|
-
acceptTerms: boolean;
|
|
321
|
-
affiliateId?: number | string;
|
|
322
|
-
couponId?: number | string;
|
|
323
|
-
idPlan?: number | string;
|
|
324
|
-
origin?: string;
|
|
325
|
-
trialDays?: number;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
export interface SocialOnboardingApiResponse {
|
|
329
|
-
status: 0 | 1;
|
|
330
|
-
message?: string;
|
|
331
|
-
cookie?: string;
|
|
332
|
-
data?: RegisterApiResponse['data'];
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export interface SocialOnboardingResponse {
|
|
336
|
-
user: User;
|
|
337
|
-
account: Account;
|
|
338
|
-
accessToken: string;
|
|
339
|
-
expiresAt: string;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
export interface UnlinkGoogleRequest {
|
|
343
|
-
idAccount: number;
|
|
344
|
-
idUser: number;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export interface UnlinkGoogleApiResponse {
|
|
348
|
-
status: 0 | 1;
|
|
349
|
-
message: string;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
export interface UnlinkGoogleResponse {
|
|
353
|
-
success: boolean;
|
|
354
|
-
message: string;
|
|
355
|
-
}
|