Skip to content

Commit

Permalink
fix: request twice when verify
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Sep 14, 2022
1 parent a51a911 commit fb93a6d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions GZCTF/ClientApp/src/pages/account/Confirm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useEffect } from 'react'
import { FC, useEffect, useRef } from 'react'
import { useNavigate, useLocation } from 'react-router-dom'
import { Text } from '@mantine/core'
import { showNotification } from '@mantine/notifications'
Expand All @@ -14,15 +14,16 @@ const Confirm: FC = () => {
const sp = new URLSearchParams(location.search)
const token = sp.get('token')
const email = sp.get('email')
const runOnce = useRef(false);

usePageTitle('邮箱验证')

useEffect(() => {
if (token && email) {
if (token && email && !runOnce.current) {
runOnce.current = true
api.account
.accountMailChangeConfirm({ token, email })
.then(() => {
navigate('/')
showNotification({
color: 'teal',
title: '邮箱已验证',
Expand All @@ -40,8 +41,11 @@ const Confirm: FC = () => {
disallowClose: true,
})
})
.finally(() => {
navigate('/')
})
}
})
}, [])

return (
<AccountView>
Expand Down
1 change: 1 addition & 0 deletions GZCTF/ClientApp/src/pages/account/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const Register: FC = () => {
title: '遇到了问题',
message: `${err.response.data.title}`,
icon: <Icon path={mdiClose} size={1} />,
disallowClose: true,
})
})
.finally(() => {
Expand Down
11 changes: 7 additions & 4 deletions GZCTF/ClientApp/src/pages/account/Verify.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useEffect } from 'react'
import { FC, useEffect, useRef } from 'react'
import { useNavigate, useLocation } from 'react-router-dom'
import { Text } from '@mantine/core'
import { showNotification } from '@mantine/notifications'
Expand All @@ -14,15 +14,16 @@ const Verify: FC = () => {
const token = sp.get('token')
const email = sp.get('email')
const navigate = useNavigate()
const runOnce = useRef(false);

usePageTitle('账户验证')

useEffect(() => {
if (token && email) {
if (token && email && !runOnce.current ) {
runOnce.current = true
api.account
.accountVerify({ token, email })
.then(() => {
navigate('/account/login')
showNotification({
color: 'teal',
title: '账户已验证,请登录',
Expand All @@ -39,9 +40,11 @@ const Verify: FC = () => {
icon: <Icon path={mdiClose} size={1} />,
disallowClose: true,
})
}).finally(() => {
navigate('/account/login')
})
}
})
}, [])

return (
<AccountView>
Expand Down

0 comments on commit fb93a6d

Please sign in to comment.