Custom Sign up direct to Dynamic ID Collection Page

Below is the standard LOG IN code to log in and redirect an existing member to a custom dynamic page (after member userid is inserted into a database collection)

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( () => {
if (wixUsers.currentUser.loggedIn) {
$w(“#socialLogin”).label = “Logout”;
$w(“#button9”).show();

}
else {
$w(“#socialLogin”).label = “Login”;
$w(“#button9”).hide();

}
} );

export function socialLogin_onclick() {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#socialLogin”).label = “Login”;
$w(“#button9”).hide();

} ); 

}
// user is logged out
else {
let userId;
let userEmail;

// prompt the user to log in
wixUsers.promptLogin( {“mode”: “login”} )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“socialclients”)
.eq(“_id”, userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail
};
// add the item to the collection
wixData.insert(“socialclients”, toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#socialLogin”).label = “Logout”;
$w(“#button9”).show();

  } ) 
  . **catch** ( (err) => { 
    console.log(err); 
  } ); 

}
}

export function button9_onclick() {
wixLocation.to(/acct/update/${wixUsers.currentUser.id});
}

I would like something just like this, but direct a brand new customer to the dynamic page (site setting on auto accept member)

import wixUsers from ‘wix-users’;

import wixLocation from ‘wix-location’;

$w.onReady( function (){

$w('#signup').onClick( **function**  (){     

let email = $w(‘#email’).value;

let password = $w(‘#password’).value;

    wixUsers.register(email,password)    

    .then(()=>{ 

        wixLocation.to('/signup');  

        }) 

    }) 

})

Hi Jameson!

Is your current code to direct users to their dynamic page working for you?
What are your intentions in the second part?
In order to direct a user to his dynamic page there has to be a record in the collection of the user.

What you can do is to direct the user (via link) to the dynamic page after submission using the button’s capabilities.

Please elaborate on your intentions and use case and I’d be glad to assist.

Doron.

Doron, appreciate the responses!

The code for the dynamic page does work, but it is predicated on directing the user to login through the standard wix login screen, pull the userid info from wix records, THEN insert a new database collection row with the userid for the dynamic page.

Just like you are saying, I need a way to insert the customer data to the collection (including userid for a dynamic page) upon sign up. Then I could use a button link to pull from the collection row.

Basically need sign up code that inserts row in database collection with the wix user ID, then I can show a button with the link to the dynamic page.

Where does the user record is being created and saved now?
The conventional way is by creating a page that represents a sign up form.
This page/form collects (by user input) the data that you need about your users and using dataset/code, submits a record to a collection that eventually will contain all your users data.

In order to use this data you then pull anything you need from that collection and voila!
-it even includes the user’s ID / OwnerID!

Using the signup method alone will leave you with nothing but the record of a member with no exceptions or details.

Doron.

TY for the response - still a couple follow up questions for you Doron -

I tried what you mentioned, basically circumventing the need for wix members and member settings. But, I don’t have a way to allow people to log in and validate/pull the collection data to route them to the right dynamic/userid page. It just creates another duplicate record with a new dynamic user id (i attached an image of the table fields).

Also, if I want to have a paid section how would I do that?

Hi Jameson!

The image isn’t very clear. Would be happy to look into your site if you’d share a link to your published version/editor.
Note that only authorized personnel can inspect your site so rest assure other users won’t be able to enter the link (for the editor).

Anyway, item ID and _ownerID are two fields that are created automatically upon item submission to the collection (you can see them under ‘Visible Fields’ in the collection page).
The value of itemID is unique and so - two items will never have the same ID.
About the _ownerID - it is also unique but since it represents the ID of the user who created the item, if there’s no limitation on how many items/records can a user create, there may be more than one.
When talking about profile page/user page we obviously want to limit it.

Now. In order to navigate to one’s dynamic item page you’ll need to find the correct path to follow (much as you did in the first part of your code in the original post). It should look something like this:

if (wixUsers.currentUser.loggedIn) {              
   wixData.query("yourCollection")             
          .eq("_owner", wixUsers.currentUser.id)             
          .find()             
          .then((results) => {                
                if (results.length > 0) {                    
                   let url = results.items[0].id ;                          
                    wixLocation.to('/yourPath/${url}')                 
                  }             
             })     
    }

Let me know if it works for you!

Doron.

P.s.

As for the new question regarding the paid section - please post a new thread so other users in the future can distinguish and profit from your curiosity. :slight_smile: