एक उपयोगकर्ता बनाएँ
आप अपने Firebase प्रोजेक्ट में CreateUserWithEmailAndPassword
विधि को कॉल करके या पहली बार फ़ेडरेटेड पहचान प्रदाता, जैसे कि Google साइन-इन या Facebook लॉगिन का उपयोग करके किसी उपयोगकर्ता में साइन इन करके एक नया उपयोगकर्ता बनाते हैं।
आप उपयोगकर्ता पृष्ठ पर फायरबेस कंसोल के प्रमाणीकरण अनुभाग से नए पासवर्ड-प्रमाणित उपयोगकर्ता भी बना सकते हैं।
वर्तमान में साइन-इन उपयोगकर्ता प्राप्त करें
ऑथ ऑब्जेक्ट पर श्रोता सेट करके वर्तमान उपयोगकर्ता प्राप्त करने का अनुशंसित तरीका है:
class MyAuthStateListener : public firebase::auth::AuthStateListener { public: void OnAuthStateChanged(firebase::auth::Auth* auth) override { firebase::auth::User user = auth->current_user(); if (user.is_valid()) { // User is signed in printf("OnAuthStateChanged: signed_in %s\n", user.uid().c_str()); } else { // User is signed out printf("OnAuthStateChanged: signed_out\n"); } // ... } }; // ... initialization code // Test notification on registration. MyAuthStateListener state_change_listener; auth->AddAuthStateListener(&state_change_listener);
एक श्रोता का उपयोग करके, आप यह सुनिश्चित करते हैं कि प्रामाणिक वस्तु एक मध्यवर्ती स्थिति में नहीं है - जैसे कि आरंभीकरण - जब आप वर्तमान उपयोगकर्ता प्राप्त करते हैं।
आप current_user
कॉल करके वर्तमान में साइन-इन किए गए उपयोगकर्ता को भी प्राप्त कर सकते हैं। यदि कोई उपयोगकर्ता साइन इन नहीं है, तो उपयोगकर्ता की is_valid
विधि गलत होगी।
उपयोगकर्ता की साख कायम रखें
उपयोगकर्ता के साइन इन करने के बाद उपयोगकर्ता के क्रेडेंशियल्स को स्थानीय कीस्टोर में संग्रहीत किया जाएगा। उपयोगकर्ता क्रेडेंशियल्स का स्थानीय कैश उपयोगकर्ता को साइन आउट करके हटाया जा सकता है। कीस्टोर प्लेटफ़ॉर्म विशिष्ट है:
- Apple प्लेटफ़ॉर्म: कीचेन सेवाएँ ।
- एंड्रॉइड: एंड्रॉइड कीस्टोर ।
- विंडोज: क्रेडेंशियल मैनेजमेंट एपीआई ।
- ओएस एक्स: किचेन सर्विसेज ।
- Linux: libsecret , जिसे उपयोक्ता ने अवश्य स्थापित किया होगा।
उपयोगकर्ता का प्रोफ़ाइल प्राप्त करें
उपयोगकर्ता की प्रोफ़ाइल जानकारी प्राप्त करने के लिए, firebase::auth::User
उदाहरण के एक्सेसर विधियों का उपयोग करें। उदाहरण के लिए:
firebase::auth::User user = auth->current_user(); if (user.is_valid()) { std::string name = user.display_name(); std::string email = user.email(); std::string photo_url = user.photo_url(); // 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 firebase::auth::User::Token() instead. std::string uid = user.uid(); }
उपयोगकर्ता की प्रदाता-विशिष्ट प्रोफ़ाइल जानकारी प्राप्त करें
किसी उपयोगकर्ता से जुड़े साइन-इन प्रदाताओं से प्रोफ़ाइल जानकारी प्राप्त करने के लिए, ProviderData
पद्धति का उपयोग करें। उदाहरण के लिए:
firebase::auth::User user = auth->current_user(); if (user.is_valid()) { for (auto it = user.provider_data().begin(); it != user.provider_data().end(); ++it) { firebase::auth::UserInfoInterface profile = *it; // Id of the provider (ex: google.com) std::string providerId = profile.provider_id(); // UID specific to the provider std::string uid = profile.uid(); // Name, email address, and profile photo Url std::string name = profile.display_name(); std::string email = profile.email(); std::string photoUrl = profile.photo_url(); } }
उपयोगकर्ता की प्रोफ़ाइल अपडेट करें
UpdateUserProfile
पद्धति से आप उपयोगकर्ता की मूलभूत प्रोफ़ाइल जानकारी—उपयोगकर्ता का प्रदर्शन नाम और प्रोफ़ाइल फ़ोटो URL—अपडेट कर सकते हैं. उदाहरण के लिए:
firebase::auth::User user = auth->current_user(); if (user.is_valid()) { firebase::auth::User::UserProfile profile; profile.display_name = "Jane Q. User"; profile.photo_url = "https://example.com/jane-q-user/profile.jpg"; user.UpdateUserProfile(profile).OnCompletion( [](const firebase::Future<void>& completed_future, void* user_data) { // We are probably in a different thread right now. if (completed_future.error() == 0) { printf("User profile updated."); } }, nullptr); // pass user_data here. }
उपयोगकर्ता का ईमेल पता सेट करें
आप UpdateEmail
पद्धति से उपयोगकर्ता का ईमेल पता सेट कर सकते हैं। उदाहरण के लिए:
firebase::auth::User user = auth->current_user(); if (user.is_valid()) { user.UpdateEmail("user@example.com") .OnCompletion( [](const firebase::Future<void>& completed_future, void* user_data) { // We are probably in a different thread right now. if (completed_future.error() == 0) { printf("User email address updated."); } }, nullptr); }
एक उपयोगकर्ता को एक सत्यापन ईमेल भेजें
आप SendEmailVerification
विधि के साथ किसी उपयोगकर्ता को पता सत्यापन ईमेल भेज सकते हैं। उदाहरण के लिए:
firebase::auth::User user = auth->current_user(); if (user.is_valid()) { user.SendEmailVerification().OnCompletion( [](const firebase::Future<void>& completed_future, void* user_data) { // We are probably in a different thread right now. if (completed_future.error() == 0) { printf("Email sent."); } }, nullptr); }
आप ईमेल टेम्पलेट पृष्ठ पर फायरबेस कंसोल के प्रमाणीकरण अनुभाग में उपयोग किए जाने वाले ईमेल टेम्पलेट को कस्टमाइज़ कर सकते हैं। Firebase सहायता केंद्र में ईमेल टेम्प्लेट देखें।
उपयोगकर्ता का पासवर्ड सेट करें
आप UpdatePassword
विधि से उपयोगकर्ता का पासवर्ड सेट कर सकते हैं। उदाहरण के लिए:
firebase::auth::User user = auth->current_user(); std::string newPassword = "SOME-SECURE-PASSWORD"; if (user.is_valid()) { user.UpdatePassword(newPassword.c_str()) .OnCompletion( [](const firebase::Future<void>& completed_future, void* user_data) { // We are probably in a different thread right now. if (completed_future.error() == 0) { printf("password updated."); } }, nullptr); }
एक पासवर्ड रीसेट ईमेल भेजें
आप SendPasswordResetEmail
पद्धति से उपयोगकर्ता को पासवर्ड रीसेट ईमेल भेज सकते हैं। उदाहरण के लिए:
std::string emailAddress = "user@example.com"; auth->SendPasswordResetEmail(emailAddress.c_str()) .OnCompletion( [](const firebase::Future<void>& completed_future, void* user_data) { // We are probably in a different thread right now. if (completed_future.error() == 0) { // Email sent. } else { // An error happened. printf("Error %d: %s", completed_future.error(), completed_future.error_message()); } }, nullptr);
आप ईमेल टेम्पलेट पृष्ठ पर फायरबेस कंसोल के प्रमाणीकरण अनुभाग में उपयोग किए जाने वाले ईमेल टेम्पलेट को कस्टमाइज़ कर सकते हैं। Firebase सहायता केंद्र में ईमेल टेम्प्लेट देखें।
आप फायरबेस कंसोल से पासवर्ड रीसेट ईमेल भी भेज सकते हैं।
एक उपयोगकर्ता हटाएं
आप Delete
मेथड से यूजर अकाउंट को डिलीट कर सकते हैं। उदाहरण के लिए:
firebase::auth::User user = auth->current_user(); if (user.is_valid()) { user.Delete().OnCompletion( [](const firebase::Future<void>& completed_future, void* user_data) { if (completed_future.error() == 0) { // User deleted. } else { // An error happened. printf("Error %d: %s", completed_future.error(), completed_future.error_message()); } }, nullptr); }
आप उपयोगकर्ता पृष्ठ पर Firebase कंसोल के प्रमाणीकरण अनुभाग से भी उपयोगकर्ताओं को हटा सकते हैं।
एक उपयोगकर्ता को फिर से प्रमाणित करें
कुछ सुरक्षा-संवेदनशील कार्रवाइयाँ—जैसे खाता हटाना , प्राथमिक ईमेल पता सेट करना और पासवर्ड बदलना —आवश्यक होता है कि उपयोगकर्ता ने हाल ही में साइन इन किया हो। कार्रवाई विफल।
जब ऐसा होता है, तो उपयोगकर्ता से नए साइन-इन क्रेडेंशियल्स प्राप्त करके और क्रेडेंशियल्स को Reauthenticate
के लिए पास करके उपयोगकर्ता को फिर से प्रमाणित करें। उदाहरण के लिए:
firebase::auth::User user = auth->current_user(); // Get auth credentials from the user for re-authentication. The example // below shows email and password credentials but there are multiple // possible providers, such as GoogleAuthProvider or FacebookAuthProvider. firebase::auth::Credential credential = firebase::auth::EmailAuthProvider::GetCredential("user@example.com", "password1234"); if (user.is_valid()) { user.Reauthenticate(credential) .OnCompletion( [](const firebase::Future<void>& completed_future, void* user_data) { if (completed_future.error() == 0) { printf("User re-authenticated."); } }, nullptr); }
उपयोगकर्ता खाते आयात करें
आप फायरबेस सीएलआई के auth:import
कमांड का उपयोग करके उपयोगकर्ता खातों को अपने फायरबेस प्रोजेक्ट में फ़ाइल से आयात कर सकते हैं। उदाहरण के लिए:
firebase auth:import users.json --hash-algo=scrypt --rounds=8 --mem-cost=14