Skip to content

Commit

Permalink
Merge pull request #3832 from thematters/fix/email-verify-url
Browse files Browse the repository at this point in the history
Fix/email verify url
  • Loading branch information
wlliaml authored Sep 21, 2023
2 parents 1576e9d + fbdbc8a commit a20b45b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
14 changes: 12 additions & 2 deletions src/common/utils/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CALLBACK_PROVIDERS,
OAUTH_SCOPE_TREE,
OAUTH_TYPE,
PATHS,
} from '~/common/enums'

export const toReadableScope = ({
Expand Down Expand Up @@ -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
}
16 changes: 6 additions & 10 deletions src/components/Dialogs/SetEmailDialog/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -96,13 +98,7 @@ const SetEmailDialogContent: React.FC<FormProps> = ({ 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: {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Forms/EmailLoginForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
parseFormSubmitErrors,
redirectToTarget,
setCookies,
signinCallabckUrl,
signinCallbackUrl,
validateEmail,
// validatePassword,
} from '~/common/utils'
Expand Down Expand Up @@ -196,7 +196,7 @@ export const EmailLoginForm: React.FC<FormProps> = ({
return
}

const redirectUrl = signinCallabckUrl(values.email)
const redirectUrl = signinCallbackUrl(values.email)

await sendCode({
variables: {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Forms/EmailSignUpForm/Init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FormattedMessage, useIntl } from 'react-intl'

import {
parseFormSubmitErrors,
signupCallabckUrl,
signupCallbackUrl,
validateEmail,
} from '~/common/utils'
import { WalletType } from '~/common/utils'
Expand Down Expand Up @@ -88,7 +88,7 @@ const Init: React.FC<FormProps> = ({
}),
onSubmit: async ({ email }, { setFieldError, setSubmitting }) => {
try {
const redirectUrl = signupCallabckUrl(email)
const redirectUrl = signupCallbackUrl(email)
await sendCode({
variables: {
input: { email, type: 'register', token, redirectUrl },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {
Expand Down

1 comment on commit a20b45b

@vercel
Copy link

@vercel vercel bot commented on a20b45b Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.