RememberMe feature using Firebase

My web application allows multiple users to log in using different credentials in separate tabs or browsers on the same machine. I achieve this by initializing Firebase with a unique app name for each login session.

When a user closes the tab or reloads the page, I automatically log them out using the signOut method from Firebase auth.

Now, I want to implement a Remember Me feature on my app page. This feature will remember the user's login information and allow them to access the app without entering their password again, even if the machine is restarted.

How can I achieve this functionality securely?

One approach I am considering is generating a token on the client side when Remember Me is activated and storing it in a cookie. This token would be linked to the user's password in a database table. However, storing passwords as-is in the database is not recommended, and sending the password back to the client poses security risks.

Are there any better alternatives for implementing the Remember Me feature?

Answer №1

With the latest update of Firebase JS 4.2.0, you now have the option to set session persistence. This means you can easily switch between different users in multiple tabs by using the following code snippet:

firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)

Additionally, when you close the window, the session will be automatically cleared.

For more details on this feature, visit https://firebase.google.com/support/release-notes/js#4.2.0 and https://firebase.google.com/docs/auth/web/auth-state-persistence

Answer №2

Integrate a rememberMe checkbox into your login form, adding a reference variable (such as remember). Utilize the firebase setPersistence method in the following manner:

firebase.auth().setPersistence(this.remember.checked ? fireauth.Auth.Persistence.LOCAL : fireauth.Auth.Persistence.SESSION)

(In this instance, JavaScript is being used for illustration purposes)

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

Utilizing model associations in Sails.js to populate an array

I am currently using "sails": "~0.10.0-rc5", "sails-mongo": "^0.10.0-rc3". I have two models: Invoice and Item. Invoice model Invoice: { name: 'sample 1', items: [1,2] // 1,2 are the ids of the Item model } Item model Item { id: 1 ...

hiding the search box by clicking away from it

Can someone help me with modifying this search box design? @import url(http://weloveiconfonts.com/api/?family=entypo); /* entypo */ [class*="entypo-"]:before { font-family: 'entypo', sans-serif; color: #C0C0C0; } * { margin: 0px; pad ...

Ensuring the absence of non-UTF8 characters in JavaScript

Seeking advice on creating a function in Javascript to determine if a string contains only UTF8 characters. The goal is to return true if the string has no non-UTF8 characters, and false if it does. No character replacement is needed, just a validation c ...

Leveraging Symfony: Passing route parameters to different functions

Exploring my controller: ** * @Route("/", name="homepage") * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function indexAction(Request $request) { return $this->render('default ...

difficulties encountered while inserting a script tag linking to a local file within an android webview

I have created an Android app with a simple WebView that loads a local HTML file from the assets folder in the project directory. The HTML file includes a tag that makes an AJAX call to an external service and expects a response in the form of a String re ...

Numerous instances of Codemirror

I have the ability to generate and exhibit multiple dynamic codemirror instances, however, I am having trouble referencing them using the code snippet below. I suspect that the problem lies in creating a dynamic function name (not entirely sure how to ac ...

Receiving JSON objects from Javascript in Django Views

When I attempt to pass a Json Object value from making an API call to my views.py in Django template, I encounter difficulty retrieving the value after an ajax call. let application = JSON.parse(sessionStorage.getItem("appId")); let kycStatus = a ...

How to use JavaScript to toggle datalabels on Highcharts?

Is it possible to make Highcharts show datalabels for a specific category when clicking on the legend item? I've attempted to enable datalabels using the code below, but it hasn't worked: chart.series[0].data.dataLabels.enabled = true; You can ...

The selected jquery script is failing to function as intended

I'm currently implementing jQuery chosen in a select element to enhance user experience, however I'm facing an issue when attempting to copy the chosen div to another div using jQuery $(document).ready(function() { $(".chosen").chosen({}); ...

Exploring the movement from one component to another in React Native

When working with React Native, I encountered a challenge in navigating between two views. The issue arises from having the button to navigate on one component while my main component is elsewhere. I am using react-navigation for this purpose. Here's ...

Configuring Firefox settings in Nightwatch

Is there a way to set Firefox preferences in nightwatch? I am trying to achieve the same thing in Java using nightwatch. To set Firefox preferences in nightwatch, you can use the following code snippet: FirefoxProfile profile = new FirefoxProfile(); prof ...

What is the process of property access and how does the subsequent line function?

I came across this code snippet on a JS tutorial page and I'm not entirely sure about its functionality. Could you please explain what this piece of code does? // Original source: https://javascript.info/property-accessors let user = { name: " ...

How can I troubleshoot the unresponsive remove div function on my website?

My code is running fine on CodePen (link provided below), but for some reason, it's not working properly in the web browser. I am executing the code from localhost and the button isn't responding as expected. CODE Here is my Visual Studio code ...

The webpage is failing to render the properties of the JSON object

I'm encountering an issue where my code is successfully displaying the object, but I am unable to access its properties in the console. What might be preventing me from retrieving the information stored in this object? Below is the snippet of code ca ...

Altering the inner HTML content of a div using the ID within an Angular component function

Attempting to change the inner HTML content of a div using its id with another div in an Angular component method. Successfully calling the populateEndpointHomeContent() method and retrieving the content, but encountering issues with subsequent content. Th ...

Creating a countdown clock with JavaScript

I am looking to create a timer using JavaScript that will decrement at different intervals based on the level. For example, if my timer starts at 500, I want it to decrement as follows: 1. The first level timer should decrement by 1 with a slow speed. ...

Ways to access PromiseValue in XMLHttpRequest with JSON

Is there a way to access an array that is within the PromiseValue instead of receiving Promise {<pending>} When I use .then(data => console.log(data)), I can see the array in the console log. However, my requirement is to display this array on an ...

Simple Way to Show API Output in Plain Text (Beginner Inquiry)

I'm a beginner when it comes to using APIs. I'm trying to display the plain text response from this URL on my webpage: However, I'm encountering issues with getting it to work. Here's my code: <script src="https://ajax.googleap ...

I'm curious about this specific expression in express.js - can you explain its significance?

Could you please provide a thorough explanation of the following line of code in NodeJS: var app = module.exports = express.createServer(); ...

Display Loading Spinner Upon Clicking Table Row

I have a table where when I click on the rows, multiple tables are loaded through ajax requests. I want to display a spinner while the ajax methods are running. So, I wrote the following code: $(".table-row").click(function (evt) { ShowSpinnerFunction( ...