Home  >  Q&A  >  body text

Create users in Vue using Firebase without logging in

I created a form to create user profiles. But whenever I create a user I have a problem. Logged in and logged out user. Please help to solve this problem.

const successCreate = () => {
  createUserWithEmailAndPassword(auth, email.value, confirmPassword.value)
    .then(() => {
      db.collection('businessForm')
        .add({
          schoolName: schoolName.value,
          board: board.value,
          subjects: [
            subject1.value,
            subject2.value,
            subject3.value,
            subject4.value,
            subject5.value,
            subject6.value,
            subject7.value,
            subject8.value,
          ],
          email: email.value,
          street: street.value,
          city: city.value,
          state: state.value,
          mobile: mobile.value,
          telephone: telephone.value,
          isAdmin: true,
        })
        .then(() => {
          isLoading.value = false
          notyf.success('Account created successfully!')
        })
        .catch((err) => {
          isLoading.value = false
          notyf.error('Something went wrong. Try again later!')
        })
    })
    .catch((err) => {
      isLoading.value = false
      notyf.error('Something went wrong. Try again later!')
    })
}

Any solutions appreciated!

P粉464088437P粉464088437108 days ago378

reply all(1)I'll reply

  • P粉068486220

    P粉0684862202024-04-07 12:29:32

    When you pass the createUserWithEmailAndPassword() method of Client JS SDK, the user will also log in to your application after success , as described in the documentation narrate. There is no way to avoid this.

    If you want to avoid the current user logging out (logout) and logging in as a newly created user, you need to implement a different method, such as calling the use of the < 来创建新用户的云函数a href="https://firebase.google.com/docs/reference/admin" rel="nofollow noreferrer">Management SDK.

    You may be interested in this article on how to use Callable Cloud Functions , a module that allows end users with a specific administrator role to create other users ( Disclaimer, I am the author).

    reply
    0
  • Cancelreply