Skip to content

Commit

Permalink
Add debug logging for authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
VenEleni committed Aug 26, 2024
1 parent 366836d commit b191a48
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
4 changes: 3 additions & 1 deletion client/src/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ export const handleOAuthCallback = (token) => async (dispatch) => {
});
localStorage.setItem('auth', JSON.stringify(loggedInUser));
} catch (error) {
console.error('Error in handleOAuthCallback:', error);
dispatch({
type: LOGIN_FAIL,
payload: 'OAuth login failed',
payload: 'OAuth authentication failed',
});
return Promise.reject(error);
}
};

Expand Down
3 changes: 3 additions & 0 deletions client/src/components/OAuthCallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ function OAuthCallback() {
const location = useLocation();

useEffect(() => {
console.log('OAuthCallback - location:', location);
const urlParams = new URLSearchParams(location.search);
const token = urlParams.get('token');
console.log('OAuthCallback - token:', token);

if (token) {
dispatch(handleOAuthCallback(token))
.then(() => {
console.log('OAuthCallback - handleOAuthCallback success');
navigate('/');
})
.catch((error) => {
Expand Down
8 changes: 8 additions & 0 deletions client/src/loggingMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const loggingMiddleware = store => next => action => {
console.group(action.type)
console.info('dispatching', action)
let result = next(action)
console.log('next state', store.getState())
console.groupEnd()
return result
}
1 change: 1 addition & 0 deletions client/src/reducers/authReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ try {
}

const authReducer = (state = initialState, action) => {
console.log('Auth Reducer - Action:', action.type, 'Payload:', action.payload);
switch (action.type) {
case REGISTER_SUCCESS:
case LOGIN_SUCCESS:
Expand Down
36 changes: 21 additions & 15 deletions client/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,30 @@ import userFetchByIdReducer from './reducers/userFetchByIdReducer';
import cartReducer from './reducers/cartReducer';
import blogReducer from './reducers/blogReducers';
import productUpdateReducer from './reducers/productUpdateReducer';
import { loggingMiddleware } from './loggingMiddleware';

const rootReducer = {
auth: authReducer,
productCreate: productCreateReducer,
productsFetch: productsFetchReducer,
cartReducer: cartReducer,
fetchFilteredProducts: fetchFilteredProductsReducer,
shippingSetInfo: shippingSetInfoReducer,
ordersFetch: ordersFetchReducer,
updateOrderStatus: orderUpdateStatusReducer,
reviewCreate: reviewCreateReducer,
reviewFetch: reviewFetchReducer,
userFetchById: userFetchByIdReducer,
blogReducer: blogReducer,
productUpdateReducer: productUpdateReducer
};

const store = configureStore({
reducer: {
auth: authReducer,
productCreate: productCreateReducer,
productsFetch: productsFetchReducer,
cartReducer: cartReducer,
fetchFilteredProducts: fetchFilteredProductsReducer,
shippingSetInfo: shippingSetInfoReducer,
ordersFetch: ordersFetchReducer,
updateOrderStatus: orderUpdateStatusReducer,
reviewCreate: reviewCreateReducer,
reviewFetch: reviewFetchReducer,
userFetchById: userFetchByIdReducer,
blogReducer: blogReducer,
productUpdateReducer: productUpdateReducer
},
reducer: rootReducer,
devTools: process.env.NODE_ENV !== 'production',
middleware: (getDefaultMiddleware) => getDefaultMiddleware({
serializableCheck: false
}).concat(loggingMiddleware)
});

export default store;
Expand Down

0 comments on commit b191a48

Please sign in to comment.