Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
How to redirect and send variables of the current logged in correctly?

Hello how are you ? I'm new to javascript and I need help with a question. I'm trying to send data of the current logged in member and redirect a different domain via a button on the website creation www.wix.com. The data are status, full name, email and id. The language used is javascript. I would like to know what I do to be able to send this data together in the url and what I'm doing wrong in the code.

import { currentMember } from 'wix-members';
import wixLocation from 'wix-location';

export function button2_click(event) {
  wixLocation.to("www.page.com" + currentMember.getMember().then((member) => {
      const id = member._id;
      const status = member.status
      const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
      return member;
    })
    .catch((error) => {
      console.error(error);
    })
  );
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

After a lot of research on the Wix Velo forum, I discovered the members-wix API, at the moment it is having problems, which results in looking for functions in the users-wix API, but it is deprecated, which hides functions on the site the fleece making access to information difficult. However, after copying a migration function from users-wix to members-wix, along with members-wix authentication, it worked perfectly, I also want to thank Mosh Feu for help https://stackoverflow.com /users/863110/mosh-feu, which helped me understand and improve this code.

import { currentMember } from 'wix-members';
import wixLocation from 'wix-location';
import { authentication } from 'wix-members';
// NOTE: This example uses the new wix-members.currentMember.getMember()
// function, which replaces wix-users.currentUser.
// See the function description for more information, and
// line 36 for the deprecated example.

// ...

currentMember.getMember('FULL')
    .then((member) => {
        // Replaces currentUser.id
        const id = member._id;

        // Replaces currentUser.loggedIn
        const loggedIn = member ? true : false;

        // Replaces currentUser.getEmail()
        const loginEmail = member.loginEmail;
        const contactEmails = member.contactDetails.emails;
    })
    .catch((error) => {
        console.error(error);
    });

currentMember.getRoles()
    .then((roles) => {
        // Replaces currentUser.role and currentUser.getRoles()
        return roles;
    })
    .catch((error) => {
        console.error(error);
    });

// NOTE: This example uses the deprecated
// wix-users.currentUser object.

import wixUsers from 'wix-users';

// ...

let user = wixUsers.currentUser;

let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true

user.getEmail()
    .then((email) => {
        let userEmail = email; // "user@something.com"
    });

user.getRoles()
    .then((roles) => {
        let firstRole = roles[0];
        let roleName = firstRole.name; // "Role Name"
        let roleDescription = firstRole.description; // "Role Description"
    });

user.getPricingPlans()
    .then((pricingPlans) => {
        let firstPlan = pricingPlans[0];
        let planName = firstPlan.name; // "Gold"
        let startDate = firstPlan.startDate; // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
        let expirationDate = firstPlan.expiryDate; // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
    });
export async function button2_click(event) {
    authentication.onLogin(async(member) => {
        const loggedInMember = await member.getMember();
        const memberId = loggedInMember._id;
        console.log(`Member ${memberId} logged in:`, loggedInMember);
    });

    const member = await currentMember.getMember();
    const id = member._id;
    const status = member.status;
    const email = member.loginEmail
    const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
    const userDetails = JSON.stringify({ id, status, fullName ,email });

    wixLocation.to(`https://www.url.com/?user=${encodeURIComponent(userDetails)}`);
}
about 4 years ago · Juan Pablo Isaza Relatório

0

  1. As James mentioned, getMember return Promise so you should wait (await) or the Promise to fulfilled with the data before you can use it.
  2. You are trying to concat an object (the user details) with string (the url). It's not possible in Javascript. You can "convert" the object to string using JSON.stringify.
  3. Even if the object is string, the URL you are trying to redirect to is not valid e.g. www.page.com{id:1111,status:'active'}. The valid way to pass data via the url is by query params e.g.www.page.com?userDetails={id:1111,status:'active'}.
    Just to be on the safe side, encode the stringified object with encodeURIComponent().
export async function button2_click(event) {
  const member = await currentMember.getMember();
  const id = member._id;
  const status = member.status
  const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
  const userDetails = JSON.stringify({id, status, fullName});
  
  wixLocation.to(`www.page.com?user=${encodeURIComponent(userDetails)}`);
}

(You can use the "then approach" you are using now but it's a good opportunity to use more modern API such as async/await)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda