Change the database in which data is saved when a person logs on

I do two types of login
1- Login for people whose data is saved in And this login I have no problem with it ( Private Members Data )

2- Corporate login
And this type of login, I do not want it to be in the same database with people. I want to have a database independent of people. Is there a way to implement that?

My Code For people login

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import wixData from 'wix-data';
let registration;

$w.onReady(function () {

 $w("#forgotPassword").onClick((event) => {

  wixUsers.promptForgotPassword()
 .then(() => {
 //
 })
 .catch((err) => {
 let errorMsg = err;
 });
 });

 if (wixUsers.currentUser.loggedIn) {
   wixWindow.lightbox.close()
    wixWindow.openLightbox('loadingPageT');
 
 }

 $w("#password").onKeyPress((event) => {
 let key = event.key;
  $w('#errorMessage').hide();
  $w('#emailExists').hide();
 if (key === "Enter") {

   console.log("Pressed Enter key on Password field"); //You can change the text of this line or delete it

 if ($w("#email").valid && $w("#password").valid && $w("#fname").valid && $w("#lastName").valid) {
 let email = $w("#email").value;
 let password = $w("#password").value;
 let first = $w("#fname").value;
 let last = $w("#lastName").value;

    wixUsers.register(email, password, {
      contactInfo: {
 "firstName": first,
 "lastName": last
 }
 })
 .then((result) => {
        wixWindow.lightbox.close()
       wixWindow.openLightbox('loadingPageT');
 
 
 })
 .catch((err) => {
 let errorMsg = err;
      console.log(errorMsg);
      $w('#emailExists').show();
 });
 } else {
    console.log("Some inputs are invalid"); //You can change the text of this line or delete it
    $w('#errorMessage').show();
 }
 } else {
   console.log("Did not press Enter key."); //You can change the text of this line or delete it
 }
 });

 $w("#registerButton").onClick((event) => {
  console.log("Button was clicked"); //You can change the text of this line or delete it
  $w('#errorMessage').hide(); //We want to hide all error messages when the person attempts to register again
  $w('#emailExists').hide(); //We want to hide all error messages when the person attempts to register again
 if ($w("#email").valid && $w("#password").valid && $w("#fname").valid && $w("#lastName").valid) {
   registerPerson();
   console.log("Trying to register"); //You can change the text of this line or delete it
 } else {
   $w('#errorMessage').show(); //This is were we prompt the message to show up again ONLY if there is an error
   console.log("Missing information"); //You can change the text of this line or delete it
 }

 });

});

function registerPerson() {

 let email = $w("#email").value;
 let password = $w("#password").value;
 let first = $w("#fname").value;
 let last = $w("#lastName").value;

 wixUsers.register(email, password, {
   contactInfo: {
 "firstName": first,
 "lastName": last
 }
 })
 .then((result) => {
    wixWindow.lightbox.close()
    wixWindow.openLightbox('loadingPageT');
 
 })
 .catch((err) => {
 let errorMsg = err;
   console.log(err);
   $w('#emailExists').show(); //This is were we prompt the message to show up again ONLY if there is an error
 });
}

I need code for Corporate login the data is stored in another database, not a Private Members Data database


any help PLZ @Velo-Ninja

1 Like

The data used to log in to companies cannot be logged in as persons and vice versa

I did not understand completely why you need a second database for log-in?
It is not recommended to use another DB than the Private-Members-Data to store member-data.

So what is exactly the aim, why you need to separate DBs? Or better asked, why you have already a secondary DB for member?

@russian-dima

The goal of creating another database is so that people cannot log in to the companies page with the same data, and also so that companies cannot enter the people page with the same data.

When registering the company’s data in order to create an account, it will be in the same database, so when you use this data on the people page, it will authorize the company to enter the people page without creating an account and vice versa

The result is to separate the company’s login data from the people’s login data, in order not to authorize one of the parties to enter the two platforms with the same data

I have a code for a Custom Page login, but it is quite complicated cause it involves using JSON Web Tokens for safety reasons. I’ll be doing a tutorial soon to explain everything.

Thank you for the reply I have no problem with the complex codes. Can you share us here.

@downloadops6 Yes, I’m just correcting some bugs to release it.


@bwprado Thanks for all your services

@Bruno Prado How are you still waiting for a solution from you

How are you still waiting for a solution from you

Hi there Diaa :raised_hand_with_fingers_splayed:

The solution for this is to use a second database for members with a reference field to the system database, and a boolean field to indicate whether the member is a business account or not.

Here’s an example of the database items:

[
    {
        name: 'Ahmad',
        email: 'ahmad@nasriya.net',
        business: false,
        member: // A referenfce to the private members (system) databse
    },
    {
        name: 'Nasriya Software, LLC',
        email: 'contact@nasriya.net',
        business: true,
        member: // A referenfce to the private members (system) databse
    }
]

This simplifies the whole process.

Hope this helps~!
Ahmad

@russian-dima I guess he just wants to prevent company members from logging into other members’ pages or vice versa