# Store Google authenticated users into a custom

**URL:** <https://community.auth0.com/t/store-google-authenticated-users-into-a-custom/103307>\
**Category:** Get Help\
**Tags:** application, sso\
**Created:** [March 25, 2023, 1:57am UTC](https://community.auth0.com/t/store-google-authenticated-users-into-a-custom/103307 "2023-03-25T01:57:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![erfan.saraj](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/erfan.saraj/32/42414_2.png) [@erfan.saraj](https://community.auth0.com/u/erfan.saraj)\
**Post date:** [March 25, 2023, 1:57am UTC](https://community.auth0.com/t/store-google-authenticated-users-into-a-custom/103307/1 "2023-03-25T01:57:01Z")

</div>

Continuing the discussion from [How to Store Google authenticated users into a custom database?](https://community.auth0.com/t/how-to-store-google-authenticated-users-into-a-custom-database/80189/3):

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?

---

<div class="post-metadata">

**Author:** ![david.doyle7](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.doyle7/32/57273_2.png) [@david.doyle7](https://community.auth0.com/u/david.doyle7)\
**Post date:** [May 22, 2024, 4:36pm UTC](https://community.auth0.com/t/store-google-authenticated-users-into-a-custom/103307/2 "2024-05-22T16:36:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![erfan.saraj](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/erfan.saraj/32/42414_2.png) [@erfan.saraj](https://community.auth0.com/u/erfan.saraj)\
**Post date:** [May 23, 2024, 1:37am UTC](https://community.auth0.com/t/store-google-authenticated-users-into-a-custom/103307/3 "2024-05-23T01:37:05Z")

</div>

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) {
    client.close();
    return callback(err || new WrongUsernameOrPasswordError(email));
  }

  bcrypt.compare(password, user.password, function (err, isValid) {
    client.close();

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

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

```

});  
}

---

<div class="post-metadata">

**Author:** ![david.doyle7](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/david.doyle7/32/57273_2.png) [@david.doyle7](https://community.auth0.com/u/david.doyle7)\
**Post date:** [May 23, 2024, 8:19am UTC](https://community.auth0.com/t/store-google-authenticated-users-into-a-custom/103307/4 "2024-05-23T08:19:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 6, 2024, 8:19am UTC](https://community.auth0.com/t/store-google-authenticated-users-into-a-custom/103307/5 "2024-06-06T08:19:02Z")

</div>

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