Socialize profiles

Hey @copleykj,

I saw your socialize meteor packages and I definitely want to start using them and contribute. Any chance you can get my started on using the socialize-profiles package?

2 Likes

Sure, so right now the profile package is basically just a starting point for you to build on. The Idea is to get away from the profile key on the user document as itā€™s easy to leave a large security hole in your app.

To get started you can append to the schema in a shared space file.

Profile.appendSchema({
    firstName:{
        type: String,
        max: 20,
        optional: true
    },
    lastName:{
        type: String,
        max: 25,
        optional: true
    }
});

And then you can add methods to the model like so

Profile.methods({
    fullName: function(){
        return this.firstName +" "+this.lastName;
    }
});

As a note, you may need to run a package update as I just added the .methods() function to the BaseModel object in a release about 30 minutes ago.

4 Likes

So this all makes sense to me. What I donā€™t understand: Your package automatically includes, when installed, the creation of the users profile?

Iā€™m new to Meteor, so bare with me :smiley:

All of the examples Iā€™ve done so far, itā€™s all about creating a ā€œpostā€ or submitting an ā€œarticleā€ which all can be created multiple times by the user. This is the first thing in meteor that Iā€™ve had to deal with an object that is NOT created by the user, only one profile can exist per user, but they have control over the customization.

Yes, a new profile record is created on behalf of the user when a new user record is inserted. You can then customize the schema and create a way for the user to update their profile. This makes sense to me, but if there is enough feedback that this is any issue for others I can remove the automatic profile creation.

2 Likes

How would profile picture, I guess images work? Are they of type string and I just need to figure out the code to upload the photo?

Iā€™m working on more packages, one of which would handle this situation, but until then my personal preference is to use cloudinary to upload the image and then store the ID returned from cloudinary and use their API via URL to request the image in the size I need with any adjustments already made to it. This is likely what the package I create will do as well.

1 Like

I know this is how you would link to a post:

Router.route('/posts/:_id', { name: 'postPage' });

How do I access the path for the users profile?

This is what I have so far

Router.route('/:_id.profile.userName', { name: 'profile' });
I want to make the url be the userā€™s userName.

This should get you startedā€¦

Router.route('/:username', {
    name: 'profile',
    data: function() {
        return Meteor.profiles.findOne({username:this.params.username);
    },
    subscriptions: function() {
        return Meteor.subscribe("profileFor", this.params.username);
    }
});

Ug, I think Iā€™m in too deep with what I want to make. This doesnā€™t seem to be working. :frowning:

Iā€™ve done two Meteor tutorial books, Discover Meteor and My First Meteor Application. Both were a bit of a challenge to complete, with not a complete understanding of everything that I coded following along. I may not be ready to be using your awesome package yet.

Which part are you having trouble with?

Well I have a lot of the concepts scrambled up in my brain. Routing, templates, and helpers are what I feel good about. But Iā€™m not quite sure what Iā€™m missing. I keep Googling tons of different tutorials and try to mesh the tutorial code with my own project, but that just makes things worst because everyone has a different way on how they structure the files on their app.

Well if you have a code repo I can clone and you can point me to specific parts you are having trouble with, I can help. For now though Iā€™m off to sleep. Iā€™ll be back around in about 9 hours

Okay I think Iā€™m getting somewhere.

I believe I implemented all the code properly, but now Iā€™m getting an error the the command line :frowning:

 I20150612-21:58:30.227(-7)? Exception while invoking method 'ATCreateUserServer' TypeError: Cannot read property 'username' of null
I20150612-21:58:30.228(-7)?     at Object.Profile.appendSchema.username.autoValue (packages/socialize:user-profile/common/profile-model.js:28:1) 

Does that have to do with your package?

1 Like

Okay. When I restart the data, make a new account, the app gives me that error. When I restart the server I can log in with the account I just created. But no profiles are created.

Meteor.profiles.find().count();
0

I need to subscribe to the profiles correct?

Ok, should be fixed now.

From an API design point of view, Iā€™d suggest using a route more like:

Router.route('/profile/:username'...)

Otherwise, if you have a user with a username that is a key in your API space, youā€™ll have issues. For example, if someone has the username ā€˜homeā€™, or ā€˜postā€™, your routes are suddenly ambiguous.

Hi. I have standard meteor app with installed accounts-ui accounts-password accounts-google and socialize:user-profile

In my main.js I added

Profile.appendSchema({ "firstName":{ type:String, required: true }, "lastName":{ type:String, required: true } })

now when register a user in my mondodb I have profiles collection but without firstName and lastName fieldsā€¦ what should I do to get them?

Hello Kelly Copley, is there a tutorial on your profile package? I would love to take an online course or something about it.

2 Likes

A video going thru it would be really nice :slight_smile:

There currently is not, but Iā€™ve recently been acquiring the equipment necessary to do this, and thereā€™s chance that it could be coming with content Iā€™m looking to create as part of my Meteor Ambassadorship. Kids go back to school in couple of weeks so stay tuned.

1 Like