• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

104
Views
Login still redirect to the same page even when using different email to log in

I'm using Firestore and Nuxt for my project.

I want my application to redirect the pages based on their user type when they are logged in.

I want if userType = contractor, when login it will redirect to /WPC/DashboardWPC. I want if userType = subcontractor, when login it will redirect to /Form/SectionA.

But currently, when logging in, it will always redirect to /Form/SectionA. I don't want that. I want it to log to different pages based on their user type.

Any advice?

    Login() {
      let credentials = {
        email: this.email,
        password: this.password,
      };
      this.$store
        .dispatch("user/Login", credentials)
        .then(() => {

          const users = firestore.collection('Users')

          users.get().then(() => {
            if (firestore.collection('Users').where("userType", "==", "subcontractor")) {
              window.location = "/Form/SectionA";
            } else if (firestore.collection('Users').where("userType", "==", "contractor")) {
              //console.log(snapshot.docs[0].data())
              window.location = "/WPC/DashboardWPC";
            } else {
              window.location = "/BWG/DashboardBWG";
            }
          })
      }).catch((err) => {
        alert(err.message)
      })
    }

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I am unsure how are you allowing your users to log in, but the signInWithEmailAndPassword is the method Firebase provides.

I have no experience with nuxt.js but something like this should give you a general idea:

Login() {
    firebase.auth().signInWithEmailAndPassword(this.email, this.password)
       .then((user) => {
            const _userDoc = firestore.collection('Users').doc(user.uid).get();
            const userType = _userDoc.data['userType'];
            if(userType == "subcontractor"){
                window.location = "/Form/SectionA";
            }
            else if(userType == "contractor"){
                window.location = "/WPC/DashboardWPC";
            }
            else{
                window.location = "/BWG/DashboardBWG";
            }
           
        },
        (err) => {
            alert(err.message);
        },
    );
}

Also, for registering your users you can use the createUserWithEmailAndPassword method.

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error