Невидимый токен reCAPTCHA 2.0 reCAPTCHA: ноль с Firebase ⇐ Jquery
Невидимый токен reCAPTCHA 2.0 reCAPTCHA: ноль с Firebase
So even in Google reCAPTCHA site it says:
We detected that your site is not verifying reCAPTCHA solutions. This is required for the proper use of reCAPTCHA on your site. Please see our developer site for more information.
And in console.log I get Token: null.
What have I done wrong here?
HTML:
Namn E-post Lösenord Skapa Konto /sso/sign-up.js:
$(document).ready(function () { // Show labels when the page loads $("#nameLabel, #emailLabel, #passwordLabel").show(); $("#warningMessage, #passwordLengthAlert, #success-message").hide(); // Add event listeners to show/hide labels as the user types function toggleLabelVisibility(inputField, label) { if (inputField.val().length > 0) { label.hide(); } else { label.show(); } } $("#inputName").on("input", function () { toggleLabelVisibility($(this), $("#nameLabel")); }); $("#inputEmail").on("input", function () { toggleLabelVisibility($(this), $("#emailLabel")); }); $("#inputPassword").on("input", function () { toggleLabelVisibility($(this), $("#passwordLabel")); // Check password length and display alert if less than 6 characters var password = $(this).val(); if (password.length < 6) { $("#passwordLengthAlert").show(); } else { $("#passwordLengthAlert").hide(); } }); $("#create-newuser-button").click(function () { // Hide the warning message at the beginning of the validation logic $("#warningMessage").hide(); // Execute invisible reCAPTCHA with the callback grecaptcha.execute(undefined, { action: 'submit' }).then(onRecaptchaSuccess); var name = $("#inputName").val(); var email = $("#inputEmail").val(); var password = $("#inputPassword").val(); var checkboxChecked = $("#flexCheckDefault").is(":checked"); if (name.trim() === '' || email.trim() === '' || password.trim() === '' || !checkboxChecked || password.length < 6) { // Show the warning message or password length alert $("#warningMessage").show(); $("#success-message").hide(); // Auto-dismiss the warning message after 3 seconds setTimeout(function () { $("#warningMessage").hide(); }, 3000); return; // Stop further processing } // Create a new user in Firebase Auth firebase.auth().createUserWithEmailAndPassword(email, password) .then(function (userCredential) { // User creation was successful var user = userCredential.user; user.sendEmailVerification() .then(function() { console.log("Email verification sent"); }) .catch(function(error) { console.error("Error sending email verification: ", error); }); // Now, store additional user data in Firestore return db.collection("users").doc(user.uid).set({ uid: user.uid, // Store the uid email: email, password: password, displayName: name, }); }) .then(function () { // Additional logic after Firestore write success console.log("User data successfully written to Firestore!"); // Show the success message $("#success-message").show(); console.log("About to show success message"); setTimeout(function() { window.location.href = "/pages/home.html"; }, 5000); // Auto-dismiss the success message after 10 seconds setTimeout(function () { $("#success-message").hide(); }, 10000); }) .catch(function (error) { // Handle errors during user creation or Firestore write console.error("Error creating user or writing data to Firestore: ", error); // Show the warning message and auto-dismiss after 3 seconds $("#warningMessage").show(); $("#success-message").hide(); // Auto-dismiss the warning message after 3 seconds setTimeout(function () { $("#warningMessage").hide(); }, 3000); }); }); }); function onRecaptchaSuccess(token) { // Log the reCAPTCHA token to the console console.log("reCAPTCHA Token:", token); // Execute your authentication logic inside the promise chain firebase.auth().signInWithRecaptcha(token) .then(function (userCredential) { // Handle successful authentication var user = userCredential.user; console.log("Authentication successful:", user); // Now you can proceed with the rest of your logic }) .catch(function (error) { // Handle authentication error console.error("Authentication error:", error); }); }
Источник: https://stackoverflow.com/questions/781 ... h-firebase
So even in Google reCAPTCHA site it says:
We detected that your site is not verifying reCAPTCHA solutions. This is required for the proper use of reCAPTCHA on your site. Please see our developer site for more information.
And in console.log I get Token: null.
What have I done wrong here?
HTML:
Namn E-post Lösenord Skapa Konto /sso/sign-up.js:
$(document).ready(function () { // Show labels when the page loads $("#nameLabel, #emailLabel, #passwordLabel").show(); $("#warningMessage, #passwordLengthAlert, #success-message").hide(); // Add event listeners to show/hide labels as the user types function toggleLabelVisibility(inputField, label) { if (inputField.val().length > 0) { label.hide(); } else { label.show(); } } $("#inputName").on("input", function () { toggleLabelVisibility($(this), $("#nameLabel")); }); $("#inputEmail").on("input", function () { toggleLabelVisibility($(this), $("#emailLabel")); }); $("#inputPassword").on("input", function () { toggleLabelVisibility($(this), $("#passwordLabel")); // Check password length and display alert if less than 6 characters var password = $(this).val(); if (password.length < 6) { $("#passwordLengthAlert").show(); } else { $("#passwordLengthAlert").hide(); } }); $("#create-newuser-button").click(function () { // Hide the warning message at the beginning of the validation logic $("#warningMessage").hide(); // Execute invisible reCAPTCHA with the callback grecaptcha.execute(undefined, { action: 'submit' }).then(onRecaptchaSuccess); var name = $("#inputName").val(); var email = $("#inputEmail").val(); var password = $("#inputPassword").val(); var checkboxChecked = $("#flexCheckDefault").is(":checked"); if (name.trim() === '' || email.trim() === '' || password.trim() === '' || !checkboxChecked || password.length < 6) { // Show the warning message or password length alert $("#warningMessage").show(); $("#success-message").hide(); // Auto-dismiss the warning message after 3 seconds setTimeout(function () { $("#warningMessage").hide(); }, 3000); return; // Stop further processing } // Create a new user in Firebase Auth firebase.auth().createUserWithEmailAndPassword(email, password) .then(function (userCredential) { // User creation was successful var user = userCredential.user; user.sendEmailVerification() .then(function() { console.log("Email verification sent"); }) .catch(function(error) { console.error("Error sending email verification: ", error); }); // Now, store additional user data in Firestore return db.collection("users").doc(user.uid).set({ uid: user.uid, // Store the uid email: email, password: password, displayName: name, }); }) .then(function () { // Additional logic after Firestore write success console.log("User data successfully written to Firestore!"); // Show the success message $("#success-message").show(); console.log("About to show success message"); setTimeout(function() { window.location.href = "/pages/home.html"; }, 5000); // Auto-dismiss the success message after 10 seconds setTimeout(function () { $("#success-message").hide(); }, 10000); }) .catch(function (error) { // Handle errors during user creation or Firestore write console.error("Error creating user or writing data to Firestore: ", error); // Show the warning message and auto-dismiss after 3 seconds $("#warningMessage").show(); $("#success-message").hide(); // Auto-dismiss the warning message after 3 seconds setTimeout(function () { $("#warningMessage").hide(); }, 3000); }); }); }); function onRecaptchaSuccess(token) { // Log the reCAPTCHA token to the console console.log("reCAPTCHA Token:", token); // Execute your authentication logic inside the promise chain firebase.auth().signInWithRecaptcha(token) .then(function (userCredential) { // Handle successful authentication var user = userCredential.user; console.log("Authentication successful:", user); // Now you can proceed with the rest of your logic }) .catch(function (error) { // Handle authentication error console.error("Authentication error:", error); }); }
Источник: https://stackoverflow.com/questions/781 ... h-firebase
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение