@greatapps/common 1.1.772 → 1.1.774
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 +4 -2
- package/dist/components/account/sections/SecuritySection.mjs.map +1 -1
- package/dist/modules/auth/services/auth.service.mjs +8 -5
- package/dist/modules/auth/services/auth.service.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/account/sections/SecuritySection.tsx +5 -3
- package/src/modules/auth/services/auth.service.ts +707 -693
|
@@ -7,6 +7,7 @@ import { useQueryClient } from "@tanstack/react-query";
|
|
|
7
7
|
import { useAuth } from "../../../providers/auth.provider";
|
|
8
8
|
import { useUnlinkGoogle } from "../../../modules/auth/hooks/unlink-google.hook";
|
|
9
9
|
import { USER_QUERY_KEY } from "../../../modules/auth/hooks/useUserQuery";
|
|
10
|
+
import { Button } from "../../ui/buttons/Button";
|
|
10
11
|
import { Toast } from "../../ui/feedback/Toast";
|
|
11
12
|
import { GoogleIcon } from "../../ui/data-display/GoogleIcon";
|
|
12
13
|
function SecuritySection({
|
|
@@ -36,11 +37,12 @@ function SecuritySection({
|
|
|
36
37
|
/* @__PURE__ */ jsx("span", { className: "paragraph-small-regular text-gray-600", children: translate("common.account.security.googleLinkedDescription") })
|
|
37
38
|
] }),
|
|
38
39
|
/* @__PURE__ */ jsx(
|
|
39
|
-
|
|
40
|
+
Button,
|
|
40
41
|
{
|
|
42
|
+
variant: "secondary",
|
|
43
|
+
className: "h-10! w-fit",
|
|
41
44
|
type: "button",
|
|
42
45
|
disabled: isUnlinking,
|
|
43
|
-
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",
|
|
44
46
|
onClick: handleUnlinkGoogle,
|
|
45
47
|
children: isUnlinking ? translate("common.account.security.unlinking") : translate("common.account.security.unlinkGoogle")
|
|
46
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/account/sections/SecuritySection.tsx"],"sourcesContent":["'use client';\n\nimport { IconAlertTriangle } from '@tabler/icons-react';\nimport { useTranslations } from 'next-intl';\nimport { toast } from 'sonner';\nimport { useQueryClient } from '@tanstack/react-query';\nimport { useAuth } from '../../../providers/auth.provider';\nimport { AccountSectionType } from '../../../enums/AccountSectionType';\nimport { useUnlinkGoogle } from '../../../modules/auth/hooks/unlink-google.hook';\nimport { USER_QUERY_KEY } from '../../../modules/auth/hooks/useUserQuery';\nimport { Toast } from '../../ui/feedback/Toast';\nimport { GoogleIcon } from '../../ui/data-display/GoogleIcon';\n\ninterface SecuritySectionProps {\n setActiveSection: (section: AccountSectionType) => void;\n onClose: () => void;\n onDeleteAccount?: () => void;\n}\n\nexport function SecuritySection({\n onDeleteAccount,\n}: SecuritySectionProps) {\n const translate = useTranslations();\n const { user } = useAuth();\n const queryClient = useQueryClient();\n const { mutateAsync: unlinkGoogle, isPending: isUnlinking } = useUnlinkGoogle();\n const hasGoogleLinked = !!user?.google_sub;\n\n const handleUnlinkGoogle = async () => {\n try {\n const result = await unlinkGoogle();\n toast.custom((t) => (\n <Toast variant=\"success\" message={result.message} toastId={t} />\n ));\n queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });\n } catch (error) {\n const message =\n error instanceof Error ? error.message : translate('common.account.security.unlinkError');\n toast.custom((toastId) => <Toast variant=\"error\" message={message} toastId={toastId} />);\n }\n };\n\n return (\n <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\">\n <span className=\"paragraph-medium-semibold text-gray-950 hidden lg:block\">\n {translate('common.account.security.title')}\n </span>\n\n {hasGoogleLinked && (\n <div className=\"flex flex-col items-center lg:items-start gap-4\">\n <div className=\"size-10 rounded-lg bg-gray-50 flex items-center justify-center\">\n <GoogleIcon size={20} />\n </div>\n\n <div className=\"flex flex-col gap-2\">\n <span className=\"paragraph-medium-semibold text-gray-950\">\n {translate('common.account.security.googleLinkedTitle')}\n </span>\n <span className=\"paragraph-small-regular text-gray-600\">\n {translate('common.account.security.googleLinkedDescription')}\n </span>\n </div>\n\n <
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/account/sections/SecuritySection.tsx"],"sourcesContent":["'use client';\n\nimport { IconAlertTriangle } from '@tabler/icons-react';\nimport { useTranslations } from 'next-intl';\nimport { toast } from 'sonner';\nimport { useQueryClient } from '@tanstack/react-query';\nimport { useAuth } from '../../../providers/auth.provider';\nimport { AccountSectionType } from '../../../enums/AccountSectionType';\nimport { useUnlinkGoogle } from '../../../modules/auth/hooks/unlink-google.hook';\nimport { USER_QUERY_KEY } from '../../../modules/auth/hooks/useUserQuery';\nimport { Button } from '../../ui/buttons/Button';\nimport { Toast } from '../../ui/feedback/Toast';\nimport { GoogleIcon } from '../../ui/data-display/GoogleIcon';\n\ninterface SecuritySectionProps {\n setActiveSection: (section: AccountSectionType) => void;\n onClose: () => void;\n onDeleteAccount?: () => void;\n}\n\nexport function SecuritySection({\n onDeleteAccount,\n}: SecuritySectionProps) {\n const translate = useTranslations();\n const { user } = useAuth();\n const queryClient = useQueryClient();\n const { mutateAsync: unlinkGoogle, isPending: isUnlinking } = useUnlinkGoogle();\n const hasGoogleLinked = !!user?.google_sub;\n\n const handleUnlinkGoogle = async () => {\n try {\n const result = await unlinkGoogle();\n toast.custom((t) => (\n <Toast variant=\"success\" message={result.message} toastId={t} />\n ));\n queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });\n } catch (error) {\n const message =\n error instanceof Error ? error.message : translate('common.account.security.unlinkError');\n toast.custom((toastId) => <Toast variant=\"error\" message={message} toastId={toastId} />);\n }\n };\n\n return (\n <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\">\n <span className=\"paragraph-medium-semibold text-gray-950 hidden lg:block\">\n {translate('common.account.security.title')}\n </span>\n\n {hasGoogleLinked && (\n <div className=\"flex flex-col items-center lg:items-start gap-4\">\n <div className=\"size-10 rounded-lg bg-gray-50 flex items-center justify-center\">\n <GoogleIcon size={20} />\n </div>\n\n <div className=\"flex flex-col gap-2\">\n <span className=\"paragraph-medium-semibold text-gray-950\">\n {translate('common.account.security.googleLinkedTitle')}\n </span>\n <span className=\"paragraph-small-regular text-gray-600\">\n {translate('common.account.security.googleLinkedDescription')}\n </span>\n </div>\n\n <Button\n variant=\"secondary\"\n className=\"h-10! w-fit\"\n type=\"button\"\n disabled={isUnlinking}\n onClick={handleUnlinkGoogle}\n >\n {isUnlinking\n ? translate('common.account.security.unlinking')\n : translate('common.account.security.unlinkGoogle')}\n </Button>\n </div>\n )}\n\n <div className=\"flex flex-col items-center lg:items-start gap-4\">\n <div className=\"size-10 rounded-lg bg-red-50 flex items-center justify-center\">\n <IconAlertTriangle size={20} className=\"text-red-500\" />\n </div>\n\n <div className=\"flex flex-col gap-2\">\n <span className=\"paragraph-medium-semibold text-gray-950\">\n {translate('common.account.deleteAccount.title')}\n </span>\n <span className=\"paragraph-small-regular text-gray-600\">\n {translate('common.account.security.deleteAccountDescription')}\n </span>\n </div>\n\n {onDeleteAccount && (\n <button\n type=\"button\"\n className=\"paragraph-small-semibold text-red-600 bg-red-50 rounded-lg px-3 py-2 cursor-pointer hover:bg-red-100 transition-colors w-fit\"\n onClick={onDeleteAccount}\n >\n {translate('common.account.security.deleteMyAccount')}\n </button>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";AAiCQ,cAsBE,YAtBF;AA/BR,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,aAAa;AACtB,SAAS,sBAAsB;AAC/B,SAAS,eAAe;AAExB,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAQpB,SAAS,gBAAg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C,qBAAkB,MAAM,IAAI,WAAU,gBAAe,GACxD;AAAA,MAEA,qBAAC,SAAI,WAAU,uBACb;AAAA,4BAAC,UAAK,WAAU,2CACb,oBAAU,oCAAoC,GACjD;AAAA,QACA,oBAAC,UAAK,WAAU,yCACb,oBAAU,kDAAkD,GAC/D;AAAA,SACF;AAAA,MAEC,mBACC;AAAA,QAAC;AAAA;AAAA,UACC,MAAK;AAAA,UACL,WAAU;AAAA,UACV,SAAS;AAAA,UAER,oBAAU,yCAAyC;AAAA;AAAA,MACtD;AAAA,OAEJ;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -6,6 +6,10 @@ import { buildWlOverrideFromJwt } from "../utils/build-wl-override";
|
|
|
6
6
|
import { findWhitelabel } from "../../../server";
|
|
7
7
|
const AUTH_COOKIE_NAME = "greatapps";
|
|
8
8
|
const COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
|
|
9
|
+
const FREE_PLAN_ID = 5;
|
|
10
|
+
function isFreePlan(idPlan) {
|
|
11
|
+
return idPlan === -1 || idPlan === FREE_PLAN_ID;
|
|
12
|
+
}
|
|
9
13
|
const COOKIE_OPTIONS = {
|
|
10
14
|
httpOnly: true,
|
|
11
15
|
secure: process.env.NODE_ENV === "production",
|
|
@@ -204,10 +208,10 @@ class AuthService {
|
|
|
204
208
|
profile: "owner",
|
|
205
209
|
language: "pt-br"
|
|
206
210
|
},
|
|
207
|
-
subscription: idPlan
|
|
211
|
+
subscription: isFreePlan(idPlan) ? {
|
|
208
212
|
type: "free",
|
|
209
213
|
id_coupon: data.couponId || 0,
|
|
210
|
-
id_plan:
|
|
214
|
+
id_plan: FREE_PLAN_ID,
|
|
211
215
|
id_product: 1
|
|
212
216
|
} : {
|
|
213
217
|
type: "trial",
|
|
@@ -299,11 +303,10 @@ class AuthService {
|
|
|
299
303
|
profile: "owner",
|
|
300
304
|
language: "pt-br"
|
|
301
305
|
},
|
|
302
|
-
subscription: idPlan
|
|
306
|
+
subscription: isFreePlan(idPlan) ? {
|
|
303
307
|
type: "free",
|
|
304
308
|
id_coupon: data.couponId || 0,
|
|
305
|
-
id_plan:
|
|
306
|
-
// Plano Free (ID fixo)
|
|
309
|
+
id_plan: FREE_PLAN_ID,
|
|
307
310
|
id_product: 1
|
|
308
311
|
} : {
|
|
309
312
|
type: "trial",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/services/auth.service.ts"],"sourcesContent":["import { cookies } from \"next/headers\";\r\n\r\nimport { api, type RequestConfig } from \"../../../infra/api/client\";\r\nimport { ApiError } from \"../../../infra/api/types\";\r\nimport { whitelabelService } from \"../../whitelabel/services/whitelabel.service\";\r\nimport { buildWlOverrideFromJwt } from \"../utils/build-wl-override\";\r\nimport {\r\n ClientInfo,\r\n ForgotPasswordRequest,\r\n ForgotPasswordResponse,\r\n GeoLocation,\r\n LoginApiResponse,\r\n LoginRequest,\r\n LoginResponse,\r\n LogoutApiResponse,\r\n LogoutRequest,\r\n LogoutResponse,\r\n RegisterApiRequest,\r\n RegisterApiResponse,\r\n RegisterRequest,\r\n RegisterResponse,\r\n ResendVerificationRequest,\r\n ResendVerificationResponse,\r\n ResetPasswordRequest,\r\n ResetPasswordResponse,\r\n SearchPlansApiResponse,\r\n SessionKeepRequest,\r\n SessionKeepResponse,\r\n SocialGoogleApiResponse,\r\n SocialGoogleResponse,\r\n SocialOnboardingApiResponse,\r\n SocialOnboardingRequest,\r\n SocialOnboardingResponse,\r\n IsolatedLoginResponse,\r\n TwoFactorApiResponse,\r\n TwoFactorRequest,\r\n TwoFactorResponse,\r\n UnlinkGoogleApiResponse,\r\n UnlinkGoogleResponse,\r\n VerifyEmailRequest,\r\n VerifyEmailResponse,\r\n} from \"../schema\";\r\nimport { findWhitelabel } from \"../../../server\";\r\n\r\nconst AUTH_COOKIE_NAME = \"greatapps\";\r\nconst COOKIE_MAX_AGE = 60 * 60 * 24 * 30;\r\n\r\nconst COOKIE_OPTIONS = {\r\n httpOnly: true,\r\n secure: process.env.NODE_ENV === \"production\",\r\n sameSite: \"lax\" as const,\r\n path: \"/\",\r\n};\r\n\r\nclass AuthService {\r\n async login(\r\n credentials: LoginRequest,\r\n clientInfo: ClientInfo,\r\n ): Promise<LoginResponse>;\r\n async login(\r\n credentials: LoginRequest,\r\n clientInfo: ClientInfo,\r\n options: { setCookie: false },\r\n ): Promise<IsolatedLoginResponse>;\r\n async login(\r\n credentials: LoginRequest,\r\n clientInfo: ClientInfo,\r\n options?: { setCookie?: boolean },\r\n ): Promise<LoginResponse | IsolatedLoginResponse>;\r\n async login(\r\n credentials: LoginRequest,\r\n clientInfo: ClientInfo,\r\n options?: { setCookie?: boolean },\r\n ): Promise<LoginResponse | IsolatedLoginResponse> {\r\n let requestConfig: RequestConfig | undefined;\r\n if (credentials.id_wl) {\r\n const wlToken = await whitelabelService.getTokenByWhitelabelId(\r\n credentials.id_wl,\r\n );\r\n requestConfig = { whiteLabelId: credentials.id_wl, authToken: wlToken };\r\n }\r\n\r\n const response = await api.apps.post<LoginApiResponse>(\r\n \"/auth/login\",\r\n {\r\n email: credentials.email,\r\n password: credentials.password,\r\n source: credentials?.source,\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n },\r\n requestConfig,\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"E-mail ou senha incorretos\",\r\n response.code || \"LOGIN_FAILED\",\r\n 401,\r\n );\r\n }\r\n\r\n if (!response.cookie) {\r\n throw new ApiError(\r\n \"Resposta de autenticação inválida\",\r\n \"INVALID_RESPONSE\",\r\n 500,\r\n );\r\n }\r\n\r\n if (response.two_factor_required) {\r\n return { result: \"two_factor_required\", cookie: response.cookie, twoFactorMode: response.two_factor_required };\r\n }\r\n\r\n // Modo isolado: caller só quer o token, sem afetar a sessão do navegador\r\n // nem pagar pelas chamadas de user/account (ex.: fluxo de SSO).\r\n if (options?.setCookie === false) {\r\n return { result: \"success\", accessToken: response.cookie };\r\n }\r\n\r\n await this.setAuthCookie(response.cookie);\r\n\r\n const [{ userService }, { accountService }] = await Promise.all([\r\n import(\"../../users/services/user.service\"),\r\n import(\"../../accounts/services/account.service\"),\r\n ]);\r\n const [user, account] = await Promise.all([\r\n userService.findById(\r\n requestConfig ? { authToken: requestConfig.authToken } : undefined,\r\n ),\r\n accountService.findCurrentAccount(requestConfig),\r\n ]);\r\n\r\n return {\r\n result: \"success\",\r\n user,\r\n account,\r\n accessToken: response.cookie,\r\n refreshToken: \"\",\r\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\r\n };\r\n }\r\n\r\n async verifyTwoFactor(\r\n cookie: string,\r\n code: string,\r\n clientInfo: ClientInfo,\r\n options?: { window?: number; setCookie?: boolean },\r\n ): Promise<TwoFactorResponse> {\r\n const payload: TwoFactorRequest = {\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n cookie,\r\n code,\r\n };\r\n\r\n const endpoint = options?.window !== undefined ? `/auth/code?window=${options.window}` : '/auth/code';\r\n const response = await api.apps.post<TwoFactorApiResponse>(\r\n endpoint,\r\n payload,\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\"Código 2FA inválido\", \"TWO_FACTOR_FAILED\", 401);\r\n }\r\n\r\n if (!response?.data?.cookie) {\r\n throw new ApiError(\r\n \"Resposta de autenticação inválida após 2FA\",\r\n \"INVALID_RESPONSE\",\r\n 500,\r\n );\r\n }\r\n\r\n // Modo isolado: devolve o token sem gravar o cookie — o caller redireciona\r\n // pra outro lugar (ex.: SSO callback) e não quer mexer na sessão atual.\r\n if (options?.setCookie === false) {\r\n return { status: 1, accessToken: response.data.cookie };\r\n }\r\n\r\n await this.setAuthCookie(response.data.cookie);\r\n\r\n return { status: 1 };\r\n }\r\n\r\n async socialLoginGoogle(\r\n code: string,\r\n clientInfo: ClientInfo,\r\n ): Promise<SocialGoogleResponse> {\r\n const response = await api.apps.post<SocialGoogleApiResponse>(\r\n \"/auth/social/google\",\r\n {\r\n code,\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n verification: true,\r\n },\r\n );\r\n\r\n if (response.status === 0) {\r\n if (response.code === \"link_requires_password\") {\r\n return {\r\n result: \"link_requires_password\",\r\n message:\r\n response.message ||\r\n \"Uma conta com esse e-mail já existe. Faça login com e-mail e senha para vincular sua conta Google.\",\r\n };\r\n }\r\n throw new ApiError(\r\n response.message || \"Falha no login com Google\",\r\n response.code || \"GOOGLE_LOGIN_FAILED\",\r\n 401,\r\n );\r\n }\r\n\r\n if (response.needs_onboarding) {\r\n if (!response.onboarding_token || !response.partial?.email) {\r\n throw new ApiError(\r\n \"Resposta de onboarding inválida\",\r\n \"INVALID_RESPONSE\",\r\n 500,\r\n );\r\n }\r\n return {\r\n result: \"needs_onboarding\",\r\n onboardingToken: response.onboarding_token,\r\n partial: response.partial,\r\n };\r\n }\r\n\r\n if (!response.cookie) {\r\n throw new ApiError(\r\n \"Resposta de autenticação inválida\",\r\n \"INVALID_RESPONSE\",\r\n 500,\r\n );\r\n }\r\n\r\n if (response.two_factor_required) {\r\n return {\r\n result: \"two_factor_required\",\r\n cookie: response.cookie,\r\n twoFactorMode: response.two_factor_required,\r\n };\r\n }\r\n\r\n await this.setAuthCookie(response.cookie);\r\n\r\n const [{ userService }, { accountService }] = await Promise.all([\r\n import(\"../../users/services/user.service\"),\r\n import(\"../../accounts/services/account.service\"),\r\n ]);\r\n const [user, account] = await Promise.all([\r\n userService.findById(),\r\n accountService.findCurrentAccount(),\r\n ]);\r\n\r\n return {\r\n result: \"success\",\r\n user,\r\n account,\r\n accessToken: response.cookie,\r\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\r\n };\r\n }\r\n\r\n async completeGoogleOnboarding(\r\n data: SocialOnboardingRequest,\r\n clientInfo: ClientInfo,\r\n ): Promise<SocialOnboardingResponse> {\r\n const today = new Date();\r\n const trialEndDate = new Date(today);\r\n const trialDays = Math.min(Math.max(data.trialDays ?? 7, 1), 90);\r\n trialEndDate.setDate(today.getDate() + trialDays);\r\n\r\n const idPlan = await this.resolvePlanId(data.idPlan);\r\n\r\n const payload = {\r\n onboarding_token: data.onboardingToken,\r\n name: data.user.name,\r\n bussiness_type: data.businessType ?? 0,\r\n language: \"pt-br\",\r\n timezone: \"America/Sao_Paulo\",\r\n currency: \"BRL\",\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n agent: clientInfo.agent,\r\n id_affiliate: data.affiliateId || 0,\r\n origin: data.origin,\r\n user: {\r\n id_api: \"\",\r\n name: data.user.name || \"\",\r\n last_name: data.user.last_name || \"\",\r\n rg: data.user.rg || \"\",\r\n cpf: data.user.cpf || \"\",\r\n gender: data.user.gender ?? 1,\r\n ddi: data.user.ddi || \"55\",\r\n phone: data.user.phone || \"\",\r\n profile: \"owner\",\r\n language: \"pt-br\",\r\n },\r\n subscription:\r\n idPlan === -1\r\n ? {\r\n type: \"free\",\r\n id_coupon: data.couponId || 0,\r\n id_plan: 5,\r\n id_product: 1,\r\n }\r\n : {\r\n type: \"trial\",\r\n id_coupon: data.couponId || 0,\r\n id_plan: idPlan,\r\n date_due: trialEndDate.toISOString().split(\"T\")[0],\r\n trial_days: trialDays,\r\n id_product: 1,\r\n },\r\n };\r\n\r\n const response = await api.apps.post<SocialOnboardingApiResponse>(\r\n \"/auth/social/onboarding\",\r\n payload,\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao finalizar cadastro com Google\",\r\n \"ONBOARDING_FAILED\",\r\n 400,\r\n );\r\n }\r\n\r\n if (!response.data?.length || !response.cookie) {\r\n throw new ApiError(\r\n \"Resposta de cadastro inválida\",\r\n \"INVALID_RESPONSE\",\r\n 500,\r\n );\r\n }\r\n\r\n await this.setAuthCookie(response.cookie);\r\n\r\n const [{ userService }, { accountService }] = await Promise.all([\r\n import(\"../../users/services/user.service\"),\r\n import(\"../../accounts/services/account.service\"),\r\n ]);\r\n const [user, account] = await Promise.all([\r\n userService.findById(),\r\n accountService.findCurrentAccount(),\r\n ]);\r\n\r\n return {\r\n user,\r\n account,\r\n accessToken: response.cookie,\r\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\r\n };\r\n }\r\n\r\n async unlinkGoogle(): Promise<UnlinkGoogleResponse> {\r\n const { id_account, id_user } = await import(\r\n \"../utils/get-user-context\"\r\n ).then((m) => m.getUserContext());\r\n\r\n const response = await api.apps.delete<UnlinkGoogleApiResponse>(\r\n `/accounts/${id_account}/users/${id_user}/social/google`,\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao desvincular conta Google\",\r\n \"UNLINK_FAILED\",\r\n 400,\r\n );\r\n }\r\n\r\n return {\r\n success: true,\r\n message: response.message,\r\n };\r\n }\r\n\r\n async register(\r\n data: RegisterRequest,\r\n clientInfo: ClientInfo,\r\n ): Promise<RegisterResponse> {\r\n const today = new Date();\r\n const trialEndDate = new Date(today);\r\n const trialDays = Math.min(Math.max(data.trialDays ?? 7, 1), 90);\r\n trialEndDate.setDate(today.getDate() + trialDays);\r\n\r\n const idPlan = await this.resolvePlanId(data.idPlan);\r\n\r\n const payload: RegisterApiRequest = {\r\n name: data.accountName,\r\n bussiness_type: data.businessType ?? 0,\r\n language: \"pt-br\",\r\n timezone: \"America/Sao_Paulo\",\r\n currency: \"BRL\",\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n agent: clientInfo.agent,\r\n id_affiliate: data.affiliateId || 0,\r\n origin: data.origin,\r\n user: {\r\n id_api: \"\",\r\n name: data.name,\r\n last_name: data.lastName || \"\",\r\n rg: data.rg || \"\",\r\n cpf: data.cpf || \"\",\r\n gender: data.gender,\r\n email: data.email,\r\n phone: data.phone,\r\n password: data.password,\r\n profile: \"owner\",\r\n language: \"pt-br\",\r\n },\r\n subscription:\r\n idPlan === -1\r\n ? {\r\n type: \"free\",\r\n id_coupon: data.couponId || 0,\r\n id_plan: 5, // Plano Free (ID fixo)\r\n id_product: 1,\r\n }\r\n : {\r\n type: \"trial\",\r\n id_coupon: data.couponId || 0,\r\n id_plan: idPlan,\r\n // Fluxo não-Stripe lê `date_due`; fluxo Stripe lê `trial_days`.\r\n // Mandamos os dois pra cobrir ambos os caminhos da API.\r\n date_due: trialEndDate.toISOString().split(\"T\")[0],\r\n trial_days: trialDays,\r\n id_product: 1,\r\n },\r\n };\r\n\r\n const response = await api.apps.post<RegisterApiResponse>(\r\n \"/accounts\",\r\n payload,\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao criar conta\",\r\n \"REGISTER_FAILED\",\r\n 400,\r\n );\r\n }\r\n\r\n if (!response.data || response.data.length === 0) {\r\n throw new ApiError(\r\n \"Resposta de registro inválida\",\r\n \"INVALID_RESPONSE\",\r\n 500,\r\n );\r\n }\r\n\r\n if (!response.cookie) {\r\n throw new ApiError(\r\n \"Resposta de autenticação inválida\",\r\n \"INVALID_RESPONSE\",\r\n 500,\r\n );\r\n }\r\n\r\n const accountData = response.data[0];\r\n\r\n await this.setAuthCookie(response.cookie);\r\n\r\n const [{ userService }, { accountService }] = await Promise.all([\r\n import(\"../../users/services/user.service\"),\r\n import(\"../../accounts/services/account.service\"),\r\n ]);\r\n const [user, account] = await Promise.all([\r\n userService.findById(),\r\n accountService.findCurrentAccount(),\r\n ]);\r\n\r\n return {\r\n user,\r\n account,\r\n accessToken: response.cookie,\r\n refreshToken: \"\",\r\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\r\n requiresEmailVerification: !accountData.verified,\r\n };\r\n }\r\n\r\n async logout(clientInfo: ClientInfo): Promise<LogoutResponse> {\r\n const cookie = await this.getToken();\r\n\r\n if (!cookie) {\r\n throw new ApiError(\r\n \"Usuário não autenticado\",\r\n \"NOT_AUTHENTICATED_LOGOUT\",\r\n 401\r\n );\r\n }\r\n\r\n const payload: LogoutRequest = {\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n cookie,\r\n };\r\n\r\n try {\r\n const response = await api.apps.post<LogoutApiResponse>(\r\n \"/auth/logout\",\r\n payload,\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao realizar logout\",\r\n response.code || \"LOGOUT_FAILED\",\r\n 400,\r\n );\r\n }\r\n } finally {\r\n await this.removeAuthCookie();\r\n }\r\n\r\n return {\r\n success: true,\r\n };\r\n }\r\n\r\n async forgotPassword(\r\n _data: ForgotPasswordRequest,\r\n ): Promise<ForgotPasswordResponse> {\r\n throw new ApiError(\r\n \"Recuperação de senha não implementada\",\r\n \"NOT_IMPLEMENTED\",\r\n 501,\r\n );\r\n }\r\n\r\n async resetPassword(\r\n _data: ResetPasswordRequest,\r\n ): Promise<ResetPasswordResponse> {\r\n throw new ApiError(\r\n \"Redefinição de senha não implementada\",\r\n \"NOT_IMPLEMENTED\",\r\n 501,\r\n );\r\n }\r\n\r\n async verifyEmail(_data: VerifyEmailRequest): Promise<VerifyEmailResponse> {\r\n throw new ApiError(\r\n \"Verificação de email não implementada\",\r\n \"NOT_IMPLEMENTED\",\r\n 501,\r\n );\r\n }\r\n\r\n async resendVerification(\r\n _data: ResendVerificationRequest,\r\n ): Promise<ResendVerificationResponse> {\r\n throw new ApiError(\r\n \"Reenvio de verificação não implementado\",\r\n \"NOT_IMPLEMENTED\",\r\n 501,\r\n );\r\n }\r\n\r\n async validateSession(clientInfo: ClientInfo): Promise<boolean> {\r\n const cookie = await this.getToken();\r\n\r\n if (!cookie) {\r\n return false;\r\n }\r\n\r\n try {\r\n const requestConfig = await buildWlOverrideFromJwt(cookie);\r\n\r\n const payload: SessionKeepRequest = {\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n cookie,\r\n };\r\n\r\n const response = await api.apps.post<SessionKeepResponse>(\r\n \"/auth/keep\",\r\n payload,\r\n requestConfig,\r\n );\r\n\r\n return response.status === 1;\r\n } catch (error) {\r\n console.error(\"[AuthService] validateSession error\", error);\r\n return false;\r\n }\r\n }\r\n\r\n async isAuthenticated(): Promise<boolean> {\r\n const token = await this.getToken();\r\n return !!token;\r\n }\r\n\r\n async getToken(): Promise<string | undefined> {\r\n if (process.env.DUMMY_AUTH_TOKEN) return process.env.DUMMY_AUTH_TOKEN;\r\n const cookieStore = await cookies();\r\n return cookieStore.get(AUTH_COOKIE_NAME)?.value;\r\n }\r\n\r\n private async resolvePlanId(idPlan?: number | string | null): Promise<number> {\r\n if (idPlan == null || idPlan === \"\") return -1;\r\n if (typeof idPlan === \"number\" || Number(idPlan)) return Number(idPlan);\r\n\r\n if (typeof idPlan === \"string\") {\r\n const response = await api.apps.get<SearchPlansApiResponse>(\r\n `/plans?search=${encodeURIComponent(idPlan)}`,\r\n );\r\n\r\n if (response.status === 1 && response.data?.length) {\r\n return response.data[0].id;\r\n }\r\n\r\n throw new ApiError(\r\n `Plano \"${idPlan}\" não encontrado`,\r\n \"PLAN_NOT_FOUND\",\r\n 404,\r\n );\r\n }\r\n return -1;\r\n }\r\n\r\n private async setAuthCookie(token: string): Promise<void> {\r\n const cookieStore = await cookies();\r\n const whitelabel = await findWhitelabel().catch(() => null);\r\n const cookieDomain =\r\n this.normalizeCookieDomain(whitelabel?.domain);\r\n\r\n cookieStore.set(AUTH_COOKIE_NAME, token, {\r\n ...COOKIE_OPTIONS,\r\n ...(cookieDomain ? { domain: cookieDomain } : {}),\r\n maxAge: COOKIE_MAX_AGE,\r\n });\r\n }\r\n\r\n async removeAuthCookie(): Promise<void> {\r\n const cookieStore = await cookies();\r\n const whitelabel = await findWhitelabel().catch(() => null);\r\n const cookieDomain =\r\n this.normalizeCookieDomain(whitelabel?.domain);\r\n\r\n cookieStore.delete({\r\n name: AUTH_COOKIE_NAME,\r\n ...COOKIE_OPTIONS,\r\n ...(cookieDomain ? { domain: cookieDomain } : {}),\r\n });\r\n }\r\n\r\n private normalizeCookieDomain(domain?: string | null): string | undefined {\r\n if (!domain) return undefined;\r\n\r\n const normalized = domain.trim();\r\n if (!normalized) return undefined;\r\n\r\n const rawHost = (() => {\r\n try {\r\n return new URL(normalized).hostname;\r\n } catch {\r\n return normalized\r\n .replace(/^https?:\\/\\//i, \"\")\r\n .replace(/^www\\./i, \"\")\r\n .split(\"/\")[0]\r\n .split(\":\")[0];\r\n }\r\n })();\r\n\r\n if (!rawHost || rawHost === \"localhost\") {\r\n return undefined;\r\n }\r\n\r\n return rawHost.startsWith(\".\") ? rawHost : `.${rawHost}`;\r\n }\r\n}\r\n\r\nexport const authService = new AuthService();\r\n\r\nexport type { ClientInfo, GeoLocation };\r\n"],"mappings":"AAAA,SAAS,eAAe;AAExB,SAAS,WAA+B;AACxC,SAAS,gBAAgB;AACzB,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AAqCvC,SAAS,sBAAsB;AAE/B,MAAM,mBAAmB;AACzB,MAAM,iBAAiB,KAAK,KAAK,KAAK;AAEtC,MAAM,iBAAiB;AAAA,EACrB,UAAU;AAAA,EACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,EACjC,UAAU;AAAA,EACV,MAAM;AACR;AAEA,MAAM,YAAY;AAAA,EAehB,MAAM,MACJ,aACA,YACA,SACgD;AAChD,QAAI;AACJ,QAAI,YAAY,OAAO;AACrB,YAAM,UAAU,MAAM,kBAAkB;AAAA,QACtC,YAAY;AAAA,MACd;AACA,sBAAgB,EAAE,cAAc,YAAY,OAAO,WAAW,QAAQ;AAAA,IACxE;AAEA,UAAM,WAAW,MAAM,IAAI,KAAK;AAAA,MAC9B;AAAA,MACA;AAAA,QACE,OAAO,YAAY;AAAA,QACnB,UAAU,YAAY;AAAA,QACtB,QAAQ,aAAa;AAAA,QACrB,UAAU,WAAW;AAAA,QACrB,IAAI,WAA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EA,WAAO,QAAQ,WAAW,GAAG,IAAI,UAAU,IAAI,OAAO;AAAA,EACxD;AACF;AAEO,MAAM,cAAc,IAAI,YAAY;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/auth/services/auth.service.ts"],"sourcesContent":["import { cookies } from \"next/headers\";\n\nimport { api, type RequestConfig } from \"../../../infra/api/client\";\nimport { ApiError } from \"../../../infra/api/types\";\nimport { whitelabelService } from \"../../whitelabel/services/whitelabel.service\";\nimport { buildWlOverrideFromJwt } from \"../utils/build-wl-override\";\nimport {\n ClientInfo,\n ForgotPasswordRequest,\n ForgotPasswordResponse,\n GeoLocation,\n LoginApiResponse,\n LoginRequest,\n LoginResponse,\n LogoutApiResponse,\n LogoutRequest,\n LogoutResponse,\n RegisterApiRequest,\n RegisterApiResponse,\n RegisterRequest,\n RegisterResponse,\n ResendVerificationRequest,\n ResendVerificationResponse,\n ResetPasswordRequest,\n ResetPasswordResponse,\n SearchPlansApiResponse,\n SessionKeepRequest,\n SessionKeepResponse,\n SocialGoogleApiResponse,\n SocialGoogleResponse,\n SocialOnboardingApiResponse,\n SocialOnboardingRequest,\n SocialOnboardingResponse,\n IsolatedLoginResponse,\n TwoFactorApiResponse,\n TwoFactorRequest,\n TwoFactorResponse,\n UnlinkGoogleApiResponse,\n UnlinkGoogleResponse,\n VerifyEmailRequest,\n VerifyEmailResponse,\n} from \"../schema\";\nimport { findWhitelabel } from \"../../../server\";\n\nconst AUTH_COOKIE_NAME = \"greatapps\";\nconst COOKIE_MAX_AGE = 60 * 60 * 24 * 30;\n\n/** Plano Free (ID fixo). */\nconst FREE_PLAN_ID = 5;\n\n/**\n * O cadastro pede o Free de duas formas, e as duas valem: ausência de plano (que o\n * `resolvePlanId` traduz para o sentinela -1) e o id do próprio Free.\n *\n * Olhar só o sentinela fazia `?id_plan=5` cair no ramo `trial` e criar um trial de 7 dias\n * do plano gratuito, com `date_due` e `trial_days` — estado que não existe no produto.\n */\nfunction isFreePlan(idPlan: number): boolean {\n return idPlan === -1 || idPlan === FREE_PLAN_ID;\n}\n\nconst COOKIE_OPTIONS = {\n httpOnly: true,\n secure: process.env.NODE_ENV === \"production\",\n sameSite: \"lax\" as const,\n path: \"/\",\n};\n\nclass AuthService {\n async login(\n credentials: LoginRequest,\n clientInfo: ClientInfo,\n ): Promise<LoginResponse>;\n async login(\n credentials: LoginRequest,\n clientInfo: ClientInfo,\n options: { setCookie: false },\n ): Promise<IsolatedLoginResponse>;\n async login(\n credentials: LoginRequest,\n clientInfo: ClientInfo,\n options?: { setCookie?: boolean },\n ): Promise<LoginResponse | IsolatedLoginResponse>;\n async login(\n credentials: LoginRequest,\n clientInfo: ClientInfo,\n options?: { setCookie?: boolean },\n ): Promise<LoginResponse | IsolatedLoginResponse> {\n let requestConfig: RequestConfig | undefined;\n if (credentials.id_wl) {\n const wlToken = await whitelabelService.getTokenByWhitelabelId(\n credentials.id_wl,\n );\n requestConfig = { whiteLabelId: credentials.id_wl, authToken: wlToken };\n }\n\n const response = await api.apps.post<LoginApiResponse>(\n \"/auth/login\",\n {\n email: credentials.email,\n password: credentials.password,\n source: credentials?.source,\n location: clientInfo.location,\n ip: clientInfo.ip,\n timezone: clientInfo.timezone,\n agent: clientInfo.agent,\n },\n requestConfig,\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"E-mail ou senha incorretos\",\n response.code || \"LOGIN_FAILED\",\n 401,\n );\n }\n\n if (!response.cookie) {\n throw new ApiError(\n \"Resposta de autenticação inválida\",\n \"INVALID_RESPONSE\",\n 500,\n );\n }\n\n if (response.two_factor_required) {\n return { result: \"two_factor_required\", cookie: response.cookie, twoFactorMode: response.two_factor_required };\n }\n\n // Modo isolado: caller só quer o token, sem afetar a sessão do navegador\n // nem pagar pelas chamadas de user/account (ex.: fluxo de SSO).\n if (options?.setCookie === false) {\n return { result: \"success\", accessToken: response.cookie };\n }\n\n await this.setAuthCookie(response.cookie);\n\n const [{ userService }, { accountService }] = await Promise.all([\n import(\"../../users/services/user.service\"),\n import(\"../../accounts/services/account.service\"),\n ]);\n const [user, account] = await Promise.all([\n userService.findById(\n requestConfig ? { authToken: requestConfig.authToken } : undefined,\n ),\n accountService.findCurrentAccount(requestConfig),\n ]);\n\n return {\n result: \"success\",\n user,\n account,\n accessToken: response.cookie,\n refreshToken: \"\",\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\n };\n }\n\n async verifyTwoFactor(\n cookie: string,\n code: string,\n clientInfo: ClientInfo,\n options?: { window?: number; setCookie?: boolean },\n ): Promise<TwoFactorResponse> {\n const payload: TwoFactorRequest = {\n location: clientInfo.location,\n ip: clientInfo.ip,\n timezone: clientInfo.timezone,\n agent: clientInfo.agent,\n cookie,\n code,\n };\n\n const endpoint = options?.window !== undefined ? `/auth/code?window=${options.window}` : '/auth/code';\n const response = await api.apps.post<TwoFactorApiResponse>(\n endpoint,\n payload,\n );\n\n if (response.status === 0) {\n throw new ApiError(\"Código 2FA inválido\", \"TWO_FACTOR_FAILED\", 401);\n }\n\n if (!response?.data?.cookie) {\n throw new ApiError(\n \"Resposta de autenticação inválida após 2FA\",\n \"INVALID_RESPONSE\",\n 500,\n );\n }\n\n // Modo isolado: devolve o token sem gravar o cookie — o caller redireciona\n // pra outro lugar (ex.: SSO callback) e não quer mexer na sessão atual.\n if (options?.setCookie === false) {\n return { status: 1, accessToken: response.data.cookie };\n }\n\n await this.setAuthCookie(response.data.cookie);\n\n return { status: 1 };\n }\n\n async socialLoginGoogle(\n code: string,\n clientInfo: ClientInfo,\n ): Promise<SocialGoogleResponse> {\n const response = await api.apps.post<SocialGoogleApiResponse>(\n \"/auth/social/google\",\n {\n code,\n location: clientInfo.location,\n ip: clientInfo.ip,\n timezone: clientInfo.timezone,\n agent: clientInfo.agent,\n verification: true,\n },\n );\n\n if (response.status === 0) {\n if (response.code === \"link_requires_password\") {\n return {\n result: \"link_requires_password\",\n message:\n response.message ||\n \"Uma conta com esse e-mail já existe. Faça login com e-mail e senha para vincular sua conta Google.\",\n };\n }\n throw new ApiError(\n response.message || \"Falha no login com Google\",\n response.code || \"GOOGLE_LOGIN_FAILED\",\n 401,\n );\n }\n\n if (response.needs_onboarding) {\n if (!response.onboarding_token || !response.partial?.email) {\n throw new ApiError(\n \"Resposta de onboarding inválida\",\n \"INVALID_RESPONSE\",\n 500,\n );\n }\n return {\n result: \"needs_onboarding\",\n onboardingToken: response.onboarding_token,\n partial: response.partial,\n };\n }\n\n if (!response.cookie) {\n throw new ApiError(\n \"Resposta de autenticação inválida\",\n \"INVALID_RESPONSE\",\n 500,\n );\n }\n\n if (response.two_factor_required) {\n return {\n result: \"two_factor_required\",\n cookie: response.cookie,\n twoFactorMode: response.two_factor_required,\n };\n }\n\n await this.setAuthCookie(response.cookie);\n\n const [{ userService }, { accountService }] = await Promise.all([\n import(\"../../users/services/user.service\"),\n import(\"../../accounts/services/account.service\"),\n ]);\n const [user, account] = await Promise.all([\n userService.findById(),\n accountService.findCurrentAccount(),\n ]);\n\n return {\n result: \"success\",\n user,\n account,\n accessToken: response.cookie,\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\n };\n }\n\n async completeGoogleOnboarding(\n data: SocialOnboardingRequest,\n clientInfo: ClientInfo,\n ): Promise<SocialOnboardingResponse> {\n const today = new Date();\n const trialEndDate = new Date(today);\n const trialDays = Math.min(Math.max(data.trialDays ?? 7, 1), 90);\n trialEndDate.setDate(today.getDate() + trialDays);\n\n const idPlan = await this.resolvePlanId(data.idPlan);\n\n const payload = {\n onboarding_token: data.onboardingToken,\n name: data.user.name,\n bussiness_type: data.businessType ?? 0,\n language: \"pt-br\",\n timezone: \"America/Sao_Paulo\",\n currency: \"BRL\",\n location: clientInfo.location,\n ip: clientInfo.ip,\n agent: clientInfo.agent,\n id_affiliate: data.affiliateId || 0,\n origin: data.origin,\n user: {\n id_api: \"\",\n name: data.user.name || \"\",\n last_name: data.user.last_name || \"\",\n rg: data.user.rg || \"\",\n cpf: data.user.cpf || \"\",\n gender: data.user.gender ?? 1,\n ddi: data.user.ddi || \"55\",\n phone: data.user.phone || \"\",\n profile: \"owner\",\n language: \"pt-br\",\n },\n subscription:\n isFreePlan(idPlan)\n ? {\n type: \"free\",\n id_coupon: data.couponId || 0,\n id_plan: FREE_PLAN_ID,\n id_product: 1,\n }\n : {\n type: \"trial\",\n id_coupon: data.couponId || 0,\n id_plan: idPlan,\n date_due: trialEndDate.toISOString().split(\"T\")[0],\n trial_days: trialDays,\n id_product: 1,\n },\n };\n\n const response = await api.apps.post<SocialOnboardingApiResponse>(\n \"/auth/social/onboarding\",\n payload,\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao finalizar cadastro com Google\",\n \"ONBOARDING_FAILED\",\n 400,\n );\n }\n\n if (!response.data?.length || !response.cookie) {\n throw new ApiError(\n \"Resposta de cadastro inválida\",\n \"INVALID_RESPONSE\",\n 500,\n );\n }\n\n await this.setAuthCookie(response.cookie);\n\n const [{ userService }, { accountService }] = await Promise.all([\n import(\"../../users/services/user.service\"),\n import(\"../../accounts/services/account.service\"),\n ]);\n const [user, account] = await Promise.all([\n userService.findById(),\n accountService.findCurrentAccount(),\n ]);\n\n return {\n user,\n account,\n accessToken: response.cookie,\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\n };\n }\n\n async unlinkGoogle(): Promise<UnlinkGoogleResponse> {\n const { id_account, id_user } = await import(\n \"../utils/get-user-context\"\n ).then((m) => m.getUserContext());\n\n const response = await api.apps.delete<UnlinkGoogleApiResponse>(\n `/accounts/${id_account}/users/${id_user}/social/google`,\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao desvincular conta Google\",\n \"UNLINK_FAILED\",\n 400,\n );\n }\n\n return {\n success: true,\n message: response.message,\n };\n }\n\n async register(\n data: RegisterRequest,\n clientInfo: ClientInfo,\n ): Promise<RegisterResponse> {\n const today = new Date();\n const trialEndDate = new Date(today);\n const trialDays = Math.min(Math.max(data.trialDays ?? 7, 1), 90);\n trialEndDate.setDate(today.getDate() + trialDays);\n\n const idPlan = await this.resolvePlanId(data.idPlan);\n\n const payload: RegisterApiRequest = {\n name: data.accountName,\n bussiness_type: data.businessType ?? 0,\n language: \"pt-br\",\n timezone: \"America/Sao_Paulo\",\n currency: \"BRL\",\n location: clientInfo.location,\n ip: clientInfo.ip,\n agent: clientInfo.agent,\n id_affiliate: data.affiliateId || 0,\n origin: data.origin,\n user: {\n id_api: \"\",\n name: data.name,\n last_name: data.lastName || \"\",\n rg: data.rg || \"\",\n cpf: data.cpf || \"\",\n gender: data.gender,\n email: data.email,\n phone: data.phone,\n password: data.password,\n profile: \"owner\",\n language: \"pt-br\",\n },\n subscription:\n isFreePlan(idPlan)\n ? {\n type: \"free\",\n id_coupon: data.couponId || 0,\n id_plan: FREE_PLAN_ID,\n id_product: 1,\n }\n : {\n type: \"trial\",\n id_coupon: data.couponId || 0,\n id_plan: idPlan,\n // Fluxo não-Stripe lê `date_due`; fluxo Stripe lê `trial_days`.\n // Mandamos os dois pra cobrir ambos os caminhos da API.\n date_due: trialEndDate.toISOString().split(\"T\")[0],\n trial_days: trialDays,\n id_product: 1,\n },\n };\n\n const response = await api.apps.post<RegisterApiResponse>(\n \"/accounts\",\n payload,\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao criar conta\",\n \"REGISTER_FAILED\",\n 400,\n );\n }\n\n if (!response.data || response.data.length === 0) {\n throw new ApiError(\n \"Resposta de registro inválida\",\n \"INVALID_RESPONSE\",\n 500,\n );\n }\n\n if (!response.cookie) {\n throw new ApiError(\n \"Resposta de autenticação inválida\",\n \"INVALID_RESPONSE\",\n 500,\n );\n }\n\n const accountData = response.data[0];\n\n await this.setAuthCookie(response.cookie);\n\n const [{ userService }, { accountService }] = await Promise.all([\n import(\"../../users/services/user.service\"),\n import(\"../../accounts/services/account.service\"),\n ]);\n const [user, account] = await Promise.all([\n userService.findById(),\n accountService.findCurrentAccount(),\n ]);\n\n return {\n user,\n account,\n accessToken: response.cookie,\n refreshToken: \"\",\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\n requiresEmailVerification: !accountData.verified,\n };\n }\n\n async logout(clientInfo: ClientInfo): Promise<LogoutResponse> {\n const cookie = await this.getToken();\n\n if (!cookie) {\n throw new ApiError(\n \"Usuário não autenticado\",\n \"NOT_AUTHENTICATED_LOGOUT\",\n 401\n );\n }\n\n const payload: LogoutRequest = {\n location: clientInfo.location,\n ip: clientInfo.ip,\n timezone: clientInfo.timezone,\n agent: clientInfo.agent,\n cookie,\n };\n\n try {\n const response = await api.apps.post<LogoutApiResponse>(\n \"/auth/logout\",\n payload,\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao realizar logout\",\n response.code || \"LOGOUT_FAILED\",\n 400,\n );\n }\n } finally {\n await this.removeAuthCookie();\n }\n\n return {\n success: true,\n };\n }\n\n async forgotPassword(\n _data: ForgotPasswordRequest,\n ): Promise<ForgotPasswordResponse> {\n throw new ApiError(\n \"Recuperação de senha não implementada\",\n \"NOT_IMPLEMENTED\",\n 501,\n );\n }\n\n async resetPassword(\n _data: ResetPasswordRequest,\n ): Promise<ResetPasswordResponse> {\n throw new ApiError(\n \"Redefinição de senha não implementada\",\n \"NOT_IMPLEMENTED\",\n 501,\n );\n }\n\n async verifyEmail(_data: VerifyEmailRequest): Promise<VerifyEmailResponse> {\n throw new ApiError(\n \"Verificação de email não implementada\",\n \"NOT_IMPLEMENTED\",\n 501,\n );\n }\n\n async resendVerification(\n _data: ResendVerificationRequest,\n ): Promise<ResendVerificationResponse> {\n throw new ApiError(\n \"Reenvio de verificação não implementado\",\n \"NOT_IMPLEMENTED\",\n 501,\n );\n }\n\n async validateSession(clientInfo: ClientInfo): Promise<boolean> {\n const cookie = await this.getToken();\n\n if (!cookie) {\n return false;\n }\n\n try {\n const requestConfig = await buildWlOverrideFromJwt(cookie);\n\n const payload: SessionKeepRequest = {\n location: clientInfo.location,\n ip: clientInfo.ip,\n timezone: clientInfo.timezone,\n agent: clientInfo.agent,\n cookie,\n };\n\n const response = await api.apps.post<SessionKeepResponse>(\n \"/auth/keep\",\n payload,\n requestConfig,\n );\n\n return response.status === 1;\n } catch (error) {\n console.error(\"[AuthService] validateSession error\", error);\n return false;\n }\n }\n\n async isAuthenticated(): Promise<boolean> {\n const token = await this.getToken();\n return !!token;\n }\n\n async getToken(): Promise<string | undefined> {\n if (process.env.DUMMY_AUTH_TOKEN) return process.env.DUMMY_AUTH_TOKEN;\n const cookieStore = await cookies();\n return cookieStore.get(AUTH_COOKIE_NAME)?.value;\n }\n\n private async resolvePlanId(idPlan?: number | string | null): Promise<number> {\n if (idPlan == null || idPlan === \"\") return -1;\n if (typeof idPlan === \"number\" || Number(idPlan)) return Number(idPlan);\n\n if (typeof idPlan === \"string\") {\n const response = await api.apps.get<SearchPlansApiResponse>(\n `/plans?search=${encodeURIComponent(idPlan)}`,\n );\n\n if (response.status === 1 && response.data?.length) {\n return response.data[0].id;\n }\n\n throw new ApiError(\n `Plano \"${idPlan}\" não encontrado`,\n \"PLAN_NOT_FOUND\",\n 404,\n );\n }\n return -1;\n }\n\n private async setAuthCookie(token: string): Promise<void> {\n const cookieStore = await cookies();\n const whitelabel = await findWhitelabel().catch(() => null);\n const cookieDomain =\n this.normalizeCookieDomain(whitelabel?.domain);\n\n cookieStore.set(AUTH_COOKIE_NAME, token, {\n ...COOKIE_OPTIONS,\n ...(cookieDomain ? { domain: cookieDomain } : {}),\n maxAge: COOKIE_MAX_AGE,\n });\n }\n\n async removeAuthCookie(): Promise<void> {\n const cookieStore = await cookies();\n const whitelabel = await findWhitelabel().catch(() => null);\n const cookieDomain =\n this.normalizeCookieDomain(whitelabel?.domain);\n\n cookieStore.delete({\n name: AUTH_COOKIE_NAME,\n ...COOKIE_OPTIONS,\n ...(cookieDomain ? { domain: cookieDomain } : {}),\n });\n }\n\n private normalizeCookieDomain(domain?: string | null): string | undefined {\n if (!domain) return undefined;\n\n const normalized = domain.trim();\n if (!normalized) return undefined;\n\n const rawHost = (() => {\n try {\n return new URL(normalized).hostname;\n } catch {\n return normalized\n .replace(/^https?:\\/\\//i, \"\")\n .replace(/^www\\./i, \"\")\n .split(\"/\")[0]\n .split(\":\")[0];\n }\n })();\n\n if (!rawHost || rawHost === \"localhost\") {\n return undefined;\n }\n\n return rawHost.startsWith(\".\") ? rawHost : `.${rawHost}`;\n }\n}\n\nexport const authService = new AuthService();\n\nexport type { ClientInfo, GeoLocation };\n"],"mappings":"AAAA,SAAS,eAAe;AAExB,SAAS,WAA+B;AACxC,SAAS,gBAAgB;AACzB,SAAS,yBAAyB;AAClC,SAAS,8BAA8B;AAqCvC,SAAS,sBAAsB;AAE/B,MAAM,mBAAmB;AACzB,MAAM,iBAAiB,KAAK,KAAK,KAAK;AAGtC,MAAM,eAAe;AASrB,SAAS,WAAW,QAAyB;AAC3C,SAAO,WAAW,MAAM,WAAW;AACrC;AAEA,MAAM,iBAAiB;AAAA,EACrB,UAAU;AAAA,EACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,EACjC,UAAU;AAAA,EACV,MAAM;AACR;AAEA,MAAM,YAAY;AAAA,EAehB,MAAM,MACJ,aACA,YACA,SACgD;AAChD,QAAI;AACJ,QAAI,YAAY,OAAO;AACrB,YAAM,UAAU,MAAM,kBAAkB;AAAA,QACtC,YAAY;AAAA,MACd;AACA,sBAAgB,EAAE,cAAc,YAAY,OAAO,WAAW,QAAQ;AAAA,IACxE;AAEA,UAAM,WAAW,MAAM,IAAI,KAAK;AAAA,MAC9B;AAAA,MACA;AAAA,QACE,OAAO,YAAY;AAAA,QACnB,UAAU,YAAY;AAAA,QACtB,QAAQ,aAAa;AAAA,QACrB,UAAU,WAAW;AAAA,QACrB,IAAI,WAAW;AAAA,QACf,UAAU,WAAW;AAAA,QACrB,OAAO,WAAW;AAAA,MACpB;AAAA,MACA;AAAA,IACF;AAEA,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,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-8,6 +8,7 @@ import { useAuth } from '../../../providers/auth.provider';
|
|
|
8
8
|
import { AccountSectionType } from '../../../enums/AccountSectionType';
|
|
9
9
|
import { useUnlinkGoogle } from '../../../modules/auth/hooks/unlink-google.hook';
|
|
10
10
|
import { USER_QUERY_KEY } from '../../../modules/auth/hooks/useUserQuery';
|
|
11
|
+
import { Button } from '../../ui/buttons/Button';
|
|
11
12
|
import { Toast } from '../../ui/feedback/Toast';
|
|
12
13
|
import { GoogleIcon } from '../../ui/data-display/GoogleIcon';
|
|
13
14
|
|
|
@@ -61,16 +62,17 @@ export function SecuritySection({
|
|
|
61
62
|
</span>
|
|
62
63
|
</div>
|
|
63
64
|
|
|
64
|
-
<
|
|
65
|
+
<Button
|
|
66
|
+
variant="secondary"
|
|
67
|
+
className="h-10! w-fit"
|
|
65
68
|
type="button"
|
|
66
69
|
disabled={isUnlinking}
|
|
67
|
-
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"
|
|
68
70
|
onClick={handleUnlinkGoogle}
|
|
69
71
|
>
|
|
70
72
|
{isUnlinking
|
|
71
73
|
? translate('common.account.security.unlinking')
|
|
72
74
|
: translate('common.account.security.unlinkGoogle')}
|
|
73
|
-
</
|
|
75
|
+
</Button>
|
|
74
76
|
</div>
|
|
75
77
|
)}
|
|
76
78
|
|