एक उपयोगकर्ता बनाएँ
आप createUserWithEmailAndPassword
विधि को कॉल करके या पहली बार फ़ेडरेटेड पहचान प्रदाता, जैसे कि Google साइन-इन या Facebook लॉगिन का उपयोग करके किसी उपयोगकर्ता में साइन इन करके अपने Firebase प्रोजेक्ट में एक नया उपयोगकर्ता बनाते हैं।
आप फायरबेस कंसोल के प्रमाणीकरण अनुभाग से, उपयोगकर्ता पृष्ठ पर, या व्यवस्थापक एसडीके का उपयोग करके नए पासवर्ड-प्रमाणित उपयोगकर्ता भी बना सकते हैं।
वर्तमान में साइन-इन उपयोगकर्ता प्राप्त करें
वर्तमान उपयोगकर्ता प्राप्त करने का अनुशंसित तरीका ऑथ ऑब्जेक्ट पर पर्यवेक्षक सेट करना है:
Web modular API
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 // ... } });
Web namespaced API
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 // ... } });
एक पर्यवेक्षक का उपयोग करके, आप सुनिश्चित करते हैं कि प्रामाणिक वस्तु एक मध्यवर्ती स्थिति में नहीं है - जैसे कि आरंभीकरण - जब आप वर्तमान उपयोगकर्ता प्राप्त करते हैं। जब आप signInWithRedirect
उपयोग करते हैं, तो onAuthStateChanged
पर्यवेक्षक तब तक प्रतीक्षा करता है जब तक getRedirectResult
ट्रिगर करने से पहले हल नहीं हो जाता।
आप currentUser
संपत्ति का उपयोग कर वर्तमान में साइन-इन उपयोगकर्ता भी प्राप्त कर सकते हैं। यदि कोई उपयोगकर्ता साइन इन नहीं है, currentUser
शून्य है:
Web modular API
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. }
Web namespaced API
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
के उदाहरण के गुणों का उपयोग करें। उदाहरण के लिए:
Web modular API
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; }
Web namespaced API
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
संपत्ति का उपयोग करें। उदाहरण के लिए:
Web modular API
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); }); }
Web namespaced API
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); }); }
उपयोगकर्ता की प्रोफ़ाइल अपडेट करें
आप उपयोगकर्ता की बुनियादी प्रोफ़ाइल जानकारी—उपयोगकर्ता का प्रदर्शन नाम और प्रोफ़ाइल फ़ोटो URL— updateProfile
पद्धति से अपडेट कर सकते हैं। उदाहरण के लिए:
Web modular API
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 // ... });
Web namespaced API
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
विधि से उपयोगकर्ता का ईमेल पता सेट कर सकते हैं। उदाहरण के लिए:
Web modular API
import { getAuth, updateEmail } from "firebase/auth"; const auth = getAuth(); updateEmail(auth.currentUser, "user@example.com").then(() => { // Email updated! // ... }).catch((error) => { // An error occurred // ... });
Web namespaced API
const user = firebase.auth().currentUser; user.updateEmail("user@example.com").then(() => { // Update successful // ... }).catch((error) => { // An error occurred // ... });
एक उपयोगकर्ता को एक सत्यापन ईमेल भेजें
आप sendEmailVerification
विधि के साथ किसी उपयोगकर्ता को पता सत्यापन ईमेल भेज सकते हैं। उदाहरण के लिए:
Web modular API
import { getAuth, sendEmailVerification } from "firebase/auth"; const auth = getAuth(); sendEmailVerification(auth.currentUser) .then(() => { // Email verification sent! // ... });
Web namespaced API
firebase.auth().currentUser.sendEmailVerification() .then(() => { // Email verification sent! // ... });
आप ईमेल टेम्पलेट पृष्ठ पर फायरबेस कंसोल के प्रमाणीकरण अनुभाग में उपयोग किए जाने वाले ईमेल टेम्पलेट को कस्टमाइज़ कर सकते हैं। Firebase सहायता केंद्र में ईमेल टेम्प्लेट देखें।
सत्यापन ईमेल भेजते समय ऐप पर वापस रीडायरेक्ट करने के लिए जारी URL के माध्यम से राज्य पास करना भी संभव है।
इसके अतिरिक्त आप ईमेल भेजने से पहले प्रमाणीकरण उदाहरण पर भाषा कोड अपडेट करके सत्यापन ईमेल को स्थानीयकृत कर सकते हैं। उदाहरण के लिए:
Web modular API
import { getAuth } from "firebase/auth"; const auth = getAuth(); auth.languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // auth.useDeviceLanguage();
Web namespaced API
firebase.auth().languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // firebase.auth().useDeviceLanguage();
उपयोगकर्ता का पासवर्ड सेट करें
आप updatePassword
विधि से उपयोगकर्ता का पासवर्ड सेट कर सकते हैं। उदाहरण के लिए:
Web modular API
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 // ... });
Web namespaced API
const user = firebase.auth().currentUser; const newPassword = getASecureRandomPassword(); user.updatePassword(newPassword).then(() => { // Update successful. }).catch((error) => { // An error ocurred // ... });
एक पासवर्ड रीसेट ईमेल भेजें
आप किसी उपयोगकर्ता को sendPasswordResetEmail
पद्धति से पासवर्ड रीसेट ईमेल भेज सकते हैं। उदाहरण के लिए:
Web modular API
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; // .. });
Web namespaced API
firebase.auth().sendPasswordResetEmail(email) .then(() => { // Password reset email sent! // .. }) .catch((error) => { var errorCode = error.code; var errorMessage = error.message; // .. });
आप ईमेल टेम्पलेट पृष्ठ पर फायरबेस कंसोल के प्रमाणीकरण अनुभाग में उपयोग किए जाने वाले ईमेल टेम्पलेट को कस्टमाइज़ कर सकते हैं। Firebase सहायता केंद्र में ईमेल टेम्प्लेट देखें।
पासवर्ड रीसेट ईमेल भेजते समय ऐप पर वापस रीडायरेक्ट करने के लिए जारी URL के माध्यम से राज्य पास करना भी संभव है।
इसके अतिरिक्त आप ईमेल भेजने से पहले प्रमाणीकरण उदाहरण पर भाषा कोड अपडेट करके पासवर्ड रीसेट ईमेल को स्थानीयकृत कर सकते हैं। उदाहरण के लिए:
Web modular API
import { getAuth } from "firebase/auth"; const auth = getAuth(); auth.languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // auth.useDeviceLanguage();
Web namespaced API
firebase.auth().languageCode = 'it'; // To apply the default browser preference instead of explicitly setting it. // firebase.auth().useDeviceLanguage();
आप फायरबेस कंसोल से पासवर्ड रीसेट ईमेल भी भेज सकते हैं।
एक उपयोगकर्ता हटाएं
आप delete
मेथड से यूजर अकाउंट को डिलीट कर सकते हैं। उदाहरण के लिए:
Web modular API
import { getAuth, deleteUser } from "firebase/auth"; const auth = getAuth(); const user = auth.currentUser; deleteUser(user).then(() => { // User deleted. }).catch((error) => { // An error ocurred // ... });
Web namespaced API
const user = firebase.auth().currentUser; user.delete().then(() => { // User deleted. }).catch((error) => { // An error ocurred // ... });
आप उपयोगकर्ता पृष्ठ पर Firebase कंसोल के प्रमाणीकरण अनुभाग से भी उपयोगकर्ताओं को हटा सकते हैं।
एक उपयोगकर्ता को फिर से प्रमाणित करें
कुछ सुरक्षा-संवेदनशील कार्रवाइयाँ—जैसे खाता हटाना , प्राथमिक ईमेल पता सेट करना और पासवर्ड बदलना —आवश्यक होता है कि उपयोगकर्ता ने हाल ही में साइन इन किया हो। क्रिया त्रुटि के साथ विफल होती है। जब ऐसा होता है, तो उपयोगकर्ता से नए साइन-इन क्रेडेंशियल्स प्राप्त करके और क्रेडेंशियल्स को reauthenticateWithCredential
पास करके उपयोगकर्ता को फिर से प्रमाणित करें। उदाहरण के लिए:
Web modular API
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 // ... });
Web namespaced API
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 // ... });
उपयोगकर्ता खाते आयात करें
आप फायरबेस सीएलआई के auth:import
कमांड का उपयोग करके उपयोगकर्ता खातों को अपने फायरबेस प्रोजेक्ट में फ़ाइल से आयात कर सकते हैं। उदाहरण के लिए:
firebase auth:import users.json --hash-algo=scrypt --rounds=8 --mem-cost=14