poeti8 пре 7 година
родитељ
комит
ea357d37d7
2 измењених фајлова са 5 додато и 3 уклоњено
  1. 2 2
      client/actions/auth.js
  2. 3 1
      client/reducers/auth.js

+ 2 - 2
client/actions/auth.js

@@ -46,7 +46,7 @@ export const loginUser = payload => async dispatch => {
     const { data: { token } } = await axios.post('/api/auth/login', payload);
     cookie.set('token', token, { expires: 7 });
     dispatch(authRenew());
-    dispatch(authUser(decodeJwt(token).sub));
+    dispatch(authUser(decodeJwt(token)));
     dispatch(setDomain(decodeJwt(token).domain));
     dispatch(showPageLoading());
     Router.push('/');
@@ -77,7 +77,7 @@ export const renewAuthUser = () => async (dispatch, getState) => {
     const { data: { token } } = await axios(options);
     cookie.set('token', token, { expires: 7 });
     dispatch(authRenew());
-    dispatch(authUser(decodeJwt(token).sub));
+    dispatch(authUser(decodeJwt(token)));
     dispatch(setDomain(decodeJwt(token).domain));
   } catch (error) {
     cookie.remove('token');

+ 3 - 1
client/reducers/auth.js

@@ -1,6 +1,7 @@
 import { AUTH_USER, AUTH_RENEW, UNAUTH_USER, SENT_VERIFICATION } from '../actions/actionTypes';
 
 const initialState = {
+  admin: false,
   isAuthenticated: false,
   sentVerification: false,
   user: '',
@@ -13,7 +14,8 @@ const auth = (state = initialState, action) => {
       return {
         ...state,
         isAuthenticated: true,
-        user: action.payload,
+        user: action.payload.sub,
+        admin: action.payload.admin,
         sentVerification: false,
       };
     case AUTH_RENEW: