Create item in separate collection on Member signup

Hi David :raised_hand_with_fingers_splayed:

Since you’re running sensitive code, you know it should run on the backend (server), and not on the frontend (visitors’ browsers), there are tons of articles and threads in this regard if you’re not familiar with it.

You need to shift the signup code to the backend, so once the user is signed up, get his ID and create an entry in your other database, here’s an example:

// Backend (Server): members.jsw
import members from 'wix-members-backend';
import { insert } from 'wix-data';

export async function signup({ email: '', password: '', firstName, lastName }) {
    const result = await members.authentication.register(
        email,
        password,
        {
            contactInfo: { firstName, lastName },
            privacyStatus: 'PRIVATE'
        }
    );
    
    console.log(result.member); // Should print:
    /*
        {
            _id: 'system_id',
            loginEmail: 'email@domain.com',
            ....
        }
    */
    
    // You can now create an entry based on the member's ID and nickname
    const member_data = {
        _id: result.member._id,
        nickname: result.member.nickname,
        property: value,
        // ...
    }
    
    await insert('col', member_data, { suppressAuth: true });
    
    return Promise.resolve({
        ok: true;
        sessionToken: result.member.sessionToken,
        approvalToken: result.member.approvalToken
    });
}

Now on your page.

import { signup } from 'backend/members.jsw';
import { authentication } from 'wix-members';
import { to } from 'wix-location';

$w('#signupBtn').onClick(() => {
    const email = $w('#email').value;
    const password = $w('#password').value;
    const firstName = $w('#firstName').value;
    const lastName = $w('#lastName').value;
    
    return signup({ email, password, firstName, lastName }).then(async (result) => {
        if (result.ok) {
            // Log the user in:            
            await authentication.applySessionToken(result.sessionToken);
            
            // Redirect the user to the home page.
            to('/');
        }
    })
})

Hope this helps~!
Ahmad