कभी-कभी मोबाइल ऐप्लिकेशन को उपयोगकर्ताओं से इंटरैक्ट करने की ज़रूरत होती है. इसके लिए, वे उपयोगकर्ताओं को ईमेल भेजकर कुछ कार्रवाइयां करने के लिए कहते हैं.
Firebase के क्लाइंट SDK टूल, उपयोगकर्ताओं को ऐसे ईमेल भेजने की सुविधा देते हैं जिनमें ऐसे लिंक होते हैं जिनका इस्तेमाल पासवर्ड रीसेट करने, ईमेल पते की पुष्टि करने, और ईमेल के ज़रिए साइन-इन करने के लिए किया जा सकता है. टेंप्लेट पर आधारित इन ईमेल को Google भेजता है. इनमें बदलाव करने की सुविधा सीमित होती है.
अगर आपको अपने ईमेल टेंप्लेट और ईमेल भेजने की अपनी सेवा का इस्तेमाल करना है, तो इस पेज पर बताया गया है कि ऊपर दिए गए फ़्लो के लिए, प्रोग्राम के हिसाब से कार्रवाई के लिंक जनरेट करने के लिए Firebase Admin SDK टूल का इस्तेमाल कैसे करें. इन लिंक को अपने उपयोगकर्ताओं को भेजे जाने वाले ईमेल में शामिल किया जा सकता है.
इससे ये फ़ायदे मिलते हैं:
- ईमेल टेंप्लेट को पसंद के मुताबिक बनाएं. इसमें नई स्टाइल और कस्टम ब्रैंडिंग जोड़ने, शब्दों और लोगो को बदलने, उपयोगकर्ताओं को पूरे नाम के बजाय पहले नाम से संबोधित करने की सुविधा वगैरह शामिल है.
- कॉन्टेक्स्ट के हिसाब से अलग-अलग टेंप्लेट लागू करें. उदाहरण के लिए, अगर कोई व्यक्ति न्यूज़लेटर की सदस्यता लेने के लिए अपने ईमेल की पुष्टि कर रहा है, तो ईमेल के कॉन्टेंट में संदर्भ दिया जाना ज़रूरी हो सकता है. ईमेल लिंक से साइन इन करने का एक और उदाहरण यहां दिया गया है: एक स्थिति में, इसे वही उपयोगकर्ता ट्रिगर कर सकता है या किसी अन्य उपयोगकर्ता के न्योते के तौर पर ट्रिगर किया जा सकता है. आपको ईमेल में संदर्भ शामिल करना होगा.
- पसंद के मुताबिक बनाए गए ईमेल टेंप्लेट को स्थानीय भाषा में उपलब्ध कराएं.
- सुरक्षित सर्वर एनवायरमेंट से लिंक जनरेट करने की सुविधा.
- लिंक को मोबाइल ऐप्लिकेशन या ब्राउज़र के ज़रिए खोलने के तरीके को पसंद के मुताबिक बनाने की सुविधा. साथ ही, स्थिति के बारे में अतिरिक्त जानकारी वगैरह को पास करने का तरीका.
- ईमेल ऐक्शन लिंक बनाते समय, मोबाइल ऐप्लिकेशन के फ़्लो के लिए इस्तेमाल किए गए मोबाइल लिंक डोमेन को पसंद के मुताबिक बनाने की सुविधा.
ActionCodeSettings को शुरू करना
ईमेल ऐक्शन लिंक जनरेट करने से पहले, आपको ActionCodeSettings
इंस्टेंस को शुरू करना पड़ सकता है.
ActionCodeSettings
की मदद से, जारी रखने के यूआरएल के ज़रिए अतिरिक्त स्थिति पास की जा सकती है. यह यूआरएल, उपयोगकर्ता के ईमेल लिंक पर क्लिक करने के बाद ऐक्सेस किया जा सकता है. इससे उपयोगकर्ता को कार्रवाई पूरी होने के बाद, ऐप्लिकेशन पर वापस जाने की सुविधा भी मिलती है. इसके अलावा, यह तय किया जा सकता है कि ईमेल ऐक्शन लिंक को सीधे तौर पर मोबाइल ऐप्लिकेशन से हैंडल करना है या ब्राउज़र से. ऐसा तब किया जाता है, जब ऐप्लिकेशन इंस्टॉल हो.
मोबाइल ऐप्लिकेशन से खोले जाने वाले लिंक का पता लगाने के लिए, आपको कुछ टास्क पूरे करने होंगे. ईमेल से की जाने वाली कार्रवाइयों के लिए, मोबाइल लिंक कॉन्फ़िगर करने के तरीके से जुड़े निर्देश देखें.
ActionCodeSettings
इंस्टेंस को शुरू करने के लिए, यह डेटा दें:
पैरामीटर | टाइप | ब्यौरा |
---|---|---|
url |
स्ट्रिंग | यह कुकी, लिंक (स्टेट/जारी रखने का यूआरएल) सेट करती है. इसका मतलब अलग-अलग संदर्भों में अलग-अलग होता है:
|
iOS |
({bundleId: string}|undefined) | यह कुकी, iOS बंडल आईडी सेट करती है. इससे Firebase Authentication को यह तय करने में मदद मिलती है कि उसे वेब-ओनली लिंक बनाना चाहिए या मोबाइल लिंक. मोबाइल लिंक को Apple डिवाइस पर खोला जाता है |
android |
({packageName: string, installApp:boolean|undefined, minimumVersion: string|undefined}|undefined) | यह कुकी, Android ऐप्लिकेशन के पैकेज का नाम सेट करती है. इससे Firebase Authentication को यह तय करने में मदद मिलती है कि उसे सिर्फ़ वेब के लिए लिंक बनाना चाहिए या मोबाइल लिंक बनाना चाहिए. मोबाइल लिंक को Android डिवाइस पर खोला जाता है |
handleCodeInApp |
(बूलियन|तय नहीं है) | ईमेल ऐक्शन लिंक को पहले मोबाइल ऐप्लिकेशन में खोला जाएगा या वेब लिंक में. डिफ़ॉल्ट रूप से, यह 'गलत' पर सेट होता है. इस विकल्प को 'सही है' पर सेट करने पर, कार्रवाई के कोड का लिंक, यूनिवर्सल लिंक या Android ऐप्लिकेशन लिंक के तौर पर भेजा जाएगा. साथ ही, अगर ऐप्लिकेशन इंस्टॉल है, तो उसे ऐप्लिकेशन से खोला जाएगा. अगर यह वैल्यू गलत है, तो कोड सबसे पहले वेब विजेट को भेजा जाएगा. इसके बाद, जारी रखने पर ऐप्लिकेशन इंस्टॉल होने पर उसे रीडायरेक्ट कर दिया जाएगा. |
linkDomain |
(string|undefined) | किसी प्रोजेक्ट के लिए कस्टम होस्टिंग लिंक डोमेन तय किए जाने पर, यह तय करें कि किसी मोबाइल ऐप्लिकेशन से लिंक खोलने के लिए, किस डोमेन का इस्तेमाल किया जाए. ऐसा न करने पर, डिफ़ॉल्ट डोमेन अपने-आप चुना जाता है. उदाहरण के लिए, PROJECT_ID.firebaseapp.com |
dynamicLinkDomain |
(string|undefined) | समर्थन नहीं होना या रुकना. इस पैरामीटर को न डालें. |
यहां दिए गए उदाहरण में, ईमेल की पुष्टि करने के लिए लिंक भेजने का तरीका बताया गया है. यह लिंक सबसे पहले मोबाइल ऐप्लिकेशन में खुलेगा. डीप लिंक में, जारी रखने के यूआरएल का पेलोड https://www.example.com/checkout?cartId=1234
शामिल होगा. इस्तेमाल किया गया कस्टम Hosting लिंक डोमेन custom-domain.com
है. इसे Firebase Hosting के साथ इस्तेमाल करने के लिए कॉन्फ़िगर किया जाना चाहिए.
Node.js
const actionCodeSettings = {
// URL you want to redirect back to. The domain (www.example.com) for
// this URL must be whitelisted in the Firebase Console.
url: 'https://www.example.com/checkout?cartId=1234',
// This must be true for email link sign-in.
handleCodeInApp: true,
iOS: {
bundleId: 'com.example.ios',
},
android: {
packageName: 'com.example.android',
installApp: true,
minimumVersion: '12',
},
// The domain must be configured in Firebase Hosting and owned by the project.
linkDomain: 'custom-domain.com',
};
Java
ActionCodeSettings actionCodeSettings = ActionCodeSettings.builder()
.setUrl("https://www.example.com/checkout?cartId=1234")
.setHandleCodeInApp(true)
.setIosBundleId("com.example.ios")
.setAndroidPackageName("com.example.android")
.setAndroidInstallApp(true)
.setAndroidMinimumVersion("12")
.setDynamicLinkDomain("coolapp.page.link")
.build();
Python
action_code_settings = auth.ActionCodeSettings(
url='https://www.example.com/checkout?cartId=1234',
handle_code_in_app=True,
ios_bundle_id='com.example.ios',
android_package_name='com.example.android',
android_install_app=True,
android_minimum_version='12',
dynamic_link_domain='coolapp.page.link',
)
शुरू करें
actionCodeSettings := &auth.ActionCodeSettings{
URL: "https://www.example.com/checkout?cartId=1234",
HandleCodeInApp: true,
IOSBundleID: "com.example.ios",
AndroidPackageName: "com.example.android",
AndroidInstallApp: true,
AndroidMinimumVersion: "12",
DynamicLinkDomain: "coolapp.page.link",
}
C#
var actionCodeSettings = new ActionCodeSettings()
{
Url = "https://www.example.com/checkout?cartId=1234",
HandleCodeInApp = true,
IosBundleId = "com.example.ios",
AndroidPackageName = "com.example.android",
AndroidInstallApp = true,
AndroidMinimumVersion = "12",
DynamicLinkDomain = "coolapp.page.link",
};
ज़्यादा जानने के लिए, ईमेल ऐक्शन में स्थिति पास करना लेख पढ़ें.
पासवर्ड रीसेट करने के लिए ईमेल लिंक जनरेट करना
पासवर्ड रीसेट करने का लिंक जनरेट करने के लिए, मौजूदा उपयोगकर्ता का ईमेल पता और एक वैकल्पिक ActionCodeSettings
ऑब्जेक्ट दें. ईमेल में दिए गए लिंक पर क्लिक करके, इस समस्या को हल किया जा सकता है. इस्तेमाल किया गया ईमेल, किसी मौजूदा उपयोगकर्ता का होना चाहिए.
Node.js
// Admin SDK API to generate the password reset link.
const userEmail = 'user@example.com';
getAuth()
.generatePasswordResetLink(userEmail, actionCodeSettings)
.then((link) => {
// Construct password reset email template, embed the link and send
// using custom SMTP server.
return sendCustomPasswordResetEmail(userEmail, displayName, link);
})
.catch((error) => {
// Some error occurred.
});
Java
String email = "user@example.com";
try {
String link = FirebaseAuth.getInstance().generatePasswordResetLink(
email, actionCodeSettings);
// Construct email verification template, embed the link and send
// using custom SMTP server.
sendCustomEmail(email, displayName, link);
} catch (FirebaseAuthException e) {
System.out.println("Error generating email link: " + e.getMessage());
}
Python
email = 'user@example.com'
link = auth.generate_password_reset_link(email, action_code_settings)
# Construct password reset email from a template embedding the link, and send
# using a custom SMTP server.
send_custom_email(email, link)
शुरू करें
email := "user@example.com"
link, err := client.PasswordResetLinkWithSettings(ctx, email, actionCodeSettings)
if err != nil {
log.Fatalf("error generating email link: %v\n", err)
}
// Construct password reset template, embed the link and send
// using custom SMTP server.
sendCustomEmail(email, displayName, link)
C#
var email = "user@example.com";
var link = await FirebaseAuth.DefaultInstance.GeneratePasswordResetLinkAsync(
email, actionCodeSettings);
// Construct email verification template, embed the link and send
// using custom SMTP server.
SendCustomEmail(email, displayName, link);
लिंक जनरेट होने के बाद, इसे पासवर्ड रीसेट करने के लिए भेजे जाने वाले कस्टम ईमेल में डाला जा सकता है. इसके बाद, कस्टम एसएमटीपी सर्वर का इस्तेमाल करके, इसे संबंधित उपयोगकर्ता को ईमेल किया जा सकता है.
अगर डिफ़ॉल्ट पासवर्ड रीसेट लैंडिंग पेज का इस्तेमाल नहीं किया जा रहा है और आपने खुद का कस्टम हैंडलर बनाया है, तो कस्टम ईमेल ऐक्शन हैंडलर बनाना लेख पढ़ें.
ईमेल पते की पुष्टि करने के लिए लिंक जनरेट करना
ईमेल की पुष्टि करने वाला लिंक जनरेट करने के लिए, मौजूदा उपयोगकर्ता का वह ईमेल पता दें जिसकी पुष्टि नहीं हुई है. साथ ही, चाहें तो ActionCodeSettings
ऑब्जेक्ट भी दें. यह कार्रवाई, ईमेल ऐक्शन लिंक के साथ पूरी होगी.
इस्तेमाल किया गया ईमेल, किसी मौजूदा उपयोगकर्ता का होना चाहिए.
Node.js
// Admin SDK API to generate the email verification link.
const useremail = 'user@example.com';
getAuth()
.generateEmailVerificationLink(useremail, actionCodeSettings)
.then((link) => {
// Construct email verification template, embed the link and send
// using custom SMTP server.
return sendCustomVerificationEmail(useremail, displayName, link);
})
.catch((error) => {
// Some error occurred.
});
Java
String email = "user@example.com";
try {
String link = FirebaseAuth.getInstance().generateEmailVerificationLink(
email, actionCodeSettings);
// Construct email verification template, embed the link and send
// using custom SMTP server.
sendCustomEmail(email, displayName, link);
} catch (FirebaseAuthException e) {
System.out.println("Error generating email link: " + e.getMessage());
}
Python
email = 'user@example.com'
link = auth.generate_email_verification_link(email, action_code_settings)
# Construct email from a template embedding the link, and send
# using a custom SMTP server.
send_custom_email(email, link)
शुरू करें
email := "user@example.com"
link, err := client.EmailVerificationLinkWithSettings(ctx, email, actionCodeSettings)
if err != nil {
log.Fatalf("error generating email link: %v\n", err)
}
// Construct email verification template, embed the link and send
// using custom SMTP server.
sendCustomEmail(email, displayName, link)
C#
var email = "user@example.com";
var link = await FirebaseAuth.DefaultInstance.GenerateEmailVerificationLinkAsync(
email, actionCodeSettings);
// Construct email verification template, embed the link and send
// using custom SMTP server.
SendCustomEmail(email, displayName, link);
लिंक जनरेट होने के बाद, इसे पुष्टि करने के लिए भेजे जाने वाले कस्टम ईमेल में डाला जा सकता है. इसके बाद, कस्टम एसएमटीपी सर्वर का इस्तेमाल करके, इसे संबंधित उपयोगकर्ता को ईमेल किया जा सकता है.
अगर ईमेल की पुष्टि करने वाले डिफ़ॉल्ट लैंडिंग पेज का इस्तेमाल नहीं किया जा रहा है और आपने खुद का कस्टम हैंडलर बनाया है, तो ईमेल से जुड़ी कस्टम कार्रवाई के हैंडलर बनाना लेख पढ़ें.
साइन-इन करने के लिए ईमेल लिंक जनरेट करना
ईमेल लिंक से साइन-इन करने की सुविधा का इस्तेमाल करके उपयोगकर्ताओं की पुष्टि करने से पहले, आपको अपने Firebase प्रोजेक्ट के लिए ईमेल लिंक से साइन-इन करने की सुविधा चालू करनी होगी.
साइन-इन लिंक जनरेट करने के लिए, उपयोगकर्ता का ईमेल पता और ActionCodeSettings
ऑब्जेक्ट दें. इस मामले में, ActionCodeSettings
ऑब्जेक्ट ज़रूरी है. इससे यह जानकारी मिलती है कि साइन-इन की प्रोसेस पूरी होने के बाद, उपयोगकर्ता को कहां रीडायरेक्ट करना है. यह कार्रवाई, ईमेल ऐक्शन लिंक के साथ पूरी होगी.
पासवर्ड रीसेट करने और ईमेल की पुष्टि करने के लिए, इस्तेमाल किए गए ईमेल पते का मौजूदा उपयोगकर्ता से जुड़ा होना ज़रूरी नहीं है. ऐसा इसलिए, क्योंकि इस ऑपरेशन का इस्तेमाल करके, ईमेल लिंक के ज़रिए नए उपयोगकर्ताओं को आपके ऐप्लिकेशन में साइन अप कराया जा सकता है.
Node.js
// Admin SDK API to generate the sign in with email link.
const useremail = 'user@example.com';
getAuth()
.generateSignInWithEmailLink(useremail, actionCodeSettings)
.then((link) => {
// Construct sign-in with email link template, embed the link and
// send using custom SMTP server.
return sendSignInEmail(useremail, displayName, link);
})
.catch((error) => {
// Some error occurred.
});
Java
String email = "user@example.com";
try {
String link = FirebaseAuth.getInstance().generateSignInWithEmailLink(
email, actionCodeSettings);
// Construct email verification template, embed the link and send
// using custom SMTP server.
sendCustomEmail(email, displayName, link);
} catch (FirebaseAuthException e) {
System.out.println("Error generating email link: " + e.getMessage());
}
Python
email = 'user@example.com'
link = auth.generate_sign_in_with_email_link(email, action_code_settings)
# Construct email from a template embedding the link, and send
# using a custom SMTP server.
send_custom_email(email, link)
शुरू करें
email := "user@example.com"
link, err := client.EmailSignInLink(ctx, email, actionCodeSettings)
if err != nil {
log.Fatalf("error generating email link: %v\n", err)
}
// Construct sign-in with email link template, embed the link and send
// using custom SMTP server.
sendCustomEmail(email, displayName, link)
C#
var email = "user@example.com";
var link = await FirebaseAuth.DefaultInstance.GenerateSignInWithEmailLinkAsync(
email, actionCodeSettings);
// Construct email verification template, embed the link and send
// using custom SMTP server.
SendCustomEmail(email, displayName, link);
लिंक जनरेट होने के बाद, उसे कस्टम साइन-इन ईमेल में डाला जा सकता है. इसके बाद, कस्टम एसएमटीपी सर्वर का इस्तेमाल करके, उसे संबंधित उपयोगकर्ता को ईमेल किया जा सकता है.
ईमेल लिंक का इस्तेमाल करके, Firebase की मदद से उपयोगकर्ताओं की पुष्टि करने के बारे में ज़्यादा जानें. इससे यह जानकारी मिलती है कि उपयोगकर्ता के लिंक पर क्लिक करने और ऐप्लिकेशन पर वापस रीडायरेक्ट होने के बाद, साइन-इन की प्रोसेस कैसे पूरी की जाए.