@@ -26,10 +26,10 @@ const Login = () => {
|
||||
email,
|
||||
password
|
||||
);
|
||||
|
||||
// Signed in
|
||||
userCredential?.user && navigate("/dashboard");
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
if (
|
||||
["auth/invalid-login-credentials", "auth/invalid-email"].includes(
|
||||
error.code
|
||||
|
||||
@@ -146,7 +146,7 @@ const SignupPage = () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveUserData(authId, dataValues) {
|
||||
async function saveUserData(authId, dataValues, customerId, subscriptionId) {
|
||||
const appUserId = uuidv4();
|
||||
const firmId = uuidv4();
|
||||
const fbAuthUid = authId;
|
||||
@@ -167,10 +167,11 @@ const SignupPage = () => {
|
||||
practiceArea,
|
||||
email,
|
||||
} = dataValues;
|
||||
|
||||
const subscriptionId = dataValues?.subscriptionId;
|
||||
const customerId = dataValues?.customerId;
|
||||
|
||||
console.log(
|
||||
"customerId, subscriptionId in saveUserData",
|
||||
customerId,
|
||||
subscriptionId
|
||||
);
|
||||
const userData = {
|
||||
docsAllowed,
|
||||
docsGenerated,
|
||||
@@ -188,8 +189,8 @@ const SignupPage = () => {
|
||||
barNumber,
|
||||
practiceArea,
|
||||
email,
|
||||
//subscriptionId,
|
||||
//customerId,
|
||||
customerId: customerId,
|
||||
subscriptionId: subscriptionId,
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -241,7 +242,6 @@ const SignupPage = () => {
|
||||
|
||||
// ******************** STRIPE PAY API CALL ******************** //
|
||||
async function handleStripeAuthorization(
|
||||
user,
|
||||
paymentDataValues,
|
||||
customerDataValues
|
||||
) {
|
||||
@@ -267,7 +267,7 @@ const SignupPage = () => {
|
||||
|
||||
const type = selectedPlan[0].value ? selectedPlan[0].value : null;
|
||||
try {
|
||||
let response = await fetch(`${apiUrl}/create-subscription`, {
|
||||
const response = await fetch(`${apiUrl}/create-subscription`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
@@ -284,14 +284,14 @@ const SignupPage = () => {
|
||||
}),
|
||||
});
|
||||
|
||||
response = await response.json();
|
||||
const data = await response.json();
|
||||
|
||||
subscriptionId = response.subscriptionId;
|
||||
customerId = response.customerId;
|
||||
console.log("data in stripe auth call -------------++++++++++++++", data);
|
||||
//subscriptionId = response.subscriptionId;
|
||||
//customerId = response.customerId;
|
||||
|
||||
return {
|
||||
subscriptionId,
|
||||
//customerId,
|
||||
data,
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -326,6 +326,19 @@ const SignupPage = () => {
|
||||
setIsBusy(true);
|
||||
if (paymentDataValues && dataValues) {
|
||||
try {
|
||||
const data = await handleStripeAuthorization(
|
||||
paymentDataValues,
|
||||
dataValues
|
||||
);
|
||||
console.log("----------------------------->>>>>>>>>>>>>>>>>data", data);
|
||||
const customerId = data.data.customerId;
|
||||
const subscriptionId = data.data.subscriptionId;
|
||||
|
||||
if (data === undefined) {
|
||||
setIsBusy(false);
|
||||
setNotice("Sorry, something went wrong. Please try again.");
|
||||
return;
|
||||
} else {
|
||||
const userCredential = await createUserWithEmailAndPassword(
|
||||
auth,
|
||||
dataValues.email,
|
||||
@@ -333,24 +346,14 @@ const SignupPage = () => {
|
||||
);
|
||||
|
||||
const user = userCredential.user;
|
||||
|
||||
const paymentResponse = await handleStripeAuthorization(
|
||||
user,
|
||||
paymentDataValues,
|
||||
dataValues
|
||||
);
|
||||
dataValues = { ...dataValues, ...data };
|
||||
console.log(
|
||||
"----------------------------->>>>>>>>>>>>>>>>>paymentResponse",
|
||||
paymentResponse
|
||||
"customerId, subscriptionId in handleSignup right before saveUserData",
|
||||
customerId,
|
||||
subscriptionId
|
||||
);
|
||||
if (paymentResponse === false) {
|
||||
setIsBusy(false);
|
||||
setNotice("Sorry, something went wrong. Please try again.");
|
||||
return;
|
||||
} else {
|
||||
dataValues = { ...dataValues, ...paymentResponse };
|
||||
await saveUserData(user.uid, dataValues);
|
||||
navigate("/");
|
||||
await saveUserData(user.uid, dataValues, customerId, subscriptionId);
|
||||
navigate("/dashboard");
|
||||
}
|
||||
} catch (error) {
|
||||
setIsBusy(false);
|
||||
|
||||
Reference in New Issue
Block a user