TLDR: This post is not about http
deprecated error, but just an issue with my code. The problem has been solved. If you are using matb33:collection-hooks
and konecty:user-presence
, this post might be of interest.
Hi,
I’m having some trouble upgrading my code to Meteor2.0
I bumped into this error, after trying to use the loginwithgoogle:
D20210205-16:49:56.195(8) (http.js:169) The http package has been deprecated, please migrate to the fetch package and new web standards.
D20210205-16:50:02.346(8) (http.js:169) The http package has been deprecated, please migrate to the fetch package and new web standards.
D20210205-16:50:02.454(8) (http.js:169) The http package has been deprecated, please migrate to the fetch package and new web standards.
I20210205-16:50:02.787(8)? Exception while invoking method 'login' MongoError: '$set' is empty. You must specify a field like so: {$set: {<field>: ...}}
I20210205-16:50:02.788(8)? at Function.create (/Users/HafizFamily/.meteor/packages/npm-mongo/.3.8.1.yf5rmr.r2ea++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb/lib/core/error.js:57:12)
I20210205-16:50:02.788(8)? at toError (/Users/HafizFamily/.meteor/packages/npm-mongo/.3.8.1.yf5rmr.r2ea++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb/lib/utils.js:123:22)
I20210205-16:50:02.788(8)? at /Users/HafizFamily/.meteor/packages/npm-mongo/.3.8.1.yf5rmr.r2ea++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb/lib/operations/common_functions.js:379:39
I20210205-16:50:02.788(8)? at /Users/HafizFamily/.meteor/packages/npm-mongo/.3.8.1.yf5rmr.r2ea++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb/lib/core/connection/pool.js:405:18
I20210205-16:50:02.789(8)? at processTicksAndRejections (internal/process/task_queues.js:79:11)**strong text**
The code works on the last version of Meteor 1.12.1
, but after i’ve upgraded to Meteor 2.0
, the error occurs.
I understand that the http
packages has been deprecated, but I have not use http
package anywhere as of right now. The app that I am developing is still in its early stages. I’ve only had few public facing pages, and is now trying to include login/logout functionality. The app runs fine before adding the more configurations to Accounts
for login logout logic.
Here’s my main.js
file:
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import dayjs from 'dayjs';
import { Roles } from 'meteor/alanning:roles';
//import collections
import { UserProfiles } from '../imports/api/UserProfiles';
Meteor.startup(() => {
//rebooting Accounts Login Services by wiping the Google services clean...
Accounts.loginServiceConfiguration.remove({
service: "google"
});
//... then register a new Accounts Login Services upon starting up.
Accounts.loginServiceConfiguration.upsert(
{ service: 'google' },
{
$set: {
clientId: 'xxxxx.apps.googleusercontent.com',
loginStyle: 'popup',
secret: 'xxxx'
}
}
);
//**** ----- RESTRICT ACCOUNTS CREATION TO SELECTED EMAILS
//Accounts.config({restrictCreationByEmailDomain: 'xxx.com'});
var checkEmailAgainstAllowed = function(email) {
//var allowedDomains = ['mycompanydomain.com'];
var allowedEmails = ['xxx.com','yyy.com', 'zzz.com'];
//var domain = email.replace(/.*@/,'').toLowerCase();
email = email.toLowerCase();
return allowedEmails.includes(email);
};
Accounts.config({
restrictCreationByEmailDomain: function(email) {
if (!email) {
throw new Meteor.Error(403,'This email address is not allowed');
}
if (!checkEmailAgainstAllowed(email)) {
throw new Meteor.Error(403,'Opps! Thank you for your interest, but your email address is not listed in our beta testers database.');
}
return true;
}
});
//**** ----- SETTING UP USER PRESENCE HOOK
// Listen for new connections, login, logoff and application exit to manage user status and register methods to be used by client to set user status and default status
UserPresence.start();
// Active logs for every changes
// Listen for changes in UserSessions and Meteor.users to set presence status based on active connections to user collection...
UserPresenceMonitor.start();
//... then apply their status to the corresponding UserProfiles document
Meteor.users.after.update(function (userId, doc, fieldNames, modifier) {
UserProfiles.update({
owner : doc._id
}, {
$set: {
status : doc.status
}
}, {multi: true})
});
//**** ----- ADDING SUPERUSER ++ DUPLICATES USER DETAILS INTO USERPROFILES COLLECTION
Meteor.users.after.insert(function (userId, doc) {
if (typeof(doc.services.google) != "undefined") {
//custom assign a specific role for XXX, the creator
if(doc.services.google.email === 'xxx.com'){
Roles.createRole('superuser', {unlessExists: true});
Roles.addUsersToRoles(doc._id, ['superuser']);
doc.roles = ['superuser'];
doc.activated = 1;
doc.status = 'offline';
} else {
Roles.createRole('student', {unlessExists: true});
Roles.addUsersToRoles(doc._id, ['student']);
doc.roles = ['student'];
doc.status = 'offline';
doc.activated = 1;
}
UserProfiles.insert({
owner: doc._id,
firstTimeLogin: true,
... //shortened the code
});
}
});
//Push information to new collection in server
Accounts.onCreateUser(function(options,user){
if (options.profile)
user.profile = options.profile;
user._id = Meteor.users._makeNewID();
// Use provided profile in options, or create an empty object
user.profile = options.profile;
// Assigns first and last names to the newly created user object
user.profile.name = options.profile.name;
return user;
});
});
I’ve tried installing fetch
packages as per suggested in the doc but without understanding what’s triggered the error, I can’t troubleshot it.
Can anyone point me to the right direction. A Meteor newbie here.
EDIT:
Additional info: When I check the mongodb using robo3T, the login function appears to be successful as new user has been created, but the error persists.