Skip to content

Commit

Permalink
Fix User signup bug & Profile meteor tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
ethancheez committed Nov 11, 2023
1 parent efce3ce commit bb096ce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
8 changes: 4 additions & 4 deletions app/imports/startup/server/Accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import { Users } from '../../api/user/User';

/* eslint-disable no-console */

const createUser = (email, password, role) => {
const createUser = (email, username, password, role) => {
console.log(` Creating user ${email}.`);
const userID = Accounts.createUser({
username: email,
username: username,
email: email,
password: password,
});
if (role === 'admin') {
Roles.createRole(role, { unlessExists: true });
Roles.addUsersToRoles(userID, 'admin');
}
Users.collection.insert({ _id: userID, username: email, email });
Users.collection.insert({ _id: userID, username, email });
};

// When running app for first time, pass a settings file to set up a default user account.
if (Meteor.users.find().count() === 0) {
if (Meteor.settings.defaultAccounts) {
console.log('Creating the default user(s)');
Meteor.settings.defaultAccounts.forEach(({ email, password, role }) => createUser(email, password, role));
Meteor.settings.defaultAccounts.forEach(({ email, username, password, role }) => createUser(email, username, password, role));
} else {
console.log('Cannot initialize the database! Please invoke meteor with a settings file.');
}
Expand Down
11 changes: 6 additions & 5 deletions app/imports/ui/pages/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ const Profile = () => {
const subscription = Meteor.subscribe(Users.userPublicationName);
const modelsSub = Meteor.subscribe(Models.userPublicationName);
const simSub = Meteor.subscribe(Simulations.userPublicationName);
const rdy = subscription.ready() && modelsSub.ready() && simSub.ready();
const rdy = subscription.ready() && modelsSub.ready() && simSub.ready() && Meteor.user() !== undefined;

const models = [];
const sims = [];
let modelItems;
let simItems;
let modelItems = [];
let simItems = [];

if (rdy) {
const usr = Users.collection.findOne({ _id: Meteor.user()._id });

Expand All @@ -45,8 +46,8 @@ const Profile = () => {
return {
likedModels: models,
likedSims: sims,
myModels: modelItems === undefined ? [] : modelItems,
mySims: simItems === undefined ? [] : simItems,
myModels: modelItems,
mySims: simItems,
ready: rdy,
};
}, []);
Expand Down
10 changes: 6 additions & 4 deletions app/imports/ui/pages/SignUp.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react';
import { Meteor } from 'meteor/meteor';
import PropTypes from 'prop-types';
import { Link, Navigate } from 'react-router-dom';
import { Accounts } from 'meteor/accounts-base';
Expand All @@ -25,16 +26,17 @@ const SignUp = ({ location }) => {
/* Handle SignUp submission. Create user account and a profile entry, then redirect to the home page. */
const submit = (doc) => {
const { email, username, password } = doc;
const userID = Accounts.createUser({ email, username, password }, (err) => {
Accounts.createUser({ email, username, password }, (err) => {
if (err) {
setError(err.reason);
} else {
setError('');
setRedirectToRef(true);
const userID = Meteor.users.findOne({ username: username })._id;
Users.collection.insert({ _id: userID, username, email }, () => {
setRedirectToRef(true);
});
}
});

Users.collection.insert({ _id: userID, username, email });
};

/* Display the signup form. Redirect to add page after successful registration and login. */
Expand Down

0 comments on commit bb096ce

Please sign in to comment.