How to do account activation through email using Djoser and React Native?

1k Views Asked by At

I am currently doing the authentication for my React Native based application using Djoser in the backend. However, for account activation Djoser sends a link containing the uid and a token. I want this link to open a page on my app while I obtain the uid and token from the link. I need to send the uid and token in the link as the body in my activation request from my react native app.Please suggest how that can be done. Any help would be appreciable because I'm stuck on this particular part.

2

There are 2 best solutions below

1
On

I integrated djoser and reactjs. so it's nearly similar like react native.It is may be usefull.

IN your django settings.py:

DJOSER = {
       ....

    'ACTIVATION_URL': 'user_activation/{uid}/{token}',
    'SEND_ACTIVATION_EMAIL': True,
    'SEND_CONFIRMATION_EMAIL':True,
      .....
}

Urls.js

....
<Route path="/user_activation/:uid/:token" component={ActivateAccount} />
....

ActivateAccount.js:

const ActivateAccount = () => {

const { uid, token } = useParams();

const history = useHistory();

const activeClick = (e) => {
   
    Axios.post('http://localhost:8000/auth/users/activation/', { uid: uid, token: token })
        .then(() => {
            history.push('/login')
        })
        .catch(err => {
            alert(err.response.data);
        })
};

return (
    <Fragment>
        <Button onClick={activeClick} color="primary">Activate Now</Button>
    </Fragment>
)
}

export default ActivateAccount;
0
On

I'm having the same issue and found a blog article that shows how to make a link to your react-native mobile app: https://medium.com/react-native-training/deep-linking-your-react-native-app-d87c39a1ad5e

This uses something called linking in react-native:

More specifications:

With djoser you can send an email to the user that provides an url to activate the user's account. This url you send should link to your frontend which will then call your api and activate the user. With the technique specified in the blog you will probably be able to do such a thing.