ব্যবহারকারী তৈরি করা
নতুন ব্যবহারকারী তৈরি করার জন্য আপনার কাছে নিম্নলিখিত বিকল্প আছে:
আপনার অ্যাপ থেকে: Firebase প্রোজেক্টে
createUserWithEmailAndPasswordমেথড কল করে অথবা Google সাইন-ইন বা Facebook লগ-ইন-এর মতো ফেডারেটেড আইডেন্টিটি প্রদানকারী ব্যবহার করে প্রথমবার কোনও ব্যবহারকারীকে সাইন-ইন করানোর মাধ্যমে নতুন ব্যবহারকারী তৈরি করুন।Firebase কনসোলে: নিরাপত্তা > যাচাইকরণ > ব্যবহারকারী ট্যাব থেকে নতুন পাসওয়ার্ড-যাচাই করা ব্যবহারকারী তৈরি করুন।
বর্তমানে সাইন-ইন করা ব্যবহারকারীকে পাওয়া
বর্তমান ব্যবহারকারীকে পাওয়ার জন্য সাজেস্ট করা পদ্ধতি হল 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 হল নাল:
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 মেথড ব্যবহার করে কোনও ব্যবহারকারীর প্রাথমিক প্রোফাইল তথ্য—ব্যবহারকারীর ডিসপ্লে নাম
ও প্রোফাইল ফটো URL—আপডেট করতে পারবেন। যেমন:
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 কনসোলের নিরাপত্তা > অনুমোদন > টেমপ্লেট ট্যাব থেকে কোন ইমেল টেমপ্লেট ব্যবহার করা হবে তা আপনি কাস্টমাইজ করতে পারবেন। Firebase সহায়তা কেন্দ্রে ইমেল টেমপ্লেট দেখুন।
এছাড়াও, যাচাইকরণ ইমেল পাঠানোর সময় চালিয়ে যাওয়ার URL-এর মাধ্যমে স্টেট পাস করা সম্ভব, যাতে অ্যাপে রিডাইরেক্ট করা যায়।
এছাড়াও, ইমেল পাঠানোর আগে 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 কনসোলের নিরাপত্তা > অনুমোদন > টেমপ্লেট ট্যাব থেকে কোন ইমেল টেমপ্লেট ব্যবহার করা হবে তা আপনি কাস্টমাইজ করতে পারবেন। Firebase সহায়তা কেন্দ্রে ইমেল টেমপ্লেট দেখুন।
এছাড়াও, পাসওয়ার্ড রিসেট করার ইমেল পাঠানোর সময় চালিয়ে যাওয়ার URL-এর মাধ্যমে স্টেট পাস করা সম্ভব, যাতে অ্যাপে রিডাইরেক্ট করা যায়।
এছাড়াও, ইমেল পাঠানোর আগে 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 কনসোলে গিয়ে নিরাপত্তা > অনুমোদন > ব্যবহারকারী ট্যাব থেকে ব্যবহারকারীদের মুছে দিতে পারবেন।
ব্যবহারকারীকে আবার যাচাই করা
কিছু নিরাপত্তা-সংবেদনশীল অ্যাকশন—যেমন
অ্যাকাউন্ট মুছে দেওয়া,
প্রাইমারি ইমেল আইডি সেট করা এবং
পাসওয়ার্ড পরিবর্তন করা—এর জন্য ব্যবহারকারীকে
সম্প্রতি সাইন-ইন করতে হবে। আপনি যদি এইসব অ্যাকশনের মধ্যে একটি পারফর্ম করেন এবং ব্যবহারকারী
অনেক আগে সাইন-ইন করে থাকেন, তাহলে অ্যাকশনটি একটি সমস্যার কারণে সম্পূর্ণ করা যায় না।
এটি ঘটলে, ব্যবহারকারীর থেকে নতুন সাইন-ইন ক্রেডেনশিয়াল
নিয়ে এবং 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