Using an action code to retrieve the current user from firebase: A step-by-step guide

I am in the process of designing 2 registration pages for users. The initial page prompts the user to input their email address only. After they submit this information, the following code is executed:

await createUserWithEmailAndPassword(auth, email.value, bcrypt.hashSync(email.value, 6))
      .then(async (userCredential) => {
        sendEmailVerification(userCredential.user)
        loading = false
        navigate('/verifyEmail')
      })
      .catch((error) => {
        log.error(`Error registering user: ${error}`)
        errorMessage = error.message
        isEmailInvalid = true
        loading = false
      })

A verification email is then sent to the user, allowing them to set up their password and account details:

    let oobCode = ''
    oobCode = window.location.href.split('oobCode=')[1].split('&')[0]
    const email = window.location.href.split('email=')[1].split('/')[0]
    let user = auth.currentUser
    await applyActionCode(auth, oobCode)
      .then(async (result) => {
        console.log(auth.currentUser)
        Promise.all([
          updateProfile(auth.currentUser, {displayName: firstName + ' ' + lastName}),
          updatePassword(auth.currentUser, password),
        ])
        console.log('Welcome', firstName, lastName)
        await setUser('local', undefined, auth.currentUser)
      })

However, if the user clicks on the link from a different browser, auth.currentUser will be null. A temporary solution could involve creating a user with a default password like 'password' and signing them in after applying the action code. Although not ideal from a security standpoint, my current approach involves encrypting the user's email as a temporary password to mitigate potential risks.

My main query revolves around updating user information post-action code application. If such an action is not feasible, what adjustments should I make to the sequence of operations?

Answer №1

How can I notify the user after applying an action code?

If the user is on a different browser, informing them may not be possible as they would not have knowledge of the password.

If notifying the user is not feasible, what changes should I make to the workflow?

In my opinion, you are complicating the onboarding process unnecessarily. Typically, accounts are created with the user choosing their own password (which should happen on the initial screen in your case) and then an email for verification is sent.

Simultaneously, access to Firebase back-ends (DBs, Cloud Storage, etc.) is restricted for users with unverified emails using Security Rules.

Once the email is verified, the user can log in:

  • If it's the same browser, the user is automatically signed in (due to the use of createUserWithEmailAndPassword())
  • If it's a different browser, the user simply needs to enter their email and password (which they should know)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Setting CSS attributes in React.js using a method similar to setState

What is the method to specify CSS in React.js? Here’s the scenario: I have a bar that starts at full height and then reduces in height through animation until it reaches 0px. Refer to the image below. https://i.sstatic.net/6cJFk.png The process works ...

Unexpected token error on an optional property in Visual Studio Code

I encountered a problem with a project I cloned. Below is the code snippet created using this project: https://github.com/enuchi/React-Google-Apps-Script export interface Vehicle { wheels: number; insurance?: string; } export default class Car { whe ...

The default locale for momentJS is set to zh-tw and I'm having trouble changing it

Currently, I am incorporating the momentJS library into my Angular application by pulling it from a CDN: <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.3/moment.min.js"></script> Although the default locale should be Engli ...

What is causing fs.readFileSync to not recognize my json document?

So, I've been working on creating a Discord bot that can extract specific data from my JSON file. Here is the structure of my project: Project | +-- data/ | | | +-- compSciCourses.json | +-- src/ | | | +-- search.js | +-- bot.js | +-- t ...

"The Vue.js/JavaScript object updates, but the changes are not being displayed in the document object model (DOM

Currently, I am endeavoring to iterate through an array of objects and display them as list items. There is a click listener that introduces a custom property to the object, and a class binding depends on the value of that property. Would you mind reviewin ...

What sets apart .create from .save in mongoose?

A while ago, I completed a bootcamp course on Express and Mongoose on Udemy. In the course, we learned how to add new fields to data by writing code like this: var playground = require("../models/playground.js"); route.post("/", middleware.isLoggedIn,fun ...

The never-ending cycle and memory overload that occur when using Angular's ngRoute

It seems like I may have hit a roadblock while attempting to get ng-view and ngRoute up and running. Everything appeared to be functioning correctly, but it looks like the entire process is caught in a loop. Just to provide some context, I am working with ...

Tips on customizing regex to selectively identify specific strings without capturing unrelated ones

Currently, I am working with this regex: /(?<=^|\/)(?:(?!\/)(?!.*\/))(.*?)[:-]v([\d.-]+)(?=\.|$)/ The goal is to extract the captured group from the following strings: rhmtc/openshift-velero-plugin-rhel8:v1.7.9-4 oc-mirror-plug ...

How can I send back multiple error messages from a pug template in a node.js application with Express?

I am currently working on validating inputs from a form on a Node.js web server using Pug.js and Express.js. The issue I am facing is that when there are multiple problems with the user's input, only the first error is displayed to the user. How can I ...

Problem encountered when transferring JSON data to PHP for file writing

After spending numerous hours researching potential solutions, I still can't seem to fix the issue at hand. Admittedly, I am fairly new to PHP, so it's possible that I am overlooking a small detail. The problem lies in the fact that I have a form ...

Consistently shifting the Aframe camera towards the focal point

Is there a way to continuously adjust the view of my Aframe scene based on the current viewing direction? It seems like there are two key components needed for this: (1) obtaining the current viewing direction in the correct format, and (2) creating and u ...

"npm is the go-to tool for managing client-side JavaScript code

As I delved into a document outlining the npm Developer Guide, a question sprang to mind. Is it within the realm of possibility to construct a web client application using javascript/css/html with npm at the helm? And if so, might there be examples avail ...

Adjust a Javascript script to choose the best font color for use in R Shiny applications

I am currently seeking to determine the font color of hover messages based on the background color. This means white if the background is dark, and black if it is light. However, I stumbled upon a Stack Overflow question with a Javascript solution that see ...

What could be causing the deployment failure of my Firebase/Postmark email dispatch function?

My Firebase function deployment is encountering an error during execution: "Function failed on loading user code. This is likely due to a bug in the user code." Below is the snippet of the function's code: const postmark = require("po ...

Discover the steps for dynamically adding a new row in an Angular application

I am trying to add new rows to a table in Angular, but I'm having some trouble. Initially, there is one empty row, and when I click on the "add new" button after entering details, a new row should be added. I was able to do this using jQuery, but I&ap ...

Is there a way to incorporate a delete button for each li element that is included in my list?

I have successfully implemented a to-do list where clicking on an item strikes a line through it and there is a delete button that works. However, I am looking for assistance on how to create a delete button for each newly added li item. var button = do ...

Problem with Ionic App crashing

Currently, I am developing an Ionic app that relies on local storage for offline data storage. The app consists of approximately 30 different templates and can accommodate any number of users. Local storage is primarily used to store three key pieces of i ...

Error encountered during Heroku deployment: "sh: 1: tailwind: not found"

package.json: "devDependencies": { "tailwindcss": "^0.7.4" }, "scripts": { "tailwind:css": "tailwind build src/css/tailwind.src.css -c tailwind.js -o src/css/tailwind.css", "start": "npm run tailwind:css && react-scripts start", ...

The proper method for developing Vue components that are dependent on the parent build tools

In my experience, this issue might also arise in other frameworks with plugin/component ecosystems that rely on specific build tools (such as React components with JSX). While Vue serves as my use-case. Having developed numerous Vue components as single . ...

Guiding users and verifying their identity using Nuxt's middleware for redirection and authentication

I have a challenge where I need to redirect a user to a login page if they are not logged in and try to access certain pages. The current code for this behavior is as follows: // middleware/authenticated.js import firebase from 'firebase' expor ...