ব্যবহারকারী তৈরি করা
নতুন ব্যবহারকারী তৈরি করার জন্য আপনার কাছে নিম্নলিখিত বিকল্প আছে:
আপনার অ্যাপ থেকে: Firebase প্রোজেক্টে
CreateUserWithEmailAndPasswordমেথড কল করে অথবা Google সাইন-ইন বা Facebook লগ-ইন-এর মতো ফেডারেটেড আইডেন্টিটি প্রদানকারী ব্যবহার করে প্রথমবার কোনও ব্যবহারকারীকে সাইন-ইন করানোর মাধ্যমে নতুন ব্যবহারকারী তৈরি করুন।Firebase কনসোলে: নিরাপত্তা > যাচাইকরণ > ব্যবহারকারী ট্যাব থেকে নতুন পাসওয়ার্ড-যাচাই করা ব্যবহারকারী তৈরি করুন।
বর্তমানে সাইন-ইন করা ব্যবহারকারীকে পাওয়া
বর্তমান ব্যবহারকারীকে পাওয়ার জন্য সাজেস্ট করা পদ্ধতি হল, 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 শূন্য মান রিটার্ন করবে। ব্যবহারকারী সাইন-আউট করে থাকলে,
ব্যবহারকারীর IsValid() false রিটার্ন করবে।
ব্যবহারকারীর ক্রেডেনশিয়াল সেভ করে রাখা
ব্যবহারকারী সাইন-ইন করার পরে, ব্যবহারকারীর ক্রেডেনশিয়াল স্থানীয় কীস্টোরে সেভ করা হবে। ব্যবহারকারীকে সাইন-আউট করে ব্যবহারকারীর ক্রেডেনশিয়ালের লোকাল ক্যাশে মুছে দেওয়া যায়। কীস্টোর প্ল্যাটফর্ম নির্দিষ্ট:
- Apple প্ল্যাটফর্ম: কীচেন পরিষেবা।
- Android: Android Keystore.
- Windows: Credential Management API.
- OS X: Keychain Services.
- Linux: libsecret, যা ব্যবহারকারীকে ইনস্টল করতে হবে।
ব্যবহারকারীর প্রোফাইল পাওয়া
ব্যবহারকারীর প্রোফাইল সংক্রান্ত তথ্য পেতে, 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 কনসোলের নিরাপত্তা > অনুমোদন > টেমপ্লেট ট্যাব থেকে কোন ইমেল টেমপ্লেট ব্যবহার করা হবে তা আপনি কাস্টমাইজ করতে পারবেন। 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 কনসোলের নিরাপত্তা > অনুমোদন > টেমপ্লেট ট্যাব থেকে কোন ইমেল টেমপ্লেট ব্যবহার করা হবে তা আপনি কাস্টমাইজ করতে পারবেন। 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 কনসোলে গিয়ে নিরাপত্তা > অনুমোদন > ব্যবহারকারী ট্যাব থেকে ব্যবহারকারীদের মুছে দিতে পারবেন।
ব্যবহারকারীকে আবার যাচাই করা
কিছু নিরাপত্তা-সংবেদনশীল অ্যাকশন—যেমন অ্যাকাউন্ট মুছে দেওয়া, প্রাইমারি ইমেল আইডি সেট করা এবং পাসওয়ার্ড পরিবর্তন করা—এর জন্য ব্যবহারকারীকে সম্প্রতি সাইন-ইন করতে হবে। আপনি যদি এইসব অ্যাকশনের মধ্যে একটি করেন এবং ব্যবহারকারী অনেক দিন আগে সাইন-ইন করে থাকেন, তাহলে অ্যাকশনটি সম্পূর্ণ হবে না।
এটি ঘটলে, ব্যবহারকারীর থেকে নতুন সাইন-ইন ক্রেডেনশিয়াল
নিয়ে এবং 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