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,CAACA,EAAKC,MAAM,CAAC3C,QAAQ,EAGrB,CAACpB,EAAegE,SAAS,CAACF,EAAKC,MAAM,CAAC3C,QAAQ,EAAEwB,OAAO,CAFzD,MAAOqB,CAAAA,EAAAA,EAAAA,EAAAA,EAAS,QAMlB,GAAIH,yBAAAA,EAAKC,MAAM,CAAC3C,QAAQ,CAA6B,CAEnD,IAAME,EAAe4C,IADLC,IAAIL,EAAKM,OAAO,CAACF,GAAG,EACX5C,YAAY,CAC/Be,EAAQf,EAAagB,GAAG,CAAC,UAAY,GACrCH,EAAQkC,mBAAmB/C,EAAagB,GAAG,CAAC,UAAY,IACxDF,EAAM,MAAMkC,CAAAA,EAAAA,EAAAA,EAAAA,EAAQ,CACxBC,MAAOC,EAAAA,EAAmBA,CAC1BC,UAAW,CACTpC,MAAOA,EACPF,MAAOA,CACT,CACF,GAAGK,KAAK,CAACC,QAAQC,KAAK,EAEtB,GAAI,CAACN,GAAKsC,YACR,MAAOT,CAAAA,EAAAA,EAAAA,EAAAA,EAAS,WAEpB,MAAO,GAAIH,iBAAAA,EAAKC,MAAM,CAAC3C,QAAQ,CAAqB,CAGlD,IAAMiB,EAAQf,IAFE6C,IAAIL,EAAKM,OAAO,CAACF,GAAG,EACX5C,YAAY,CACVgB,GAAG,CAAC,UAAY,GACrCF,EAAM,MAAMkC,CAAAA,EAAAA,EAAAA,EAAAA,EAAQ,CACxBC,MAAOI,EAAAA,EAAmBA,CAC1BF,UAAW,CACTpC,MAAOA,CACT,CACF,GAAGG,KAAK,CAACC,QAAQC,KAAK,EAEtB,GAAI,CAACN,GAAKwC,YACR,MAAOX,CAAAA,EAAAA,EAAAA,EAAAA,EAAS,WAEpB,CACA,OAAO,IACT,C","sources":["webpack://@affine/web/../core/src/pages/auth.tsx"],"sourcesContent":["import { notify } from '@affine/component';\nimport {\n ChangeEmailPage,\n ChangePasswordPage,\n ConfirmChangeEmail,\n OnboardingPage,\n SetPasswordPage,\n SignInSuccessPage,\n SignUpPage,\n} from '@affine/component/auth-components';\nimport {\n changeEmailMutation,\n changePasswordMutation,\n fetcher,\n sendVerifyChangeEmailMutation,\n verifyEmailMutation,\n} from '@affine/graphql';\nimport { useI18n } from '@affine/i18n';\nimport { useLiveData, useService } from '@toeverything/infra';\nimport { useCallback } from 'react';\nimport type { LoaderFunction } from 'react-router-dom';\nimport { redirect, useParams, useSearchParams } from 'react-router-dom';\nimport { z } from 'zod';\n\nimport { useMutation } from '../hooks/use-mutation';\nimport { RouteLogic, useNavigateHelper } from '../hooks/use-navigate-helper';\nimport { AuthService, ServerConfigService } from '../modules/cloud';\n\nconst authTypeSchema = z.enum([\n 'onboarding',\n 'setPassword',\n 'signIn',\n 'changePassword',\n 'signUp',\n 'changeEmail',\n 'confirm-change-email',\n 'subscription-redirect',\n 'verify-email',\n]);\n\nexport const Component = () => {\n const authService = useService(AuthService);\n const account = useLiveData(authService.session.account$);\n const t = useI18n();\n const serverConfig = useService(ServerConfigService).serverConfig;\n const passwordLimits = useLiveData(\n serverConfig.credentialsRequirement$.map(r => r?.password)\n );\n\n const { authType } = useParams();\n const [searchParams] = useSearchParams();\n\n const { trigger: changePassword } = useMutation({\n mutation: changePasswordMutation,\n });\n\n const { trigger: sendVerifyChangeEmail } = useMutation({\n mutation: sendVerifyChangeEmailMutation,\n });\n\n const { jumpToIndex } = useNavigateHelper();\n\n const onSendVerifyChangeEmail = useCallback(\n async (email: string) => {\n const res = await sendVerifyChangeEmail({\n token: searchParams.get('token') || '',\n email,\n callbackUrl: `/auth/confirm-change-email`,\n }).catch(console.error);\n\n // FIXME: There is not notification\n if (res?.sendVerifyChangeEmail) {\n notify.success({\n title: t['com.arms.auth.sent.verify.email.hint'](),\n });\n } else {\n notify.error({\n title: t['com.arms.auth.sent.change.email.fail'](),\n });\n }\n\n return !!res?.sendVerifyChangeEmail;\n },\n [searchParams, sendVerifyChangeEmail, t]\n );\n\n const onSetPassword = useCallback(\n async (password: string) => {\n await changePassword({\n token: searchParams.get('token') || '',\n userId: searchParams.get('userId') || '',\n newPassword: password,\n });\n },\n [changePassword, searchParams]\n );\n const onOpenAffine = useCallback(() => {\n jumpToIndex(RouteLogic.REPLACE);\n }, [jumpToIndex]);\n\n if (!passwordLimits) {\n // TODO(@eyhn): loading UI\n return null;\n }\n\n switch (authType) {\n case 'onboarding':\n return (\n account && \n );\n case 'signUp': {\n return (\n account && (\n \n )\n );\n }\n case 'signIn': {\n return ;\n }\n case 'changePassword': {\n return (\n \n );\n }\n case 'setPassword': {\n return (\n \n );\n }\n case 'changeEmail': {\n return (\n \n );\n }\n case 'confirm-change-email': {\n return ;\n }\n case 'verify-email': {\n return ;\n }\n }\n return null;\n};\n\nexport const loader: LoaderFunction = async args => {\n if (!args.params.authType) {\n return redirect('/404');\n }\n if (!authTypeSchema.safeParse(args.params.authType).success) {\n return redirect('/404');\n }\n\n if (args.params.authType === 'confirm-change-email') {\n const url = new URL(args.request.url);\n const searchParams = url.searchParams;\n const token = searchParams.get('token') ?? '';\n const email = decodeURIComponent(searchParams.get('email') ?? '');\n const res = await fetcher({\n query: changeEmailMutation,\n variables: {\n token: token,\n email: email,\n },\n }).catch(console.error);\n // TODO(@eyhn): Add error handling\n if (!res?.changeEmail) {\n return redirect('/expired');\n }\n } else if (args.params.authType === 'verify-email') {\n const url = new URL(args.request.url);\n const searchParams = url.searchParams;\n const token = searchParams.get('token') ?? '';\n const res = await fetcher({\n query: verifyEmailMutation,\n variables: {\n token: token,\n },\n }).catch(console.error);\n\n if (!res?.verifyEmail) {\n return redirect('/expired');\n }\n }\n return null;\n};\n"],"names":["authTypeSchema","z","enum","Component","authService","useService","AuthService","account","useLiveData","session","account$","t","useI18n","serverConfig","ServerConfigService","passwordLimits","credentialsRequirement$","map","r","password","authType","useParams","searchParams","useSearchParams","trigger","changePassword","useMutation","mutation","changePasswordMutation","sendVerifyChangeEmail","sendVerifyChangeEmailMutation","jumpToIndex","useNavigateHelper","onSendVerifyChangeEmail","useCallback","email","res","token","get","callbackUrl","catch","console","error","notify","success","title","onSetPassword","userId","newPassword","onOpenAffine","RouteLogic","REPLACE","OnboardingPage","user","SignUpPage","SignInSuccessPage","ChangePasswordPage","SetPasswordPage","ChangeEmailPage","onChangeEmail","ConfirmChangeEmail","loader","args","params","safeParse","redirect","url","URL","request","decodeURIComponent","fetcher","query","changeEmailMutation","variables","changeEmail","verifyEmailMutation","verifyEmail"],"sourceRoot":""}