একজন ব্যবহারকারী তৈরি করুন
নতুন ব্যবহারকারী তৈরি করার জন্য আপনার কাছে নিম্নলিখিত বিকল্পগুলো রয়েছে:
আপনার অ্যাপ থেকে : আপনার Firebase প্রজেক্টে
CreateUserWithEmailAndPasswordমেথডটি কল করে অথবা Google Sign-In বা Facebook Login-এর মতো কোনো ফেডারেটেড আইডেন্টিটি প্রোভাইডার ব্যবহার করে প্রথমবারের মতো কোনো ইউজারকে সাইন ইন করিয়ে একজন নতুন ইউজার তৈরি করুন।Firebase কনসোলে : Security > Authentication > Users ট্যাবে একটি নতুন পাসওয়ার্ড-প্রমাণিত ব্যবহারকারী তৈরি করুন।
বর্তমানে সাইন-ইন করা ব্যবহারকারীকে খুঁজুন
বর্তমান ব্যবহারকারীকে পাওয়ার প্রস্তাবিত উপায় হলো Auth অবজেক্টে একটি লিসেনার সেট করা:
Firebase.Auth.FirebaseAuth auth; Firebase.Auth.FirebaseUser user; // Handle initialization of the necessary firebase modules: void InitializeFirebase() { Debug.Log("Setting up Firebase Auth"); auth = Firebase.Auth.FirebaseAuth.DefaultInstance; auth.StateChanged += AuthStateChanged; AuthStateChanged(this, null); } // Track state changes of the auth object. void AuthStateChanged(object sender, System.EventArgs eventArgs) { if (auth.CurrentUser != user) { bool signedIn = user != auth.CurrentUser && auth.CurrentUser != null; if (!signedIn && user != null) { Debug.Log("Signed out " + user.UserId); } user = auth.CurrentUser; if (signedIn) { Debug.Log("Signed in " + user.UserId); } } } // Handle removing subscription and reference to the Auth instance. // Automatically called by a Monobehaviour after Destroy is called on it. void OnDestroy() { auth.StateChanged -= AuthStateChanged; auth = null; }
লিসেনার ব্যবহার করে আপনি নিশ্চিত করতে পারেন যে, বর্তমান ব্যবহারকারীকে পাওয়ার সময় Auth অবজেক্টটি কোনো মধ্যবর্তী অবস্থায়—যেমন প্রারম্ভিক অবস্থায়—থাকছে না।
আপনি CurrentUser কল করে বর্তমানে সাইন-ইন করা ব্যবহারকারীকেও পেতে পারেন। যদি কোনো ব্যবহারকারী সাইন-ইন করা না থাকে, তাহলে CurrentUser null রিটার্ন করবে। যদি কোনো ব্যবহারকারী সাইন-আউট করা থাকে, তাহলে তার IsValid() false রিটার্ন করবে।
ব্যবহারকারীর পরিচয়পত্র সংরক্ষণ করুন
ব্যবহারকারী সাইন ইন করার পর তার ক্রেডেনশিয়ালগুলো লোকাল কীস্টোরে সংরক্ষিত হবে। ব্যবহারকারীকে সাইন আউট করার মাধ্যমে তার ক্রেডেনশিয়ালের লোকাল ক্যাশ মুছে ফেলা যায়। কীস্টোরটি প্ল্যাটফর্ম-নির্দিষ্ট:
- অ্যাপল প্ল্যাটফর্ম: কীচেইন পরিষেবা ।
- অ্যান্ড্রয়েড: অ্যান্ড্রয়েড কীস্টোর ।
- উইন্ডোজ: ক্রেডেনশিয়াল ম্যানেজমেন্ট এপিআই ।
- OS X: কীচেইন পরিষেবা ।
- লিনাক্স: লিবসিক্রেট , যা ব্যবহারকারীকে অবশ্যই ইনস্টল করতে হবে।
একজন ব্যবহারকারীর প্রোফাইল পান
কোনো ব্যবহারকারীর প্রোফাইল তথ্য পেতে, Firebase.Auth.FirebaseUser এর কোনো ইনস্ট্যান্সের অ্যাক্সেসর মেথডগুলো ব্যবহার করুন। উদাহরণস্বরূপ:
Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { string name = user.DisplayName; string email = user.Email; System.Uri photo_url = user.PhotoUrl; // 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.TokenAsync() instead. string uid = user.UserId; }
ব্যবহারকারীর প্রদানকারী-নির্দিষ্ট প্রোফাইল তথ্য পান
কোনো ব্যবহারকারীর সাথে লিঙ্ক করা সাইন-ইন প্রোভাইডারগুলি থেকে সংগৃহীত প্রোফাইল তথ্য পেতে, ProviderData মেথডটি ব্যবহার করুন। উদাহরণস্বরূপ:
Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { foreach (var profile in user.ProviderData) { // Id of the provider (ex: google.com) string providerId = profile.ProviderId; // UID specific to the provider string uid = profile.UserId; // Name, email address, and profile photo Url string name = profile.DisplayName; string email = profile.Email; System.Uri photoUrl = profile.PhotoUrl; } }
একজন ব্যবহারকারীর প্রোফাইল আপডেট করুন
আপনি UpdateUserProfile মেথড ব্যবহার করে একজন ব্যবহারকারীর মৌলিক প্রোফাইল তথ্য—যেমন তার প্রদর্শিত নাম এবং প্রোফাইল ফটোর URL—আপডেট করতে পারেন। উদাহরণস্বরূপ:
Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { Firebase.Auth.UserProfile profile = new Firebase.Auth.UserProfile { DisplayName = "Jane Q. User", PhotoUrl = new System.Uri("https://example.com/jane-q-user/profile.jpg"), }; user.UpdateUserProfileAsync(profile).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("UpdateUserProfileAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("UpdateUserProfileAsync encountered an error: " + task.Exception); return; } Debug.Log("User profile updated successfully."); }); }
একজন ব্যবহারকারীর ইমেল ঠিকানা সেট করুন
আপনি UpdateEmail মেথড ব্যবহার করে একজন ব্যবহারকারীর ইমেল ঠিকানা সেট করতে পারেন। উদাহরণস্বরূপ:
Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { user.UpdateEmailAsync("user@example.com").ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("UpdateEmailAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("UpdateEmailAsync encountered an error: " + task.Exception); return; } Debug.Log("User email updated successfully."); }); }
একজন ব্যবহারকারীকে একটি যাচাইকরণ ইমেল পাঠান
আপনি SendEmailVerification মেথড ব্যবহার করে কোনো ব্যবহারকারীকে ঠিকানা যাচাইকরণের ইমেল পাঠাতে পারেন। উদাহরণস্বরূপ:
Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { user.SendEmailVerificationAsync().ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SendEmailVerificationAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SendEmailVerificationAsync encountered an error: " + task.Exception); return; } Debug.Log("Email sent successfully."); }); }
আপনি Firebase কনসোলের Security > Authentication > Templates ট্যাবে কোন ইমেল টেমপ্লেট ব্যবহার করা হবে তা কাস্টমাইজ করতে পারেন। Firebase হেল্প সেন্টারে ইমেল টেমপ্লেট দেখুন।
ব্যবহারকারীর পাসওয়ার্ড সেট করুন
আপনি UpdatePassword মেথড ব্যবহার করে একজন ব্যবহারকারীর পাসওয়ার্ড সেট করতে পারেন। উদাহরণস্বরূপ:
Firebase.Auth.FirebaseUser user = auth.CurrentUser; string newPassword = "SOME-SECURE-PASSWORD"; if (user != null) { user.UpdatePasswordAsync(newPassword).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("UpdatePasswordAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("UpdatePasswordAsync encountered an error: " + task.Exception); return; } Debug.Log("Password updated successfully."); }); }
পাসওয়ার্ড রিসেট করার জন্য একটি ইমেল পাঠান
আপনি SendPasswordResetEmail মেথড ব্যবহার করে কোনো ব্যবহারকারীকে পাসওয়ার্ড রিসেট ইমেল পাঠাতে পারেন। উদাহরণস্বরূপ:
string emailAddress = "user@example.com"; if (user != null) { auth.SendPasswordResetEmailAsync(emailAddress).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SendPasswordResetEmailAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SendPasswordResetEmailAsync encountered an error: " + task.Exception); return; } Debug.Log("Password reset email sent successfully."); }); }
আপনি Firebase কনসোলের Security > Authentication > Templates ট্যাবে কোন ইমেল টেমপ্লেট ব্যবহার করা হবে তা কাস্টমাইজ করতে পারেন। Firebase হেল্প সেন্টারে ইমেল টেমপ্লেট দেখুন।
আপনি Firebase কনসোল থেকেও পাসওয়ার্ড রিসেট ইমেল পাঠাতে পারেন।
একজন ব্যবহারকারীকে মুছে ফেলুন
আপনি Delete পদ্ধতি ব্যবহার করে একটি ব্যবহারকারী অ্যাকাউন্ট মুছে ফেলতে পারেন। উদাহরণস্বরূপ:
Firebase.Auth.FirebaseUser user = auth.CurrentUser; if (user != null) { user.DeleteAsync().ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("DeleteAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("DeleteAsync encountered an error: " + task.Exception); return; } Debug.Log("User deleted successfully."); }); }
এছাড়াও আপনি Firebase কনসোলের Security > Authentication > Users ট্যাব থেকে ব্যবহারকারীদের মুছে ফেলতে পারেন।
একজন ব্যবহারকারীকে পুনরায় প্রমাণীকরণ করুন
কিছু নিরাপত্তামূলক কাজ—যেমন অ্যাকাউন্ট মুছে ফেলা , প্রাথমিক ইমেল ঠিকানা সেট করা এবং পাসওয়ার্ড পরিবর্তন করা —করার জন্য ব্যবহারকারীকে সম্প্রতি সাইন ইন করতে হয়। আপনি যদি এই কাজগুলোর মধ্যে কোনো একটি করেন এবং ব্যবহারকারী অনেক আগে সাইন ইন করে থাকেন, তাহলে কাজটি ব্যর্থ হয়।
যখন এমনটা ঘটে, তখন ব্যবহারকারীর কাছ থেকে নতুন সাইন-ইন ক্রেডেনশিয়াল নিয়ে এবং সেই ক্রেডেনশিয়ালগুলো Reauthenticate এ পাঠিয়ে ব্যবহারকারীকে পুনরায় প্রমাণীকরণ করুন। উদাহরণস্বরূপ:
Firebase.Auth.FirebaseUser user = auth.CurrentUser; // 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 != null) { user.ReauthenticateAsync(credential).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("ReauthenticateAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("ReauthenticateAsync encountered an error: " + task.Exception); return; } Debug.Log("User reauthenticated successfully."); }); }
ব্যবহারকারী অ্যাকাউন্ট আমদানি করুন
আপনি Firebase CLI-এর auth:import কমান্ড ব্যবহার করে একটি ফাইল থেকে আপনার Firebase প্রজেক্টে ইউজার অ্যাকাউন্ট ইম্পোর্ট করতে পারেন। উদাহরণস্বরূপ:
firebase auth:import users.json --hash-algo=scrypt --rounds=8 --mem-cost=14