Firebase-এ ব্যবহারকারীদের ম্যানেজ করা

ব্যবহারকারী তৈরি করুন

নতুন ব্যবহারকারী তৈরি করার জন্য আপনার কাছে নিম্নলিখিত বিকল্পগুলি রয়েছে:

  • আপনার অ্যাপ থেকে: CreateUserWithEmailAndPassword মেথড কল করে অথবা Google Sign-In বা Facebook Login-এর মতো ফেডারেটেড পরিচয় প্রদানকারী ব্যবহার করে প্রথমবার কোনও ব্যবহারকারীকে সাইন-ইন করিয়ে আপনার Firebase প্রোজেক্টে নতুন ব্যবহারকারী তৈরি করুন।

  • 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 রিটার্ন করবে।

ব্যবহারকারীর ক্রেডেনশিয়াল সেভ করে রাখা

ব্যবহারকারী সাইন-ইন করার পরে তার ক্রেডেনশিয়াল স্থানীয় কীস্টোরে স্টোর করা হবে। ব্যবহারকারীকে সাইন-আউট করে ব্যবহারকারীর ক্রেডেনশিয়ালের স্থানীয় ক্যাশে মুছে ফেলা যেতে পারে। কীস্টোরটি প্ল্যাটফর্ম নির্দিষ্ট:

ব্যবহারকারীর প্রোফাইল পান

ব্যবহারকারীর প্রোফাইল সংক্রান্ত তথ্য পেতে, 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