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

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

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

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

  • Firebase কনসোলে : Security > Authentication > Users ট্যাবে একটি নতুন পাসওয়ার্ড-প্রমাণিত ব্যবহারকারী তৈরি করুন।

বর্তমানে সাইন-ইন করা ব্যবহারকারীকে খুঁজুন

বর্তমান ব্যবহারকারীকে পাওয়ার প্রস্তাবিত উপায় হলো Auth অবজেক্টে একটি অবজারভার সেট করা:

Web

import { getAuth, onAuthStateChanged } from "firebase/auth";

const auth = getAuth();
onAuthStateChanged(auth, (user) => {
  if (user) {
    // User is signed in, see docs for a list of available properties
    // https://firebase.google.com/docs/reference/js/auth.user
    const uid = user.uid;
    // ...
  } else {
    // User is signed out
    // ...
  }
});

Web

firebase.auth().onAuthStateChanged((user) => {
  if (user) {
    // User is signed in, see docs for a list of available properties
    // https://firebase.google.com/docs/reference/js/v8/firebase.User
    var uid = user.uid;
    // ...
  } else {
    // User is signed out
    // ...
  }
});

একটি অবজারভার ব্যবহার করে আপনি নিশ্চিত করেন যে, বর্তমান ব্যবহারকারীকে পাওয়ার সময় Auth অবজেক্টটি কোনো মধ্যবর্তী অবস্থায়—যেমন ইনিশিয়ালাইজেশন—থাকছে না। যখন আপনি signInWithRedirect ব্যবহার করেন, তখন onAuthStateChanged অবজারভারটি ট্রিগার হওয়ার আগে getRedirectResult রিজলভ হওয়া পর্যন্ত অপেক্ষা করে।

আপনি ` currentUser প্রপার্টি ব্যবহার করে বর্তমানে সাইন-ইন করা ব্যবহারকারীকেও পেতে পারেন। যদি কোনো ব্যবহারকারী সাইন-ইন করা না থাকে, তাহলে currentUser `null` হয়।

Web

import { getAuth } from "firebase/auth";

const auth = getAuth();
const user = auth.currentUser;

if (user) {
  // User is signed in, see docs for a list of available properties
  // https://firebase.google.com/docs/reference/js/auth.user
  // ...
} else {
  // No user is signed in.
}

Web

const user = firebase.auth().currentUser;

if (user) {
  // User is signed in, see docs for a list of available properties
  // https://firebase.google.com/docs/reference/js/v8/firebase.User
  // ...
} else {
  // No user is signed in.
}

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

কোনো ব্যবহারকারীর প্রোফাইল তথ্য পেতে, User ইনস্ট্যান্সের প্রোপার্টিগুলো ব্যবহার করুন। উদাহরণস্বরূপ:

Web

import { getAuth } from "firebase/auth";

const auth = getAuth();
const user = auth.currentUser;
if (user !== null) {
  // The user object has basic properties such as display name, email, etc.
  const displayName = user.displayName;
  const email = user.email;
  const photoURL = user.photoURL;
  const emailVerified = user.emailVerified;

  // 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.getToken() instead.
  const uid = user.uid;
}

Web

const user = firebase.auth().currentUser;
if (user !== null) {
  // The user object has basic properties such as display name, email, etc.
  const displayName = user.displayName;
  const email = user.email;
  const photoURL = user.photoURL;
  const emailVerified = user.emailVerified;

  // 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.getIdToken() instead.
  const uid = user.uid;
}

ব্যবহারকারীর প্রদানকারী-নির্দিষ্ট প্রোফাইল তথ্য পান

কোনো ব্যবহারকারীর সাথে লিঙ্ক করা সাইন-ইন প্রোভাইডারগুলি থেকে প্রাপ্ত প্রোফাইল তথ্য পেতে, providerData প্রপার্টিটি ব্যবহার করুন। উদাহরণস্বরূপ:

Web

import { getAuth } from "firebase/auth";

const auth = getAuth();
const user = auth.currentUser;

if (user !== null) {
  user.providerData.forEach((profile) => {
    console.log("Sign-in provider: " + profile.providerId);
    console.log("  Provider-specific UID: " + profile.uid);
    console.log("  Name: " + profile.displayName);
    console.log("  Email: " + profile.email);
    console.log("  Photo URL: " + profile.photoURL);
  });
}

Web

const user = firebase.auth().currentUser;

if (user !== null) {
  user.providerData.forEach((profile) => {
    console.log("Sign-in provider: " + profile.providerId);
    console.log("  Provider-specific UID: " + profile.uid);
    console.log("  Name: " + profile.displayName);
    console.log("  Email: " + profile.email);
    console.log("  Photo URL: " + profile.photoURL);
  });
}

একজন ব্যবহারকারীর প্রোফাইল আপডেট করুন

আপনি updateProfile মেথড ব্যবহার করে একজন ব্যবহারকারীর মৌলিক প্রোফাইল তথ্য—যেমন তার প্রদর্শিত নাম এবং প্রোফাইল ফটোর ইউআরএল—আপডেট করতে পারেন। উদাহরণস্বরূপ:

Web

import { getAuth, updateProfile } from "firebase/auth";
const auth = getAuth();
updateProfile(auth.currentUser, {
  displayName: "Jane Q. User", photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(() => {
  // Profile updated!
  // ...
}).catch((error) => {
  // An error occurred
  // ...
});

Web

const user = firebase.auth().currentUser;

user.updateProfile({
  displayName: "Jane Q. User",
  photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(() => {
  // Update successful
  // ...
}).catch((error) => {
  // An error occurred
  // ...
});  

একজন ব্যবহারকারীর ইমেল ঠিকানা সেট করুন

আপনি ` updateEmail মেথড ব্যবহার করে একজন ব্যবহারকারীর ইমেল ঠিকানা সেট করতে পারেন। উদাহরণস্বরূপ:

Web

import { getAuth, updateEmail } from "firebase/auth";
const auth = getAuth();
updateEmail(auth.currentUser, "user@example.com").then(() => {
  // Email updated!
  // ...
}).catch((error) => {
  // An error occurred
  // ...
});

Web

const user = firebase.auth().currentUser;

user.updateEmail("user@example.com").then(() => {
  // Update successful
  // ...
}).catch((error) => {
  // An error occurred
  // ...
});

একজন ব্যবহারকারীকে একটি যাচাইকরণ ইমেল পাঠান

আপনি sendEmailVerification মেথড ব্যবহার করে কোনো ব্যবহারকারীকে ঠিকানা যাচাইকরণের ইমেল পাঠাতে পারেন। উদাহরণস্বরূপ:

Web

import { getAuth, sendEmailVerification } from "firebase/auth";

const auth = getAuth();
sendEmailVerification(auth.currentUser)
  .then(() => {
    // Email verification sent!
    // ...
  });

Web

firebase.auth().currentUser.sendEmailVerification()
  .then(() => {
    // Email verification sent!
    // ...
  });

আপনি Firebase কনসোলের Security > Authentication > Templates ট্যাবে কোন ইমেল টেমপ্লেট ব্যবহার করা হবে তা কাস্টমাইজ করতে পারেন। Firebase হেল্প সেন্টারে ইমেল টেমপ্লেট দেখুন।

ভেরিফিকেশন ইমেল পাঠানোর সময় অ্যাপে রিডাইরেক্ট করার জন্য একটি কন্টিনিউ ইউআরএল-এর মাধ্যমে স্টেট পাস করাও সম্ভব।

এছাড়াও, ইমেল পাঠানোর আগে Auth ইনস্ট্যান্সে ল্যাঙ্গুয়েজ কোড আপডেট করে আপনি ভেরিফিকেশন ইমেলটিকে স্থানীয়করণ করতে পারেন। উদাহরণস্বরূপ:

Web

import { getAuth } from "firebase/auth";

const auth = getAuth();
auth.languageCode = 'it';
// To apply the default browser preference instead of explicitly setting it.
// auth.useDeviceLanguage();

Web

firebase.auth().languageCode = 'it';
// To apply the default browser preference instead of explicitly setting it.
// firebase.auth().useDeviceLanguage();

ব্যবহারকারীর পাসওয়ার্ড সেট করুন

আপনি updatePassword মেথড ব্যবহার করে একজন ব্যবহারকারীর পাসওয়ার্ড সেট করতে পারেন। উদাহরণস্বরূপ:

Web

import { getAuth, updatePassword } from "firebase/auth";

const auth = getAuth();

const user = auth.currentUser;
const newPassword = getASecureRandomPassword();

updatePassword(user, newPassword).then(() => {
  // Update successful.
}).catch((error) => {
  // An error ocurred
  // ...
});

Web

const user = firebase.auth().currentUser;
const newPassword = getASecureRandomPassword();

user.updatePassword(newPassword).then(() => {
  // Update successful.
}).catch((error) => {
  // An error ocurred
  // ...
});

পাসওয়ার্ড রিসেট করার জন্য একটি ইমেল পাঠান

আপনি sendPasswordResetEmail মেথড ব্যবহার করে কোনো ব্যবহারকারীকে পাসওয়ার্ড রিসেট করার ইমেল পাঠাতে পারেন। উদাহরণস্বরূপ:

Web

import { getAuth, sendPasswordResetEmail } from "firebase/auth";

const auth = getAuth();
sendPasswordResetEmail(auth, email)
  .then(() => {
    // Password reset email sent!
    // ..
  })
  .catch((error) => {
    const errorCode = error.code;
    const errorMessage = error.message;
    // ..
  });

Web

firebase.auth().sendPasswordResetEmail(email)
  .then(() => {
    // Password reset email sent!
    // ..
  })
  .catch((error) => {
    var errorCode = error.code;
    var errorMessage = error.message;
    // ..
  });

আপনি Firebase কনসোলের Security > Authentication > Templates ট্যাবে কোন ইমেল টেমপ্লেট ব্যবহার করা হবে তা কাস্টমাইজ করতে পারেন। Firebase হেল্প সেন্টারে ইমেল টেমপ্লেট দেখুন।

পাসওয়ার্ড রিসেট ইমেল পাঠানোর সময় অ্যাপে ফিরিয়ে আনার জন্য একটি কন্টিনিউ ইউআরএল- এর মাধ্যমে স্টেট পাস করাও সম্ভব।

এছাড়াও, ইমেল পাঠানোর আগে Auth ইনস্ট্যান্সে ল্যাঙ্গুয়েজ কোড আপডেট করে আপনি পাসওয়ার্ড রিসেট ইমেলটি স্থানীয়করণ করতে পারেন। উদাহরণস্বরূপ:

Web

import { getAuth } from "firebase/auth";

const auth = getAuth();
auth.languageCode = 'it';
// To apply the default browser preference instead of explicitly setting it.
// auth.useDeviceLanguage();

Web

firebase.auth().languageCode = 'it';
// To apply the default browser preference instead of explicitly setting it.
// firebase.auth().useDeviceLanguage();

আপনি Firebase কনসোল থেকেও পাসওয়ার্ড রিসেট ইমেল পাঠাতে পারেন।

একজন ব্যবহারকারীকে মুছে ফেলুন

আপনি delete পদ্ধতি ব্যবহার করে একটি ব্যবহারকারী অ্যাকাউন্ট মুছে ফেলতে পারেন। উদাহরণস্বরূপ:

Web

import { getAuth, deleteUser } from "firebase/auth";

const auth = getAuth();
const user = auth.currentUser;

deleteUser(user).then(() => {
  // User deleted.
}).catch((error) => {
  // An error ocurred
  // ...
});

Web

const user = firebase.auth().currentUser;

user.delete().then(() => {
  // User deleted.
}).catch((error) => {
  // An error ocurred
  // ...
});

এছাড়াও আপনি Firebase কনসোলের Security > Authentication > Users ট্যাব থেকে ব্যবহারকারীদের মুছে ফেলতে পারেন।

একজন ব্যবহারকারীকে পুনরায় প্রমাণীকরণ করুন

কিছু নিরাপত্তা-সংবেদনশীল কাজ—যেমন অ্যাকাউন্ট মুছে ফেলা , প্রাথমিক ইমেল ঠিকানা সেট করা এবং পাসওয়ার্ড পরিবর্তন করা —এর জন্য ব্যবহারকারীকে সম্প্রতি সাইন ইন করতে হয়। আপনি যদি এই কাজগুলোর মধ্যে কোনো একটি করেন এবং ব্যবহারকারী অনেক দিন আগে সাইন ইন করে থাকেন, তাহলে কাজটি একটি ত্রুটির সাথে ব্যর্থ হয়। এমনটি ঘটলে, ব্যবহারকারীর কাছ থেকে নতুন সাইন-ইন ক্রেডেনশিয়াল নিয়ে এবং সেই ক্রেডেনশিয়ালগুলো reauthenticateWithCredential এ পাস করে ব্যবহারকারীকে পুনরায় প্রমাণীকরণ করুন। উদাহরণস্বরূপ:

Web

import { getAuth, reauthenticateWithCredential } from "firebase/auth";

const auth = getAuth();
const user = auth.currentUser;

// TODO(you): prompt the user to re-provide their sign-in credentials
const credential = promptForCredentials();

reauthenticateWithCredential(user, credential).then(() => {
  // User re-authenticated.
}).catch((error) => {
  // An error ocurred
  // ...
});

Web

const user = firebase.auth().currentUser;

// TODO(you): prompt the user to re-provide their sign-in credentials
const credential = promptForCredentials();

user.reauthenticateWithCredential(credential).then(() => {
  // User re-authenticated.
}).catch((error) => {
  // An error occurred
  // ...
});

ব্যবহারকারী অ্যাকাউন্ট আমদানি করুন

আপনি Firebase CLI-এর auth:import কমান্ড ব্যবহার করে একটি ফাইল থেকে আপনার Firebase প্রজেক্টে ইউজার অ্যাকাউন্ট ইম্পোর্ট করতে পারেন। উদাহরণস্বরূপ:

firebase auth:import users.json --hash-algo=scrypt --rounds=8 --mem-cost=14