उपयोगकर्ता बनाएं
आप
createUserWithEmailAndPassword
करने का तरीका इस्तेमाल करें या फ़ेडरेटेड आइडेंटिटी का इस्तेमाल करके पहली बार साइन इन करें
जैसे, Google साइन-इन या
Facebook में लॉगिन करें.
पुष्टि करने की सुविधा से, पासवर्ड की पुष्टि करने वाले नए उपयोगकर्ता भी बनाए जा सकते हैं Firebase कंसोल के सेक्शन में जाकर, उपयोगकर्ता पेज पर जाकर या एडमिन SDK टूल.
वर्तमान में प्रवेश किए हुए उपयोगकर्ता को पाएं
वर्तमान उपयोगकर्ता प्राप्त करने का सुझाव दिया जाता है कि आप पुष्टि करने के लिए ऑब्जेक्ट:
import { getAuth, onAuthStateChanged } from "firebase/auth"; const auth = getAuth(); onAuthStateChanged(auth, (user) => { if (user) { // User is signed in, see docs for a list of available properties // https://firebase.google.com/docs/reference/js/auth.user const uid = user.uid; // ... } else { // User is signed out // ... } });
firebase.auth().onAuthStateChanged((user) => { if (user) { // User is signed in, see docs for a list of available properties // https://firebase.google.com/docs/reference/js/v8/firebase.User var uid = user.uid; // ... } else { // User is signed out // ... } });
ऑब्ज़र्वर का इस्तेमाल करके, आप यह पक्का करते हैं कि Auth ऑब्जेक्ट किसी इंटरमीडिएट में नहीं है
स्थिति—जैसे कि शुरू करना—जब आपको मौजूदा उपयोगकर्ता मिल जाए. आसानी से अपने कैलेंडर में जोड़ें.
signInWithRedirect
का इस्तेमाल करें, onAuthStateChanged
ऑब्ज़र्वर कब तक इंतज़ार करेगा
ट्रिगर करने से पहले getRedirectResult
का समाधान हो जाता है.
currentUser
का इस्तेमाल करके, साइन-इन किए हुए मौजूदा उपयोगकर्ता की जानकारी भी पाई जा सकती है
प्रॉपर्टी. अगर किसी उपयोगकर्ता ने साइन इन नहीं किया है, तो currentUser
शून्य होता है:
import { getAuth } from "firebase/auth"; const auth = getAuth(); const user = auth.currentUser; if (user) { // User is signed in, see docs for a list of available properties // https://firebase.google.com/docs/reference/js/auth.user // ... } else { // No user is signed in. }
const user = firebase.auth().currentUser; if (user) { // User is signed in, see docs for a list of available properties // https://firebase.google.com/docs/reference/js/v8/firebase.User // ... } else { // No user is signed in. }
उपयोगकर्ता की प्रोफ़ाइल पाएं
किसी उपयोगकर्ता की प्रोफ़ाइल जानकारी प्राप्त करने के लिए,
User
. उदाहरण के लिए:
import { getAuth } from "firebase/auth"; const auth = getAuth(); const user = auth.currentUser; if (user !== null) { // The user object has basic properties such as display name, email, etc. const displayName = user.displayName; const email = user.email; const photoURL = user.photoURL; const emailVerified = user.emailVerified; // The user's ID, unique to the Firebase project. Do NOT use // this value to authenticate with your backend server, if // you have one. Use User.getToken() instead. const uid = user.uid; }
const user = firebase.auth().currentUser; if (user !== null) { // The user object has basic properties such as display name, email, etc. const displayName = user.displayName; const email = user.email; const photoURL = user.photoURL; const emailVerified = user.emailVerified; // The user's ID, unique to the Firebase project. Do NOT use // this value to authenticate with your backend server, if // you have one. Use User.getIdToken() instead. const uid = user.uid; }
उपयोगकर्ता की कंपनी से जुड़ी प्रोफ़ाइल की जानकारी पाना
किसी
उपयोगकर्ता, providerData
प्रॉपर्टी का इस्तेमाल करें. उदाहरण के लिए:
import { getAuth } from "firebase/auth"; const auth = getAuth(); const user = auth.currentUser; if (user !== null) { user.providerData.forEach((profile) => { console.log("Sign-in provider: " + profile.providerId); console.log(" Provider-specific UID: " + profile.uid); console.log(" Name: " + profile.displayName); console.log(" Email: " + profile.email); console.log(" Photo URL: " + profile.photoURL); }); }
const user = firebase.auth().currentUser; if (user !== null) { user.providerData.forEach((profile) => { console.log("Sign-in provider: " + profile.providerId); console.log(" Provider-specific UID: " + profile.uid); console.log(" Name: " + profile.displayName); console.log(" Email: " + profile.email); console.log(" Photo URL: " + profile.photoURL); }); }
उपयोगकर्ता की प्रोफ़ाइल अपडेट करना
आपके पास उपयोगकर्ता की प्रोफ़ाइल की बुनियादी जानकारी—उपयोगकर्ता का डिसप्ले नेम अपडेट करने का विकल्प होता है
और प्रोफ़ाइल फ़ोटो का यूआरएल—updateProfile
तरीके का इस्तेमाल करके. उदाहरण के लिए:
import { getAuth, updateProfile } from "firebase/auth"; const auth = getAuth(); updateProfile(auth.currentUser, { displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg" }).then(() => { // Profile updated! // ... }).catch((error) => { // An error occurred // ... });
const user = firebase.auth().currentUser; user.updateProfile({ displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg" }).then(() => { // Update successful // ... }).catch((error) => { // An error occurred // ... });
उपयोगकर्ता का ईमेल पता सेट करें
updateEmail
तरीके का इस्तेमाल करके, उपयोगकर्ता का ईमेल पता सेट किया जा सकता है. उदाहरण के लिए:
import { getAuth, updateEmail } from "firebase/auth"; const auth = getAuth(); updateEmail(auth.currentUser, "user@example.com").then(() => { // Email updated! // ... }).catch((error) => { // An error occurred // ... });
const user = firebase.auth().currentUser; user.updateEmail("user@example.com").then(() => { // Update successful // ... }).catch((error) => { // An error occurred // ... });
उपयोगकर्ता को पुष्टि करने के लिए ईमेल भेजें
आप ऐसे उपयोगकर्ता को पते की पुष्टि करने के लिए ईमेल भेज सकते हैं जिसके पास
sendEmailVerification
तरीका. उदाहरण के लिए:
import { getAuth, sendEmailVerification } from "firebase/auth"; const auth = getAuth(); sendEmailVerification(auth.currentUser) .then(() => { // Email verification sent! // ... });
firebase.auth().currentUser.sendEmailVerification() .then(() => { // Email verification sent! // ... });
आप उस ईमेल टेम्प्लेट को कस्टमाइज़ कर सकते है जिसका उपयोग के प्रमाणीकरण अनुभाग में किया जाता है ईमेल टेंप्लेट के पेज पर, Firebase कंसोल में दिखेगा. इसमें ईमेल टेम्प्लेट देखें Firebase सहायता केंद्र.
राज्य को किसी वापस रीडायरेक्ट करने के लिए यूआरएल जारी रखें को ऐप पर अपडेट करें.
इसके अलावा, पुष्टि करने के लिए लिंक की भाषा अपडेट करके, उसे स्थानीय भाषा में भेजा जा सकता है ईमेल भेजने से पहले Auth इंस्टेंस पर कोड. उदाहरण के लिए:
import { getAuth } from "firebase/auth"; const auth = getAuth(); auth.languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // auth.useDeviceLanguage();
firebase.auth().languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // firebase.auth().useDeviceLanguage();
उपयोगकर्ता का पासवर्ड सेट करना
updatePassword
तरीके से उपयोगकर्ता का पासवर्ड सेट किया जा सकता है. उदाहरण के लिए:
import { getAuth, updatePassword } from "firebase/auth"; const auth = getAuth(); const user = auth.currentUser; const newPassword = getASecureRandomPassword(); updatePassword(user, newPassword).then(() => { // Update successful. }).catch((error) => { // An error ocurred // ... });
const user = firebase.auth().currentUser; const newPassword = getASecureRandomPassword(); user.updatePassword(newPassword).then(() => { // Update successful. }).catch((error) => { // An error ocurred // ... });
पासवर्ड रीसेट करने के लिए ईमेल भेजें
आपके पास sendPasswordResetEmail
वाले किसी उपयोगकर्ता को पासवर्ड फिर सेट करने का ईमेल भेजने का विकल्प है
तरीका. उदाहरण के लिए:
import { getAuth, sendPasswordResetEmail } from "firebase/auth"; const auth = getAuth(); sendPasswordResetEmail(auth, email) .then(() => { // Password reset email sent! // .. }) .catch((error) => { const errorCode = error.code; const errorMessage = error.message; // .. });
firebase.auth().sendPasswordResetEmail(email) .then(() => { // Password reset email sent! // .. }) .catch((error) => { var errorCode = error.code; var errorMessage = error.message; // .. });
आप उस ईमेल टेम्प्लेट को कस्टमाइज़ कर सकते है जिसका उपयोग के प्रमाणीकरण अनुभाग में किया जाता है ईमेल टेंप्लेट के पेज पर, Firebase कंसोल में दिखेगा. इसमें ईमेल टेम्प्लेट देखें Firebase सहायता केंद्र.
राज्य को किसी वापस रीडायरेक्ट करने के लिए यूआरएल जारी रखें ऐप्लिकेशन को पासवर्ड रीसेट ईमेल भेजते समय.
इसके अलावा, पासवर्ड रीसेट ईमेल की भाषा अपडेट करके उसे स्थानीय भाषा में भी बदला जा सकता है ईमेल भेजने से पहले Auth इंस्टेंस पर कोड. उदाहरण के लिए:
import { getAuth } from "firebase/auth"; const auth = getAuth(); auth.languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // auth.useDeviceLanguage();
firebase.auth().languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // firebase.auth().useDeviceLanguage();
Firebase कंसोल से, पासवर्ड फिर से सेट करने के ईमेल भी भेजे जा सकते हैं.
उपयोगकर्ता को हटाना
आपके पास delete
तरीके से किसी उपयोगकर्ता खाते को मिटाने का विकल्प होता है. उदाहरण के लिए:
import { getAuth, deleteUser } from "firebase/auth"; const auth = getAuth(); const user = auth.currentUser; deleteUser(user).then(() => { // User deleted. }).catch((error) => { // An error ocurred // ... });
const user = firebase.auth().currentUser; user.delete().then(() => { // User deleted. }).catch((error) => { // An error ocurred // ... });
आप चाहें, तो Firebase कंसोल, उपयोगकर्ताओं के पेज पर.
किसी उपयोगकर्ता की फिर से पुष्टि करें
सुरक्षा के लिए संवेदनशील कार्रवाइयां—जैसे
खाता मिटाना,
मुख्य ईमेल पता सेट करना और
पासवर्ड बदलना—यह ज़रूरी है कि उपयोगकर्ता के पास
हाल ही में साइन इन किया है. अगर इनमें से कोई भी कार्रवाई की जाती है और उपयोगकर्ता ने साइन इन किया हुआ है
बहुत समय पहले, किसी गड़बड़ी के साथ कार्रवाई पूरी नहीं हो सकी.
ऐसा होने पर, साइन इन करने के लिए नए क्रेडेंशियल हासिल करके, उपयोगकर्ता की फिर से पुष्टि करें
उपयोगकर्ता से और reauthenticateWithCredential
को क्रेडेंशियल पास करना.
उदाहरण के लिए:
import { getAuth, reauthenticateWithCredential } from "firebase/auth"; const auth = getAuth(); const user = auth.currentUser; // TODO(you): prompt the user to re-provide their sign-in credentials const credential = promptForCredentials(); reauthenticateWithCredential(user, credential).then(() => { // User re-authenticated. }).catch((error) => { // An error ocurred // ... });
const user = firebase.auth().currentUser; // TODO(you): prompt the user to re-provide their sign-in credentials const credential = promptForCredentials(); user.reauthenticateWithCredential(credential).then(() => { // User re-authenticated. }).catch((error) => { // An error occurred // ... });
उपयोगकर्ता खाते इंपोर्ट करें
आप फ़ाइल से उपयोगकर्ता खातों को अपने Firebase प्रोजेक्ट में इंपोर्ट कर सकते हैं. इसके लिए
Firebase सीएलआई की auth:import
कमांड. उदाहरण के लिए:
firebase auth:import users.json --hash-algo=scrypt --rounds=8 --mem-cost=14