Search code examples
apostrophe-cms

User profile picture


I am Starting A Project with apostrophe-cms as CMS. one thing which I need is the ability to add user profile pictures. I have seen that it is feasible in the demo that they provide here.

I have searched the docs how to do this but haven't seen a direct hint to it. Can someone point me in the right direction o how to achieve this?

Kind regards


Solution

  • You want to add an apostrophe-images widget to the schema of the piece responsible for managing user profiles, apostrophe-users in this case.

    In your lib/modules/apostrophe-users/index.js

    module.exports = {
      addFields: [
        {
          name: 'thumbnail',
          type: 'singleton',
          widgetType: 'apostrophe-images',
          label: 'Profile Picture',
          options: {
            limit: 1,
            aspectRatio: [100, 100]
          }
        }
      ]
    };
    

    You can change limit and aspectRatio to suite your needs or omit them altogether.

    You can view the code for how the demo does what it does by reviewing the code

    https://github.com/apostrophecms/apostrophe-sandbox/blob/master/lib/modules/apostrophe-users/index.js

    https://github.com/apostrophecms/apostrophe-sandbox/