Store Google authenticated users into a custom

Continuing the discussion from How to Store Google authenticated users into a custom database?:

I want to add all users to my MongoDB custom database upon signup.
Can you provide an example of how to write the post-login script? which API should I call?

Was there ever a solution you found to this issue ? Thanks!

This is the post login script that I wrote, hope it helps.

function login(email, password, callback) {
const bcrypt = require(‘bcrypt’);
const MongoClient = require(‘mongodb@3.1.4’).MongoClient;
const client = new MongoClient(‘YOUR MONGO URL’);

client.connect(function (err) {
if (err) return callback(err);

const db = client.db('YOUR DB NAME');
const users = db.collection('YOU USER COLLECTION');

users.findOne({ email: email }, function (err, user) {
  if (err || !user) {
    return callback(err || new WrongUsernameOrPasswordError(email));
  }, user.password, function (err, isValid) {

    if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(email));

    return callback(null, {
        user_id: user._id.toString()


1 Like

Thanks so much for the reply, appreciate it! Quick side question, do you think users should have the ability to delete themselves from you customdb as well as the auth0 db when they click delete account or is that too much access for a user to have if that makes sense?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.