diff --git a/src/common/utils/oauth.ts b/src/common/utils/oauth.ts index c7c74eea57..71cf8fd1bb 100644 --- a/src/common/utils/oauth.ts +++ b/src/common/utils/oauth.ts @@ -4,6 +4,7 @@ import { CALLBACK_PROVIDERS, OAUTH_SCOPE_TREE, OAUTH_TYPE, + PATHS, } from '~/common/enums' export const toReadableScope = ({ @@ -85,14 +86,23 @@ export const facebookOauthUrl = async (type: OauthType) => { return url } -export const signupCallabckUrl = (email: string) => { +export const signupCallbackUrl = (email: string) => { return `https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}/callback/${ CALLBACK_PROVIDERS.EmailSignup }?email=${encodeURIComponent(email)}` } -export const signinCallabckUrl = (email: string) => { +export const signinCallbackUrl = (email: string) => { return `https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}/callback/${ CALLBACK_PROVIDERS.EmailSignin }?email=${encodeURIComponent(email)}` } + +export const emailVerifyCallbackUrl = (email: string) => { + const redirectPath = `/callback/${CALLBACK_PROVIDERS.EmailVerification}` + const host = `https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}` + const redirectUrl = `${host}${redirectPath}?email=${encodeURIComponent( + email + )}&target=${encodeURIComponent(host)}${encodeURIComponent(PATHS.ME_SETTINGS)}` + return redirectUrl +} diff --git a/src/components/Dialogs/SetEmailDialog/Content.tsx b/src/components/Dialogs/SetEmailDialog/Content.tsx index a9dc8732bd..1247385671 100644 --- a/src/components/Dialogs/SetEmailDialog/Content.tsx +++ b/src/components/Dialogs/SetEmailDialog/Content.tsx @@ -5,13 +5,15 @@ import React, { useContext } from 'react' import { FormattedMessage, useIntl } from 'react-intl' import { - CALLBACK_PROVIDERS, KEYVALUE, MAX_CHANGE_EMAIL_TIME_DAILY, - PATHS, TOAST_SEND_EMAIL_VERIFICATION, } from '~/common/enums' -import { parseFormSubmitErrors, validateEmail } from '~/common/utils' +import { + emailVerifyCallbackUrl, + parseFormSubmitErrors, + validateEmail, +} from '~/common/utils' import { Dialog, Form, @@ -96,13 +98,7 @@ const SetEmailDialogContent: React.FC = ({ closeDialog }) => { try { await set({ variables: { input: { email } } }) - const redirectPath = `/callback/${CALLBACK_PROVIDERS.EmailVerification}` - const host = `https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}` - const redirectUrl = `${host}${redirectPath}?email=${encodeURIComponent( - email - )}&target=${encodeURIComponent(host)}${encodeURIComponent( - PATHS.ME_SETTINGS - )}` + const redirectUrl = emailVerifyCallbackUrl(email) await sendCode({ variables: { diff --git a/src/components/Forms/EmailLoginForm/index.tsx b/src/components/Forms/EmailLoginForm/index.tsx index df9ba7d26a..4340186000 100644 --- a/src/components/Forms/EmailLoginForm/index.tsx +++ b/src/components/Forms/EmailLoginForm/index.tsx @@ -15,7 +15,7 @@ import { parseFormSubmitErrors, redirectToTarget, setCookies, - signinCallabckUrl, + signinCallbackUrl, validateEmail, // validatePassword, } from '~/common/utils' @@ -196,7 +196,7 @@ export const EmailLoginForm: React.FC = ({ return } - const redirectUrl = signinCallabckUrl(values.email) + const redirectUrl = signinCallbackUrl(values.email) await sendCode({ variables: { diff --git a/src/components/Forms/EmailSignUpForm/Init.tsx b/src/components/Forms/EmailSignUpForm/Init.tsx index 8ce1d74049..18f25f0155 100644 --- a/src/components/Forms/EmailSignUpForm/Init.tsx +++ b/src/components/Forms/EmailSignUpForm/Init.tsx @@ -5,7 +5,7 @@ import { FormattedMessage, useIntl } from 'react-intl' import { parseFormSubmitErrors, - signupCallabckUrl, + signupCallbackUrl, validateEmail, } from '~/common/utils' import { WalletType } from '~/common/utils' @@ -88,7 +88,7 @@ const Init: React.FC = ({ }), onSubmit: async ({ email }, { setFieldError, setSubmitting }) => { try { - const redirectUrl = signupCallabckUrl(email) + const redirectUrl = signupCallbackUrl(email) await sendCode({ variables: { input: { email, type: 'register', token, redirectUrl }, diff --git a/src/components/GlobalToasts/EmailVerificationToast/ResendAction.tsx b/src/components/GlobalToasts/EmailVerificationToast/ResendAction.tsx index 46051806c2..c17dd83c52 100644 --- a/src/components/GlobalToasts/EmailVerificationToast/ResendAction.tsx +++ b/src/components/GlobalToasts/EmailVerificationToast/ResendAction.tsx @@ -2,11 +2,10 @@ import { useContext, useEffect } from 'react' import { FormattedMessage } from 'react-intl' import { - CALLBACK_PROVIDERS, OAUTH_STORAGE_SEND_EMAIL_CODE_COUNTDOWN, SEND_CODE_COUNTDOWN, } from '~/common/enums' -import { storage } from '~/common/utils' +import { emailVerifyCallbackUrl, storage } from '~/common/utils' import { useCountdown, useMutation, ViewerContext } from '~/components' import SEND_CODE from '~/components/GQL/mutations/sendCode' import { @@ -50,11 +49,7 @@ const ResendAction = ({ initCountdown }: Props) => { const resend = async () => { const email = viewer.info.email - const redirectPath = `/callback/${CALLBACK_PROVIDERS.EmailVerification}` - const redirectUrl = `${ - process.env.NEXT_PUBLIC_SITE_DOMAIN - }${redirectPath}?email=${encodeURIComponent(email)}` - + const redirectUrl = emailVerifyCallbackUrl(email) await sendCode({ variables: { input: {