Skip to content

Commit

Permalink
storing username in mongoDb
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Sood committed Oct 2, 2020
1 parent 6533013 commit b66bc2b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 79 deletions.
112 changes: 37 additions & 75 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions client/src/store/modules/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ export default {
const user = await firebase
.auth()
.signInWithEmailAndPassword(payload.email, payload.password);
const username = user.user.displayName;
const userPayload = { id: user.user.uid, username: username };
const userPayload = { id: user.user.uid, username: user.user.displayName };
await axios.post('/api/users', userPayload);
commit('SET_USER', userPayload);
} catch (e) {
Expand Down
3 changes: 3 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const schema = new mongoose.Schema({
type: String,
required: true
},
username: {
type: String
}
});

module.exports = mongoose.model('User', schema);
5 changes: 3 additions & 2 deletions routes/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const router = express.Router();
// TODO:do you use it currently?

router.post('/', async (req, res) => {
const { id } = req.body
const { id, username } = req.body
const user = new User({
id
id,
username
});
try {
const newUser = await user.save();
Expand Down

0 comments on commit b66bc2b

Please sign in to comment.