Skip to content

Instantly share code, notes, and snippets.

@jschlieber
Last active January 19, 2017 18:43
Show Gist options
  • Save jschlieber/ac6a8cd9d8456fdb429caf8db6f78568 to your computer and use it in GitHub Desktop.
Save jschlieber/ac6a8cd9d8456fdb429caf8db6f78568 to your computer and use it in GitHub Desktop.
Secure Meteor collections
import {Mongo} from 'meteor/mongo';
import createCollection from '../util/createCollection';
export interface Beer {
_id: string,
name: string,
variety: string;
strength: number;
}
export const Beers: Mongo.Collection<Beer> = createCollection<Beer>('beers');
import {Mongo} from 'meteor/mongo';
import lockCollection from './lockCollection';
export default function createCollection<DocInterface>(name: string): Mongo.Collection<DocInterface> {
let collection: Mongo.Collection<DocInterface> = new Mongo.Collection<DocInterface>(name);
return lockCollection<DocInterface>(collection);
}
import {Mongo} from 'meteor/mongo';
const DENY_RULES: Mongo.AllowDenyOptions = {
insert: () => true,
update: () => true,
remove: () => true,
};
export default function lockCollection<DocInterface>(collection: Mongo.Collection<DocInterface>): Mongo.Collection<DocInterface> {
collection.deny(DENY_RULES);
return collection;
}
import {Mongo} from 'meteor/mongo';
const DENY_RULES = {
create: () => true,
update: () => true,
delete: () => true,
};
export default function lockCollection(collection) {
collection.deny(DENY_RULES);
return collection;
}
import {Mongo} from 'meteor/mongo';
const DENY_RULES: Mongo.AllowDenyOptions = {
create: () => true,
update: () => true,
delete: () => true,
};
export default function lockCollection<DocInterface>(collection: Mongo.Collection<DocInterface>): Mongo.Collection<DocInterface> {
collection.deny(DENY_RULES);
return collection;
}
@jschlieber
Copy link
Author

jschlieber commented Jan 19, 2017

lockcollection ts - admin - visual studio code_013
lockcollection ts - admin - visual studio code_015
lockcollection ts - admin - visual studio code_017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment