Custom user redirects

Hi,
Im trying to find the best solution for allowing user’s to log in and be taken to there own page after logging in.

I have a external database that i want to display on the users page via HTML frame element,
This means every user needs a page that only they can access and allow me to add the HTML frame elements to there page.

Any help greatly appreciated.

I have managed to come up with what i hope to be a solution but will need further guidance am I’m not all to familiar with the .JS

The idea is to create a custom login and then using the ‘wixUsers’ to redirect to a specific page.
import wixUsers from ‘wix-users’ ;
import wixLocation from ‘wix-location’ ;

$w.onReady( function (){
$w( ‘#loginNow’ ).onClick( function (){
let email = $w( ‘#loginEmail’ ).value;
let password = $w( ‘#loginPassword’ ).value;
wixUsers.login(email,password)
.then(()=>{
wixLocation.to( ‘/wixUser’ );
})
})
})

for example,
if JOHN logs in and is a valid user ‘wixUser’ then he gets redirected to www.domain/JOHN
from there i could create a page titled JOHN and the redirect would work ???

Hey @deciseelectricandcontrol,

I’m not sure about redirecting a user to a page based on their username, but you could do it based on their email, have a look at this:

$w('#loginNow').onClick(function(){ 
    let email = $w('#loginEmail').value; 
    let password = $w('#loginPassword').value;
wixUsers.login(email,password)
    .then(()=>{
wixLocation.to(`/${email}`
});
    });
    });

You could use their username if you have it saved in a database, otherwise I don’t think there is a way.

Please try out this code and let me know if you need help!

Hi,
Here is the code i tryed,
import wixUsers from ‘wix-users’ ;
import wixLocation from ‘wix-location’ ;

$w( ‘#loginNow’ ).onClick( function (){
let email = $w( ‘#loginEmail’ ).value;
let password = $w( ‘#loginPassword’ ).value;
wixUsers.login(email,password)
.then(()=>{
wixLocation.to( / ${email}
});
});
});

$w.onReady( function (){
$w( ‘#registerNow’ ).onClick( function (){
let email = $w( ‘#registerEmail’ ).value;
let password = $w( ‘#registerPassword’ ).value;
wixUsers.register(email,password)
.then(()=>{
wixLocation.to( ‘/home’ );
})
})
})

register works perfect however, im not being redirected when trying it with a test email,

I have created a page titled with the test email but still no redirect.

thoughts?

Try this:

wixLocation.to(`/${email}`

If this does not work, please confirm the URL of the test email page