কাস্টম ইমেল অ্যাকশন হ্যান্ডলার তৈরি করুন

ব্যবহারকারীর ইমেল ঠিকানা আপডেট করা এবং ব্যবহারকারীর পাসওয়ার্ড রিসেট করার মতো কিছু ব্যবহারকারী ব্যবস্থাপনার কাজ, যার ফলে ব্যবহারকারীকে ইমেল পাঠানো হয়। এই ইমেলগুলিতে এমন লিঙ্ক রয়েছে যা প্রাপকরা ব্যবহারকারী পরিচালনার ক্রিয়া সম্পূর্ণ বা বাতিল করতে খুলতে পারে। ডিফল্টরূপে, ব্যবহারকারী ব্যবস্থাপনা ইমেলগুলি ডিফল্ট অ্যাকশন হ্যান্ডলারের সাথে লিঙ্ক করে, যা আপনার প্রকল্পের Firebase হোস্টিং ডোমেনের একটি URL-এ হোস্ট করা একটি ওয়েব পৃষ্ঠা।

আপনি পরিবর্তে কাস্টম প্রসেসিং করতে এবং আপনার ওয়েবসাইটের সাথে ইমেল অ্যাকশন হ্যান্ডলারকে সংহত করতে একটি কাস্টম ইমেল অ্যাকশন হ্যান্ডলার তৈরি এবং হোস্ট করতে পারেন।

নিম্নলিখিত ব্যবহারকারী ব্যবস্থাপনা কর্মের জন্য ব্যবহারকারীকে একটি ইমেল অ্যাকশন হ্যান্ডলার ব্যবহার করে কাজটি সম্পূর্ণ করতে হবে:

  • পাসওয়ার্ড রিসেট করা হচ্ছে
  • ইমেল ঠিকানার পরিবর্তনগুলি প্রত্যাহার করা হচ্ছে—যখন ব্যবহারকারীরা তাদের অ্যাকাউন্টের প্রাথমিক ইমেল ঠিকানাগুলি পরিবর্তন করেন, তখন Firebase তাদের পুরানো ঠিকানাগুলিতে একটি ইমেল পাঠায় যা তাদের পরিবর্তনকে পূর্বাবস্থায় ফেরাতে দেয়
  • ইমেল ঠিকানা যাচাই করা হচ্ছে

আপনার Firebase প্রকল্পের ইমেল অ্যাকশন হ্যান্ডলার কাস্টমাইজ করতে, আপনাকে অবশ্যই একটি ওয়েব পৃষ্ঠা তৈরি এবং হোস্ট করতে হবে যা অনুরোধের বৈধতা যাচাই করতে এবং অনুরোধটি সম্পূর্ণ করতে Firebase JavaScript SDK ব্যবহার করে। তারপর, আপনার কাস্টম অ্যাকশন হ্যান্ডলারের সাথে লিঙ্ক করতে আপনাকে অবশ্যই আপনার Firebase প্রকল্পের ইমেল টেমপ্লেটগুলি কাস্টমাইজ করতে হবে।

ইমেল অ্যাকশন হ্যান্ডলার পৃষ্ঠা তৈরি করুন

  1. Firebase আপনার অ্যাকশন হ্যান্ডলার ইউআরএলে বেশ কিছু ক্যোয়ারী প্যারামিটার যোগ করে যখন এটি ইউজার ম্যানেজমেন্ট ইমেল তৈরি করে। যেমন:

    https://example.com/usermgmt?mode=resetPassword&oobCode=ABC123&apiKey=AIzaSy...&lang=fr

    এই পরামিতিগুলি ব্যবহারকারী পরিচালনার কাজটি নির্দিষ্ট করে যা ব্যবহারকারী সম্পূর্ণ করছে। আপনার ইমেল অ্যাকশন হ্যান্ডলার পৃষ্ঠাকে অবশ্যই নিম্নলিখিত ক্যোয়ারী প্যারামিটারগুলি পরিচালনা করতে হবে:

    পরামিতি
    মোড

    ব্যবহারকারী ব্যবস্থাপনা কর্ম সম্পূর্ণ করা হবে. নিম্নলিখিত মানগুলির মধ্যে একটি হতে পারে:

    • resetPassword
    • recoverEmail
    • verifyEmail
    oobCode একটি এককালীন কোড, একটি অনুরোধ সনাক্ত করতে এবং যাচাই করতে ব্যবহৃত হয়
    apiKey আপনার ফায়ারবেস প্রকল্পের API কী, সুবিধার জন্য প্রদান করা হয়েছে
    continueUrl এটি একটি ঐচ্ছিক URL যেটি একটি URL এর মাধ্যমে অ্যাপ্লিকেশানে রাজ্যটি ফেরত দেওয়ার একটি উপায় প্রদান করে৷ এটি পাসওয়ার্ড রিসেট এবং ইমেল যাচাইকরণ মোডগুলির সাথে প্রাসঙ্গিক৷ একটি পাসওয়ার্ড রিসেট ইমেল বা যাচাইকরণ ইমেল পাঠানোর সময়, এটি উপলব্ধ হওয়ার জন্য একটি ActionCodeSettings অবজেক্টকে একটি অবিরত URL সহ নির্দিষ্ট করতে হবে৷ এটি একটি ব্যবহারকারীর পক্ষে ইমেল অ্যাকশনের পরে যেখানে তারা ছেড়েছিল ঠিক সেখানেই চালিয়ে যাওয়া সম্ভব করে তোলে।
    lang

    এটি হল ঐচ্ছিক BCP47 ভাষা ট্যাগ যা ব্যবহারকারীর লোকেলকে প্রতিনিধিত্ব করে (উদাহরণস্বরূপ, fr )। আপনি আপনার ব্যবহারকারীদের স্থানীয় ইমেল অ্যাকশন হ্যান্ডলার পৃষ্ঠাগুলি প্রদান করতে এই মানটি ব্যবহার করতে পারেন।

    স্থানীয়করণ Firebase কনসোলের মাধ্যমে বা গতিশীলভাবে ইমেল অ্যাকশন ট্রিগার করার আগে সংশ্লিষ্ট ক্লায়েন্ট API-কে কল করে সেট করা যেতে পারে। উদাহরণস্বরূপ, জাভাস্ক্রিপ্ট ব্যবহার করে: firebase.auth().languageCode = 'fr'; .

    সামঞ্জস্যপূর্ণ ব্যবহারকারীর অভিজ্ঞতার জন্য, নিশ্চিত করুন যে ইমেল অ্যাকশন হ্যান্ডলার স্থানীয়করণ ইমেল টেমপ্লেটের সাথে মেলে।

    নিম্নলিখিত উদাহরণটি দেখায় যে আপনি কীভাবে ব্রাউজার ভিত্তিক হ্যান্ডলারে ক্যোয়ারী প্যারামিটারগুলি পরিচালনা করতে পারেন। (আপনি অনুরূপ যুক্তি ব্যবহার করে একটি Node.js অ্যাপ্লিকেশন হিসাবে হ্যান্ডলার প্রয়োগ করতে পারেন।)

    Web modular API

    import { initializeApp } from "firebase/app";
    import { getAuth } from "firebase/auth";
    
    document.addEventListener('DOMContentLoaded', () => {
      // TODO: Implement getParameterByName()
    
      // Get the action to complete.
      const mode = getParameterByName('mode');
      // Get the one-time code from the query parameter.
      const actionCode = getParameterByName('oobCode');
      // (Optional) Get the continue URL from the query parameter if available.
      const continueUrl = getParameterByName('continueUrl');
      // (Optional) Get the language code if available.
      const lang = getParameterByName('lang') || 'en';
    
      // Configure the Firebase SDK.
      // This is the minimum configuration required for the API to be used.
      const config = {
        'apiKey': "YOUR_API_KEY" // Copy this key from the web initialization
                                 // snippet found in the Firebase console.
      };
      const app = initializeApp(config);
      const auth = getAuth(app);
    
      // Handle the user management action.
      switch (mode) {
        case 'resetPassword':
          // Display reset password handler and UI.
          handleResetPassword(auth, actionCode, continueUrl, lang);
          break;
        case 'recoverEmail':
          // Display email recovery handler and UI.
          handleRecoverEmail(auth, actionCode, lang);
          break;
        case 'verifyEmail':
          // Display email verification handler and UI.
          handleVerifyEmail(auth, actionCode, continueUrl, lang);
          break;
        default:
          // Error: invalid mode.
      }
    }, false);

    Web namespaced API

    document.addEventListener('DOMContentLoaded', () => {
      // TODO: Implement getParameterByName()
    
      // Get the action to complete.
      var mode = getParameterByName('mode');
      // Get the one-time code from the query parameter.
      var actionCode = getParameterByName('oobCode');
      // (Optional) Get the continue URL from the query parameter if available.
      var continueUrl = getParameterByName('continueUrl');
      // (Optional) Get the language code if available.
      var lang = getParameterByName('lang') || 'en';
    
      // Configure the Firebase SDK.
      // This is the minimum configuration required for the API to be used.
      var config = {
        'apiKey': "YOU_API_KEY" // Copy this key from the web initialization
                                // snippet found in the Firebase console.
      };
      var app = firebase.initializeApp(config);
      var auth = app.auth();
    
      // Handle the user management action.
      switch (mode) {
        case 'resetPassword':
          // Display reset password handler and UI.
          handleResetPassword(auth, actionCode, continueUrl, lang);
          break;
        case 'recoverEmail':
          // Display email recovery handler and UI.
          handleRecoverEmail(auth, actionCode, lang);
          break;
        case 'verifyEmail':
          // Display email verification handler and UI.
          handleVerifyEmail(auth, actionCode, continueUrl, lang);
          break;
        default:
          // Error: invalid mode.
      }
    }, false);
  2. প্রথমে verifyPasswordResetCode দিয়ে অ্যাকশন কোড যাচাই করে পাসওয়ার্ড রিসেট করার অনুরোধগুলি পরিচালনা করুন; তারপর ব্যবহারকারীর কাছ থেকে একটি নতুন পাসওয়ার্ড পান এবং confirmPasswordReset করুন। উদাহরণ স্বরূপ:

    Web modular API

    import { verifyPasswordResetCode, confirmPasswordReset } from "firebase/auth";
    
    function handleResetPassword(auth, actionCode, continueUrl, lang) {
      // Localize the UI to the selected language as determined by the lang
      // parameter.
    
      // Verify the password reset code is valid.
      verifyPasswordResetCode(auth, actionCode).then((email) => {
        const accountEmail = email;
    
        // TODO: Show the reset screen with the user's email and ask the user for
        // the new password.
        const newPassword = "...";
    
        // Save the new password.
        confirmPasswordReset(auth, actionCode, newPassword).then((resp) => {
          // Password reset has been confirmed and new password updated.
    
          // TODO: Display a link back to the app, or sign-in the user directly
          // if the page belongs to the same domain as the app:
          // auth.signInWithEmailAndPassword(accountEmail, newPassword);
    
          // TODO: If a continue URL is available, display a button which on
          // click redirects the user back to the app via continueUrl with
          // additional state determined from that URL's parameters.
        }).catch((error) => {
          // Error occurred during confirmation. The code might have expired or the
          // password is too weak.
        });
      }).catch((error) => {
        // Invalid or expired action code. Ask user to try to reset the password
        // again.
      });
    }

    Web namespaced API

    function handleResetPassword(auth, actionCode, continueUrl, lang) {
      // Localize the UI to the selected language as determined by the lang
      // parameter.
    
      // Verify the password reset code is valid.
      auth.verifyPasswordResetCode(actionCode).then((email) => {
        var accountEmail = email;
    
        // TODO: Show the reset screen with the user's email and ask the user for
        // the new password.
        var newPassword = "...";
    
        // Save the new password.
        auth.confirmPasswordReset(actionCode, newPassword).then((resp) => {
          // Password reset has been confirmed and new password updated.
    
          // TODO: Display a link back to the app, or sign-in the user directly
          // if the page belongs to the same domain as the app:
          // auth.signInWithEmailAndPassword(accountEmail, newPassword);
    
          // TODO: If a continue URL is available, display a button which on
          // click redirects the user back to the app via continueUrl with
          // additional state determined from that URL's parameters.
        }).catch((error) => {
          // Error occurred during confirmation. The code might have expired or the
          // password is too weak.
        });
      }).catch((error) => {
        // Invalid or expired action code. Ask user to try to reset the password
        // again.
      });
    }
  3. প্রথমে checkActionCode দিয়ে অ্যাকশন কোড যাচাই করে ইমেল ঠিকানা পরিবর্তন প্রত্যাহার পরিচালনা করুন; তারপর applyActionCode দিয়ে ব্যবহারকারীর ইমেল ঠিকানা পুনরুদ্ধার করুন। উদাহরণ স্বরূপ:

    Web modular API

    import { checkActionCode, applyActionCode, sendPasswordResetEmail } from "firebase/auth";
    
    function handleRecoverEmail(auth, actionCode, lang) {
      // Localize the UI to the selected language as determined by the lang
      // parameter.
      let restoredEmail = null;
      // Confirm the action code is valid.
      checkActionCode(auth, actionCode).then((info) => {
        // Get the restored email address.
        restoredEmail = info['data']['email'];
    
        // Revert to the old email.
        return applyActionCode(auth, actionCode);
      }).then(() => {
        // Account email reverted to restoredEmail
    
        // TODO: Display a confirmation message to the user.
    
        // You might also want to give the user the option to reset their password
        // in case the account was compromised:
        sendPasswordResetEmail(auth, restoredEmail).then(() => {
          // Password reset confirmation sent. Ask user to check their email.
        }).catch((error) => {
          // Error encountered while sending password reset code.
        });
      }).catch((error) => {
        // Invalid code.
      });
    }

    Web namespaced API

    function handleRecoverEmail(auth, actionCode, lang) {
      // Localize the UI to the selected language as determined by the lang
      // parameter.
      var restoredEmail = null;
      // Confirm the action code is valid.
      auth.checkActionCode(actionCode).then((info) => {
        // Get the restored email address.
        restoredEmail = info['data']['email'];
    
        // Revert to the old email.
        return auth.applyActionCode(actionCode);
      }).then(() => {
        // Account email reverted to restoredEmail
    
        // TODO: Display a confirmation message to the user.
    
        // You might also want to give the user the option to reset their password
        // in case the account was compromised:
        auth.sendPasswordResetEmail(restoredEmail).then(() => {
          // Password reset confirmation sent. Ask user to check their email.
        }).catch((error) => {
          // Error encountered while sending password reset code.
        });
      }).catch((error) => {
        // Invalid code.
      });
    }
  4. applyActionCode কল করে ইমেল ঠিকানা যাচাইকরণ পরিচালনা করুন। উদাহরণ স্বরূপ:

    Web modular API

    function handleVerifyEmail(auth, actionCode, continueUrl, lang) {
      // Localize the UI to the selected language as determined by the lang
      // parameter.
      // Try to apply the email verification code.
      applyActionCode(auth, actionCode).then((resp) => {
        // Email address has been verified.
    
        // TODO: Display a confirmation message to the user.
        // You could also provide the user with a link back to the app.
    
        // TODO: If a continue URL is available, display a button which on
        // click redirects the user back to the app via continueUrl with
        // additional state determined from that URL's parameters.
      }).catch((error) => {
        // Code is invalid or expired. Ask the user to verify their email address
        // again.
      });
    }

    Web namespaced API

    function handleVerifyEmail(auth, actionCode, continueUrl, lang) {
      // Localize the UI to the selected language as determined by the lang
      // parameter.
      // Try to apply the email verification code.
      auth.applyActionCode(actionCode).then((resp) => {
        // Email address has been verified.
    
        // TODO: Display a confirmation message to the user.
        // You could also provide the user with a link back to the app.
    
        // TODO: If a continue URL is available, display a button which on
        // click redirects the user back to the app via continueUrl with
        // additional state determined from that URL's parameters.
      }).catch((error) => {
        // Code is invalid or expired. Ask the user to verify their email address
        // again.
      });
    }
  5. পৃষ্ঠাটি কোথাও হোস্ট করুন, উদাহরণস্বরূপ ফায়ারবেস হোস্টিং ব্যবহার করুন।

এর পরে, আপনাকে অবশ্যই আপনার Firebase প্রোজেক্ট কনফিগার করতে হবে আপনার কাস্টম ইমেল অ্যাকশন হ্যান্ডলারের সাথে লিঙ্ক করার জন্য এর ব্যবহারকারী ব্যবস্থাপনা ইমেলগুলিতে।

আপনার কাস্টম ইমেল অ্যাকশন হ্যান্ডলার ব্যবহার করার জন্য আপনার Firebase প্রকল্প কনফিগার করতে:

  1. Firebase কনসোলে আপনার প্রকল্প খুলুন।
  2. প্রমাণ বিভাগে ইমেল টেমপ্লেট পৃষ্ঠায় যান।
  3. যে কোনো ইমেল প্রকার এন্ট্রিতে, ইমেল টেমপ্লেট সম্পাদনা করতে পেন্সিল আইকনে ক্লিক করুন।
  4. কাস্টমাইজ অ্যাকশন ইউআরএল-এ ক্লিক করুন এবং আপনার কাস্টম ইমেল অ্যাকশন হ্যান্ডলারে ইউআরএল নির্দিষ্ট করুন।

আপনি URLটি সংরক্ষণ করার পরে, এটি আপনার Firebase প্রকল্পের সমস্ত ইমেল টেমপ্লেট ব্যবহার করবে৷