Learn The Mern Stack [10] - React & Redux Auth State

preview_player
Показать описание
In this video we will add our auth reducer to handle storing authentication state including the JWT token and the user data.

Original Series First Video:

Code:

💖 Become a Patron: Show support & get perks!

Website & Udemy Courses

Follow Traversy Media:
Рекомендации по теме
Комментарии
Автор

For everybody else who was confused about how does our Local storage know about token, I think Brad forgot to actually send it in reducer
Edit: Yep, thath's true, it's fixed in the next video

ВладГалышев-кэ
Автор

Man, you're doing the lord's work with these videos

emiljanocamie
Автор

People hate redux because of all the boilerplate, but it's pretty simple, because Redux actions are just functions. Here is an example how i define my actions in my app:

const createAction = type => ({ type, action: payload => ({ type, payload }) }); //utility function to create actions
export const actionAuthLoginSuccess =
export const actionAuthLogout = createAction('AUTH_LOGOUT');

very clean!. Then in your reducer

export const authReducer = (state = {}, { type, payload }) => {
switch (type) {
case actionAuthLoginSuccess.type:
return { ...state, isAuthenticated: true, currentUser: payload };
default:
return state;
}
};

then in the component i want to dispatch:


rtorcato
Автор

Hey @Brad is it safe to store the jwt token in local storage? I have wondered about this for a bit. Thanks

camsolo
Автор

At 25:00, it's really amazing that you could identify the problem immediatly!

yuchengzhou
Автор

Hi guys!, 21:57 in errorAction.js why we don't have dispatch(), please ?.

yanndeo
Автор

I think I can understand redux a bit. I am just telling the actions then reducer is doing his works. Their connection between them is created by redux. Please correct me if I am wrong.

shadabanwar
Автор

Brad, or anyone else, would you use localStorage for JWTs in a production application?

chancer
Автор

i've read in redux documentation that reducers should not cause side effects but you are removing token from the localstorage inside one reducer

apkpyramid
Автор

Redux state refreshes on reload ? How to persist that ?
Using localstorage, session is also not safe.
Saving few datas throughout the session is important.

samirkumar
Автор

Is it possible to use React Context API and not have to use redux at all?
I'm speaking in terms of small to medium applications.

sahilvig
Автор

I gotta say dude, sometimes I dog you out because you never answer Udemy Q&A but I spent 10k on a useless code bootcamp and I learn more from a free youtube video/$12 Udemy course than I did through them. I don't expect you to answer this, but why do we not use passport? I know you updated your MERN stack front to back course to exclude passport and was just curious. Thanks and keep posting and we'll keep grinding.

Elregar
Автор

My route at /api/auth/user will not run if there is no token, but Brad's seems to work fine?

flyingchicn
Автор

I am never gonna use this redux thing ever after this tutorial :)

ashishchourasia
Автор

Thank you so much for adding auth and access control videos :)

prafullaraichurkar
Автор

Wow!! Just Wow!! I was waiting for this series to continue

KochharAmandeep
Автор

My brain gonna explode absorbing all of these all at once! haha

renzserilo
Автор

Hello! I am getting the following error: TypeError: Cannot read property 'token' of undefined
. I think it's coming from de auth reducer. Can anyone help me please?

Itsthatboldguy
Автор

Dude you are an awesome instructor on youtube ❤️

nabeelimdad
Автор

Hey, my redux state is getting updated perfectly, but I'm getting the error on the console as well (from xhr.js : 177). Any idea why this is happening?

suryamn
visit shbcf.ru