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

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

আপনি createUserWithEmailAndPassword পদ্ধতিতে কল করে অথবা Google সাইন-ইন বা Facebook লগইন- এর মতো ফেডারেটেড আইডেন্টিটি প্রদানকারী ব্যবহার করে প্রথমবার কোনো ব্যবহারকারীকে সাইন ইন করার মাধ্যমে আপনার ফায়ারবেস প্রকল্পে একজন নতুন ব্যবহারকারী তৈরি করেন।

আপনি Firebase কনসোলের প্রমাণীকরণ বিভাগ থেকে, ব্যবহারকারী পৃষ্ঠায় বা অ্যাডমিন SDK ব্যবহার করে নতুন পাসওয়ার্ড-প্রমাণিত ব্যবহারকারী তৈরি করতে পারেন।

বর্তমানে সাইন ইন করা ব্যবহারকারী পান

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

Web modular API

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 namespaced API

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 শূন্য:

Web modular API

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 namespaced API

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 modular API

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 namespaced API

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 modular API

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 namespaced API

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 পদ্ধতির মাধ্যমে ব্যবহারকারীর মৌলিক প্রোফাইল তথ্য-ব্যবহারকারীর প্রদর্শন নাম এবং প্রোফাইল ফটো URL- আপডেট করতে পারেন। উদাহরণ স্বরূপ:

Web modular API

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 namespaced API

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 modular API

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

Web namespaced API

const user = firebase.auth().currentUser;

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

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

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

Web modular API

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

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

Web namespaced API

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

আপনি Firebase কনসোলের প্রমাণীকরণ বিভাগে ব্যবহৃত ইমেল টেমপ্লেটটি কাস্টমাইজ করতে পারেন, ইমেল টেমপ্লেট পৃষ্ঠায়। Firebase সহায়তা কেন্দ্রে ইমেল টেমপ্লেট দেখুন।

একটি যাচাইকরণ ইমেল পাঠানোর সময় অ্যাপে পুনঃনির্দেশিত করতে একটি অবিরত URL এর মাধ্যমে রাজ্য পাস করাও সম্ভব।

উপরন্তু আপনি ইমেল পাঠানোর আগে Auth উদাহরণে ভাষা কোড আপডেট করে যাচাইকরণ ইমেল স্থানীয়করণ করতে পারেন। উদাহরণ স্বরূপ:

Web modular API

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 namespaced API

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

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

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

Web modular API

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 namespaced API

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

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

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

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

Web modular API

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 namespaced API

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

আপনি Firebase কনসোলের প্রমাণীকরণ বিভাগে ব্যবহৃত ইমেল টেমপ্লেটটি কাস্টমাইজ করতে পারেন, ইমেল টেমপ্লেট পৃষ্ঠায়। Firebase সহায়তা কেন্দ্রে ইমেল টেমপ্লেট দেখুন।

পাসওয়ার্ড রিসেট ইমেল পাঠানোর সময় অ্যাপ্লিকেশানে পুনঃনির্দেশিত করতে একটি অবিরত URL এর মাধ্যমে রাজ্য পাস করাও সম্ভব।

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

Web modular API

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 namespaced API

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

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

একটি ব্যবহারকারী মুছুন

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

Web modular API

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

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

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

Web namespaced API

const user = firebase.auth().currentUser;

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

এছাড়াও আপনি ব্যবহারকারীদের পৃষ্ঠায় Firebase কনসোলের প্রমাণীকরণ বিভাগ থেকে ব্যবহারকারীদের মুছতে পারেন।

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

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

Web modular API

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 namespaced API

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