Setup:
I'm using Meteor 1.4.4.2 with React and the accounts-password package (versions accounts-base#1.2.17, accounts-password#1.3.6).
Problem:
When I import the accounts-password package (as instructed here) the function Accounts.changePassword is undefined. But other functions of the imported Accounts object are regularly defined, e.g. Accounts.setUsername.
Question: How to access the Accounts.changePassword function?
Code Snippet:
import {Meteor} from "meteor/meteor";
import {Accounts} from "meteor/accounts-base";
Meteor.methods({
"changePassword"(oldPassword, newPassword, callback) {
console.log(Accounts !== undefined); // => true
console.log(Accounts.changePassword === undefined); // => true
Accounts.changePassword(
oldPassword, newPassword, callback
); // => Error
}
Thank you for your help!
You need to check where you try to invoke the changePassword function. It is client only, see here. So you cannot use it in a method. Use it somewhere under a /client folder and you should be good.
Related
Am getting this error after following the steps mentioned in the nativescript-plugin-firebase readme file.
JS: firebase.init error: TypeError: Cannot read property 'database' of
undefined
https://github.com/EddyVerbruggen/nativescript-plugin-firebase
but i dont really understand nor do i know how to solve that.
the version of the plugin am using is : 6.4.0
with tns 4.1.2
EDIT: init code, from app.js
var firebase = require("nativescript-plugin-firebase");
firebase.init({ persist: true
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
}).then(
function (instance) {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
I finally solved it by installing the plugin manually via the CLI (i initially installed it through NativeScript sidekick) apparently they didnt take in count the fact that some plugins may require some user inputs, to do write specific config file (which nativescript-plugin-firebase), so by installing it manually i got to provide the user input needed, it got configured and it worked!
Good day developers! I'm working with Meteor.js it's my 1st expirience
I created collection in file
// ./dbs/messages.js
import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
export const Messages = new Mongo.Collection('messages');
and use it in api point with calling Messages.insert like that
// server/mail.js
import Messages from './dbs/messages.js';
Meteor.methods({
'message.post'(messageText, location){
Messages.insert({
messageText: messageText,
location: location
});
}
})
But when I call 'message.post' I get an error
Exception while invoking method 'message.post' TypeError
Messages.insert is not a function
BUT, when I comment collection import and declare it in server/main.js like that
// import Messages from './dbs/messages.js';
const Messages = new Mongo.Collection('messages');
Meteor.methods({
'message.post'(messageText, location){
Messages.insert({
messageText: messageText,
location: location
});
}
});
In this case my Messages.insert works properly.
Who has experience with Meteor - can you explain me what is the reason?
Thanks!
Also I have removed autopublish and insecure packages
As #MasterAM and #Ankur Soni said you need to import Messages using brackets import { Messages } from './dbs/messages.js';
The only way to import without brackets is by defining Messages and then exporting it like so export default Messages;
I initiate my collections in a "common" space. I feel what you did is actually right. You either declare the collection twice, once on the client side and once on the server side or do it only once in a common folder. I see in many documentations that the popular place to keep these declarations is the /imports/api ... which is common to both server and client.
Rgs,
Paul
Following Meteor docs on how to use the import directory structure, Example directory layout.
//-------------- publication.js`
import {Vehicles} from '../vehicles.js';
Meteor.publish('vehicles', function () {
return Vehicles.find();
});
//-------------- carClass.jsx
import './vehicles/server/publications.js';
const composer = (props, onData) => {
const subscription = Meteor.subscribe('vehicles');
if (subscription.ready()) {
const vehicle = Vehicles.findOne({name: 'jack'});
onData(null, { vehicle });
}
};
Does the publish method need to be exported?
Error in browser console saying:
Uncaught Error: Cannot find module './vehicles/server/publications.js'
How can this error be fixed? Thanks
Meteor publications are server-only code, so you can't import that script in carClass.jsx.
You should have some file like {app root}/server/main.js. You import your publications here to make them available for client scripts to subscribe to. It's important that this file isn't inside of the /imports folder, so that it is eagerly loaded when the server starts.
The problem is that the path ./vehicles/server/publications.js is not reachable from the carClass.jsx file. You should reference it by ./server/publications.js
I'm writing a angular2-meteor application with typescript using angular2-meteor 0.5.4 and angular2 beta17.
I'm using accounts-password meteor package with with angular2-meteor-accounts-ui for ui representation.
I also installed the meteor package alanning:roles.
now I need to import Roles in typescript and i fail to do so because it doesn't contain a typescript definition file.
I searched on google and I found https://github.com/meteor-typescript/meteor-typescript-libs
which container typescript definitions for many packages including Roles.
is this the way to go? am I missing something.
since I'm new to meteor and typescript i need reassurance that i'm following the right path.
thank you!
import your Roles like so
import { Roles } from 'meteor/alanning:roles';
Next, you need to add / update your custom typings file (meteor.d.ts in my case, which is autoloaded by Meteor)
declare module "meteor/alanning:roles" {
export module Roles {
function createRole(roleName: string): string;
function deleteRole(roleName: string): void;
function addUsersToRoles(users: any, roles: any, groups?: string): void;
function removeUsersFromRoles(users: any, roles: any): void;
function userIsInRole(user: any, roles: any): boolean; //user can be user ID or user object
function getRolesForUser(userId: string): string[];
function getAllRoles(): Mongo.Cursor<RolesDAO>;
function getUsersInRole(roleName: string): Mongo.Cursor<RolesDAO>;
var GLOBAL_GROUP: string;
}
}
There is a simpler way to import meteor packages in typescript. Most of the types are defined here
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types
https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/meteor
Install NPM module that has types defined.
meteor npm install --save #types/meteor-roles
Import the types in your modules
import { } from '#types/meteor-roles';
Now, you can use Roles type for methods like addUsersToRoles() etc.
I have a Meteor project where I'm using audit-argument-check. I'm getting an error message
Error: Did not check() all arguments during publisher 'document
I'm know this is related the audit-argument-check not being able to check all arguments. But as far as I'm concerned, I checked all of them. Concrete, I have defined a collection 'documents' and attached a SimpleSchema. As part of iron-router, I have the following:
Router.route('customerDocumentShow', {
template: 'customerDocumentShow',
path: 'customer/documents/:_id',
waitOn: function () {
return Meteor.subscribe('document', this.params._id);
},
data: function () {
return Documents.findOne(this.params._id);
}
});
So I'm passing only the documentId (this.params._id). On the server, I have defined a method:
Meteor.methods({
documentsReadMethod: function(documentId){
check(documentId, String);
var documentItem = Document.findOne(argument);
if (!documentItem) {
throw new Meteor.Error(500, 'Error 500: Not Found', 'No documents found.');
}
return documentItem;
}
});
So I'm checking to documentId in the server method. So not sure why I'm getting this error message.
Note: One thing I'm not entirely sure about though is how I need to call this method (right now, it's documentsReadMethod_. I'm not explicitly calling (on the client):
Meteor.call(documentsReadMethod, this.params_id);
as I'm using autoform, collection2 and simpleschema. I've been spending the entire weekend, but have no clue. Any idea's ?
Note: the code is on github: https://github.com/wymedia/meteor-starter-base
The problem is in the publish. You didn't check the id here:
https://github.com/wymedia/meteor-starter-base/blob/master/server/publications/documents.js#L16
Just add check(id, String); line 16 and it should work.
I have the same problem with another tuto !
Answer found at check is not defined in meteor.js : since Meteor v1.2, you have to add this package:
$ meteor add check