Hi all,
Is there a clever somebody who could advise on an effective solution?
At the moment I am hiding a button from members not logged in. Only logged in members can see this button.
It works fine with Js code apart from when you are logged in the button remains hidden until page is refreshed. Is there a way to code a 1 time page refresh after member logs in?
Usually it should by default refresh the page on promptLogin as it is loaded for the first time after the user identifies. It is strange that elements aren’t loading after a login since it’s the same behavior as refreshing the page.
Meanwhile as a workaround I’d suggest you to use Wix-Location .to method and target the page itself at the end of the login event.
Please share a link to your site in the comments so we’ll be able to look into it.
@bmrt82 Were you ever able to solve this issue? I am expanding some elements (Wix Video Library) on a page based on whether the user is logged in and, if so, their user roles. The code works fine except when a user is logged out and then logs in on the same page I have the expand code. I either have to refresh the page or navigate to another page and come back. I can’t redirect because the code is in the onReady event. It will keep rendering. So, I would like to know if there is a way to force it to refresh the page after the login. It does not perform a refresh as expected. By the way, the page works fine if the user is on the page with the expand code and logs out. In this scenario, the page refreshes and the updates to the page are visible.
To save rendering time, I don’t need to refresh the whole page. I could re-render a portion of it.
create a lightBox for login, you can activate the login lightbox with an onClick event on your webpage, then code something like this on the lightbox page:
import wixUsers from ‘wix-users’; import wixLocation from ‘wix-location’; import {local} from ‘wix-storage’; import wixWindow from ‘wix-window’;
@mikemoynihan99 It looks like the onLogin() event handler (part of the wix-users API) was exactly what I was looking for. I put it in my onReady() event and added the wixLocation.to(wixLocation.url) to force a refresh of the current web page. I debated putting the code at the site level, but opted for the page level, since I really don’t need to force a refresh on every page each time a user logins. The elements which are expanded or collapsed based on the user login (and, if logged in, their roles) works now when the user logs in while on that particular page.
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
$w.onReady(function () {
$w("#forgotPassword").onClick( (event) => {
//wixWindow.lightbox.close()
wixUsers.promptForgotPassword()
.then( ( ) => {
//
} )
.catch( (err) => {
let errorMsg = err; //"The user closed the forgot password dialog"
});
});
});
export function loginButton_onclick(event) {
let email = $w("#email").value;
let password = $w("#password").value;
wixUsers.login(email, password)
.then( () => {
console.log("User is logged in");
wixWindow.lightbox.close();
wixLocation.to(wixLocation.url); //This reloads the same page and allows code to show hidden member parts.
} )
.catch( (err) => {
console.log(err);
$w("#errorMessage").expand(); // You can delete this line if you are not going to add an error message. Use a regular text element set to 'collapse on load' from the Properties Panel.
} );
}
Thanks guys for your answers, I did find a solution however I moved to Wordpress as Wix just was not working for what I needed for memberships and for downloading documents. There were too many fixes and coding snippets for simple actions
The database system was clunky as I had a 100 + downloadables. Wordpress has been my saving grace with this project and can be customised front end through plug ins. I do use wix for my other sites but found it did not Work for anything more than a simple e-commerce site sadly. That’s my experience anyway !
How can we achieve the same refresh, but after redirecting to a new page?
I want my users to land to a welcome page after sign-up (not login) which should show collection elements stored during the registration function I wrote custom. These elements appear only if I manually refreshing the page.
The additional data I stored in the register function should be retrieved automatically and shown in the signup-confirmation page upon load, but they actually appear only after I refresh manually the page.
Any idea on how I can achieve this? This is driving me mad since 3 days already, any help is super appreciated
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#registerButton").onClick( (event) => {
let email = $w("#email").value;
let password = $w("#password").value;
let first = $w("#firstName").value;
let last = $w("#lastName").value;
wixUsers.register(email, password, {
contactInfo: {
"firstName": $w('#firstName').value,
"lastName": $w('#lastName').value,
}
} )
.then( (result) => {
let resultStatus = result.status;
wixWindow.lightbox.close();
wixLocation.to("/sign-in-status"); //Change the URL ending to whatever page you want to send the user to after they log in.
} );
} );
});
Now that all depends on what you have set up your new members to do after registration, either manually approve or automatically approve.
My signup lightbox code below works fine perfectly and closes after registering details before moving user on to my signup status page, then both names will be saved in contacts and once site member is manually approved the member details will be added to ‘members’ database. https://support.wix.com/en/article/approving-a-site-member Who can be a member? Choose who can be a member of your site: Everyone: When a new member signs up, they are approved automatically. You do not need to do anything. People I approve: When a new member signs up, you receive a notification, both by email and in your site’s dashboard, asking if you want to approve or reject them. Only those who you approve become site members.
If you use Wix CRM, then you will be able to get certain parts of the new site members info through the contacts in your Wix dashboard before they are saved into your additional members dataset and then you can use Wix Users.