i’m practicing reactjs watching this video https://www.youtube.com/watch?v=5rh853GTgKo&list=PLJRGQoqpRwdfoa9591BcUS6NmMpZcvFsM&index=9
I want to verify my information using uid and token, but I don’t know how to deliver it.
In this code: Activate.js in container
JavaScript
x
21
21
1
import React, { useState } from 'react';
2
import { Redirect } from 'react-router-dom';
3
import { connect } from 'react-redux';
4
import { verify } from '../actions/auth';
5
6
const Activate = ({ verify, match }) => {
7
const [verified, setVerified] = useState(false);
8
9
const verify_account = e => {
10
const uid = match.params.uid; // I Think This part is Problem
11
const token = match.params.token;
12
13
verify(uid, token);
14
setVerified(true);
15
};
16
17
18
if (verified) {
19
return <Redirect to='/' />
20
}
21
and this code : auth.js in actions
JavaScript
1
22
22
1
export const verify = (uid, token) => async dispatch => {
2
const config = {
3
headers: {
4
'Content-Type': 'application/json'
5
}
6
};
7
8
const body = JSON.stringify({ uid, token });
9
10
try {
11
await axios.post(`${process.env.REACT_APP_API_URL}/auth/users/activation/`, body, config);
12
13
dispatch ({
14
type: ACTIVATION_SUCCESS,
15
});
16
} catch (err) {
17
dispatch ({
18
type: ACTIVATION_FAIL
19
});
20
}
21
}
22
i think i didn’t render uid, token but i confused how to do that
App.js code:
JavaScript
1
10
10
1
<Router>
2
<Layout>
3
<Switch>
4
<Route exact path ='/activate/:uid/:token'>
5
<Activate />
6
</Route>
7
</Switch>
8
</Layout>
9
</Router>
10
I’d appreciate any help. 🙂
Advertisement
Answer
use the useParams hook to extract uid
and token
params:
JavaScript
1
19
19
1
import React, { useState } from 'react';
2
import { Redirect, useParams } from 'react-router-dom';
3
import { connect } from 'react-redux';
4
import { verify } from '../actions/auth';
5
6
const Activate = ({ verify }) => {
7
const [verified, setVerified] = useState(false);
8
const { uid, token } = useParams();
9
10
const verify_account = e => {
11
verify(uid, token);
12
setVerified(true);
13
};
14
15
16
if (verified) {
17
return <Redirect to='/' />
18
}
19