Is it possible to verify the domain zone of an email in Firebase Authentication?

Is it possible to verify the email domain zone in Firebase Authentication?

For instance, I am interested in allowing successful registrations for emails from Yahoo and Gmail (@yahoo.com, @gmail.com emails).

p.s. While validation on the client side is an option, it may not be sufficient.

Answer №1

Regrettably, it is not possible to verify the email domain prior to registration without client-side validation.

You have a couple of options available to you:

  • Option 1: Restrict access to the database and storage if the user's domain does not match specific domains:

For instance:

"rules": {
    ".read": "auth.token.email.endsWith('@gmail.com')",
    ".write": "auth.token.email.endsWith('@gmail.com')"
  }
}

or something along these lines:

"rules": {
    ".read": "auth.token.email_verified == true && auth.token.email.matches(/.*@gmail.com$/)",
    ".write": "auth.token.email_verified == true && auth.token.email.matches(/.*@gmail.com$/)"
  }
}

Credits:

  • Option 2: Implement a Firebase Authentication trigger to monitor new users. This way, you can validate newly registered users and deactivate those with invalid domains:

For example:

exports.validateUser = functions.auth.user().onCreate((user) => {
   if (!user.email.matches(/.*@gmail.com$/)) {
       admin.auth().updateUser(data, {
           disabled: true
       });
   }
});

Credits: https://firebase.google.com/docs/functions/auth-events

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

Is there a way to obtain the current time upon clicking the timepicker?

Here is a snippet of my code: // TIME $('#timepicker').datetimepicker({ minDate: minTime, }) .on('dp.show', function(e){ console.log(selectedDate); if($(this).val()==""){ $(this).val(minTime.format("HH:mm") ...

A comprehensive guide to utilizing the features of popper.js

I'm currently working on a Laravel project and have made the decision not to include Bootstrap. Is it possible for me to import and use the popper.js plugin separately without relying on Bootstrap? After attempting to do so, I've encountered an ...

Please complete and submit the form received from an AJAX request

I am having trouble submitting a form returned by ajax. Below is the code snippet I attempted to use: The file in question is named 3.php <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> ...

Angular - Issue: Unable to locate 'classlist.js'

require('classlist.js'); While building the project using Angular CLI, an error appeared in the console. I ran the command "npm install --save classlist.js" within the project directory. Error: Module not found: Can't resolve 'classl ...

Is it possible to synchronously read a custom field from package.json?

Is there a way for users of my module to customize its functionality by defining a custom field in package.json? I'm struggling with reading it synchronously. If I need to read someField from the package.json file of an app or module that utilizes my ...

ReactJS encountered an error: [function] is not defined, July 2017

Attempting to convert a JSON file into an array and then randomly selecting 5 items from it. I suspect the issue lies in my render/return statement at the end of ImageContainer.js, but as a newbie in ReactJS, it could be anything. Any assistance or guida ...

Invoke a function or variable based on a string parameter within a JavaScript/React function dynamically

I am currently exploring ways to dynamically call a function based on a string or reference a variable using a string. For example: import React, {useState} from 'react' const array = [ { text: 'count1', setFunctionName: &apo ...

Could someone provide a breakdown of the purpose of the $q service in AngularJS?

Being new to the world of angularjs, I recently came across $q while exploring restful api calls. The use of $q.defer() to retain the promise object caught my attention, but after reading up on promises, I still couldn't quite grasp their purpose. Wh ...

What is the best way to create a seamless Asynchronous loop?

Adhering to the traditional REST standards, I have divided my resources into separate endpoints and calls. The primary focus here revolves around two main objects: List and Item (with a list containing items as well as additional associated data). For ins ...

Can a JavaScript function be sent back via AJAX from PHP?

Can a javascript function be returned via Ajax from php? Typically, I would just return a value and handle it in plain javascript. However, since I am working on an Apache Cordova mobile app, I need to approach things differently. account = localStorage.g ...

Looking to loop through the JSON objects saved in an array of JSON data in local storage

I have reviewed various resources, including Iterate through nested json object array, but none of them seem to address my specific situation. The current challenge I am facing involves storing multiple JSON objects in an array within local storage. This ...

Unintentional GET request triggered by Axios baseURL

I have encountered a strange issue where defining axios.defaults.baseURL = baseUrl; results in an unexpected GET request right after initializing my Vue app. Any assistance would be greatly appreciated! Below are images showing the code and network reques ...

Placing the Cursor in a Document Editor

I'm currently working on a basic text editor and I'd like to add the feature where users can click on any text they've written to start editing it. To make this happen, I've set up a caret div to act as the cursor, positioning it accor ...

Issue with iOS app crashing due to Firebase - Seeking guidance on reconfiguring app to access database smoothly

After setting up my app with FirebaseApp.configure(); in the Appdelegate and launching the app, I realized I needed to incorporate database functionality. So, I replaced the initial configuration code with: AppDelegate.ref = Database.database().referenc ...

Guide on importing non-English content into Firestore using JSON files?

While I understand how to transfer data from JSON to RTDB and then to Cloud Firestore using node.js, I am facing a unique issue. My database is in Gujarati, an Indian language, but when I import it into Firebase RTBD, the text gets converted to question m ...

Tips for continuously randomizing colors in p5.js

I recently began exploring p5.js and I have a query regarding color randomization. Currently, it seems that the color only changes randomly when I restart the code. Is there a way to trigger this randomization every time the mouse is clicked? Below is the ...

Utilizing AJAX and PHP to refresh information in the database

For my project, I need to change the data in my database's tinyint column to 1 if a checkbox is selected and 0 if it is deselected. This is the Javascript/Ajax code I have written: <script> function updateDatabaseWithCheckboxValue(chk,address) ...

Utilize JavaScript and CSS to create dynamic text animations

(() => { const paraElement = document.querySelector('#animated-text'); const spanElement = paraElement.querySelector('span'); const wordsList = JSON.parse(spanElement.dataset.words); let counter = 0; setInterval(funct ...

My postman is successfully uploading image files, but for some reason, my code isn't cooperating. Are there any adjustments that need to be made?

While attempting to upload an image file with form data in Angular, I encountered a discrepancy in behavior between Postman and my project. In Postman, under the headers section, I have configured the following: Content-Type: multipart/form-data, token: ...

Wait for the completion of asynchronous functions, then execute them sequentially and finally call the last function

Currently, I am utilizing Vue, Node, and TypeScript for my project. One of the challenges I am facing is fetching essential data that multiple functions rely on. The getDataForFunction123() function requires an await operation, which is working fine. Howe ...