RuslanZab
RuslanZab

Reputation: 125

Do I have to use Redux with React for authentication?

This may be a stupid question.
So, I am using Django for my backend and React for my frontend. The goal is to only show the objects that belong to the user that is making the request. Since Django takes care of authentication, do I need to use Redux, or any other framework for that matter, for authentication?

Couldn't I just do something like: request.user.something.objects.all() on my backend when I receive the Axios request from my frontend? Do Axios request even provide the user?

Upvotes: 0

Views: 560

Answers (2)

Sagar Roy
Sagar Roy

Reputation: 443

Yes you can store data in rudex thats why logically you can also use rudex store as authentication . but if you change route or refresh page this data will be destroy . Axios in general send Brear?Basic authentication . For that you need to also configure your back-end api like that .You can also make authentication buy using browser session storage or localstorage . For that you have to pass authentication code from you header request Like as .

  fetch(URL+'/api/user/profile', {
                method: 'GET',
                   headers: {
                      'Authorization': 'Bearer ' + sessionStorage.getItem('token')
                            }
                 }).then(response => {
                    return response.json();

                })
                .then(profile => {   
                   // console.log(profile);
                     this.setState({
                            profile : profile[0]
                        });
                });

Upvotes: 1

Frustrated Programmer
Frustrated Programmer

Reputation: 341

No. Redux is optional. Store your token in local storage you can use mobx, redux and the context api for your user authentication

Upvotes: 0

Related Questions