Search code examples
react-admin

React admin app bar name and photo shows null


My react-admin project has been updated to lattest version. Now I can see this image in my AppBar. How can I show right username and photo correctly.

Appbar image

Thanks. Regards.


Solution

  • This is deep in the doc and happened in the authProvider:

    // in src/authProvider.js
    const authProvider = {
        login: ({ username, password }) => { /* ... */ },
        checkError: (error) => { /* ... */ },
        checkAuth: () => { /* ... */ },
        logout: () => { /* ... */ },
        getIdentity: () => {
            try {
                const { id, fullName, avatar } = JSON.parse(localStorage.getItem('auth'));
                return Promise.resolve({ id, fullName, avatar });
            } catch (error) {
                return Promise.reject(error);
            }
        }
        // ...
    };
    
    export default authProvider;
    

    ref: https://marmelab.com/react-admin/Authentication.html#user-identity