I am trying to setup verify account with react and have the following in my App.js file
App.js
import SigninPage from './pages/signin';
import ResetPasswordPage from './pages/resetPassword'
import VerifyAccountPage from './pages/verifyAccount'
...
...
import { useHistory } from 'react-router';
import { logout } from './utils/auth';
function App() {
const history = useHistory();
return (
<Router>
<Switch>
<Route path='/' component={Home} exact />
<Route
path="/signout"
render={() => {
logout();
history.push('/');
return null;
}}
/>
<Route path='/signin' component={SigninPage} exact />
<Route path='/reset-password?reset-password-token=:resetPasswordToken' component={ResetPasswordPage} />
<Route path='/verify-account?token=:token&email=:email' component={VerifyAccountPage} exact />
</Switch>
</Router>
);
}
export default App;
and in my VerifyAccountPage component have the following
import { Redirect } from 'react-router-dom';
import { useHistory } from 'react-router';
import { verifyAccount, isAuthenticated } from '../../utils/auth';
const VerifyAccount = () => {
const { token, email } = this.props.match.params
const history = useHistory();
const [error, setError] = useState('');
const handleGet = async (e) => {
e.preventDefault();
setError('');
try {
const data = await verifyAccount(token, email);
if (data) {
history.push('/');
}
console.log(data);
} catch (err) {
if (err instanceof Error) {
// handle errors thrown from frontend
setError(err.message);
} else {
// handle errors thrown from backend
setError(err);
}
}
};
return isAuthenticated() ? (
<Redirect to="/#" />
) : (
<>
<Container>
<FormWrap>
<Icon to='/'>mywebsite</Icon>
<FormContent>
<Form action='#'>
<FormH1>Verify Account</FormH1>
<Text>Account has been verified!</Text>
</Form>
</FormContent>
</FormWrap>
</Container>
</>
);
};
export default VerifyAccount;
and here is verifyAccount.js page
import React from 'react';
import VerifyAccount from '../components/VerifyAccount';
import ScrollToTop from '../components/ScrollToTop';
function VerifyAccountPage() {
return (
<>
<ScrollToTop />
<VerifyAccount />
</>
);
}
export default VerifyAccountPage;
here is
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
but this is not working and when I go to the link https://mywebsite.com/verify-account?token=3heubek&email=user1@email.com nothing happens other than a 200 or 304 status code
no request is sent to the API so means that the params are not getting pulled out
can anyone point me to what is going on?
package versions used from package.json file
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-icons": "^3.11.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3",
"react-scroll": "^1.8.1",
"styled-components": "^5.2.0",
"@types/node": "^15.6.0",
"jwt-decode": "^3.0.0"