Skip to content

Instantly share code, notes, and snippets.

@JeremyIglehart
Created August 31, 2016 23:04
Show Gist options
  • Save JeremyIglehart/acd1d400dca89768b0cce85ac8d7ec82 to your computer and use it in GitHub Desktop.
Save JeremyIglehart/acd1d400dca89768b0cce85ac8d7ec82 to your computer and use it in GitHub Desktop.
Setting Meteor Session from the "Server" - or really?

This is probably bad design, Don't do this in real life.

I'm writing this gist in response to a comment on forums.meteor.com

I guess it's working... I wonder what is actually happening on the server side of things :X

Heh, oh well.

Thanks for the pointers aadams

... Other imports, etc...
import { addSuggestion } from '../../../api/suggestions/suggestions_methods'
... skipping code ...
addSuggestion.call(newSuggestion, (error, result) => {
if (error) {
// Something really bad has happened...
console.log(error)
} else {
// Success, clear the suggestion box
this.setState(this.setDefaultState())
console.log(result)
}
})
import { Meteor } from 'meteor/meteor'
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import { Session } from 'meteor/session'
import { Suggestions } from './suggestions'
import _ from 'lodash'
import moment from 'moment'
export const addSuggestion = new ValidatedMethod({
name: 'suggestion.add',
validate() { }, // Install `meteor add audit-argument-checks`
run(incommingSuggestion) {
let currentUser = Meteor.user()
if (!currentUser) {
Session.set('showLoginModal', true)
throw new Meteor.Error("not-logged-in", "An account is required to submit a new idea.", "addSuggestion method")
} else {
let suggestion = _.extend(incommingSuggestion, {
userId: currentUser._id,
score: 0,
timestamp: moment().toDate(),
})
return Suggestions.insert(suggestion)
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment