I am not able to render when I initally sign in- ReactJs, Firebase

0

I am expecting that after login I should be directed to the discover page, but by default it is going to the profile page. (only once i refresh the page, does discover page appear) this is the route config.

when we sign in , we don’t fetch the redux state on initial load, but when you refresh , you get the redux state. we want that redux state immediately after sign in, only then the mentee condition will be set as true

import React from 'react'
import { AUTH_PREFIX_PATH, APP_PREFIX_PATH } from 'configs/AppConfig'
import store from '../store'
import { CURRENT_USER } from 'constants/AuthConstant';

const reduxState = store.getState();
console.log(reduxState);
const isMentee = reduxState?.auth?.user?.role === 'mentee' || false;
console.log(isMentee);

export const protectedRoutes = [
    {
        key: 'dashboard.default',
        path: `${APP_PREFIX_PATH}/dashboards/default`,
        component: (isMentee) ? 
        React.lazy(() => import('views/app-views/dashboards/pages/home/homepage')): 
        React.lazy(()=> import('views/app-views/dashboards/pages/profile/profilepage')),
    },


// and from authSlice we need need auth.

export const authSlice = createSlice({
    name: 'auth',
    initialState,
    reducers: {
        authenticated: (state, action) => {
            state.loading = false
            state.redirect = '/'
            state.token = action.payload
        },
        showAuthMessage: (state, action) => {
            state.message = action.payload
            state.showMessage = true
            state.loading = false
        },
        hideAuthMessage: (state) => {
            state.message = ''
            state.showMessage = false
        },
        signOutSuccess: (state) => {
            state.loading = false
            state.token = null
            state.redirect = '/'
        },
        showLoading: (state) => {
            state.loading = true
        },
        signInSuccess: (state, action) => {
            state.loading = false
            state.token = action.payload.token
            state.user =  action.payload.user
            state.isRegistered = action.payload.isRegistered
        }, 
        pendingFeedback: (state, action) =>{
            state.user.pendingFeedback = action.payload.pendingFeedback
        } 
    },

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.