Firebase-এ ব্যবহারকারীদের পরিচালনা করুন

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

আপনি CreateUserWithEmailAndPassword পদ্ধতিতে কল করার মাধ্যমে অথবা Google সাইন-ইন বা Facebook লগইন- এর মতো ফেডারেটেড আইডেন্টিটি প্রদানকারী ব্যবহার করে প্রথমবার একজন ব্যবহারকারীকে সাইন ইন করার মাধ্যমে আপনার 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() মিথ্যা ফিরে আসবে।

ব্যবহারকারীর শংসাপত্র বজায় রাখুন

ব্যবহারকারী সাইন ইন করার পরে ব্যবহারকারীর শংসাপত্রগুলি স্থানীয় কীস্টোরে সংরক্ষণ করা হবে৷ ব্যবহারকারীকে সাইন আউট করার মাধ্যমে ব্যবহারকারীর শংসাপত্রের স্থানীয় ক্যাশে মুছে ফেলা যেতে পারে৷ কীস্টোরটি প্ল্যাটফর্ম নির্দিষ্ট:

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

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