implemented stripe for the cloud instance
This commit is contained in:
@@ -3,10 +3,16 @@ import { AccountSettings } from "@/types/global";
|
||||
import bcrypt from "bcrypt";
|
||||
import removeFile from "@/lib/api/storage/removeFile";
|
||||
import createFile from "@/lib/api/storage/createFile";
|
||||
import updateCustomerEmail from "../../updateCustomerEmail";
|
||||
|
||||
export default async function updateUser(
|
||||
user: AccountSettings,
|
||||
userId: number
|
||||
sessionUser: {
|
||||
id: number;
|
||||
username: string;
|
||||
email: string;
|
||||
isSubscriber: boolean;
|
||||
}
|
||||
) {
|
||||
if (!user.username || !user.email)
|
||||
return {
|
||||
@@ -24,7 +30,7 @@ export default async function updateUser(
|
||||
const base64Data = profilePic.replace(/^data:image\/jpeg;base64,/, "");
|
||||
|
||||
await createFile({
|
||||
filePath: `uploads/avatar/${userId}.jpg`,
|
||||
filePath: `uploads/avatar/${sessionUser.id}.jpg`,
|
||||
data: base64Data,
|
||||
isBase64: true,
|
||||
});
|
||||
@@ -39,7 +45,7 @@ export default async function updateUser(
|
||||
};
|
||||
}
|
||||
} else if (profilePic == "") {
|
||||
removeFile({ filePath: `uploads/avatar/${userId}.jpg` });
|
||||
removeFile({ filePath: `uploads/avatar/${sessionUser.id}.jpg` });
|
||||
}
|
||||
|
||||
// Other settings
|
||||
@@ -49,7 +55,7 @@ export default async function updateUser(
|
||||
|
||||
const updatedUser = await prisma.user.update({
|
||||
where: {
|
||||
id: userId,
|
||||
id: sessionUser.id,
|
||||
},
|
||||
data: {
|
||||
name: user.name,
|
||||
@@ -64,6 +70,17 @@ export default async function updateUser(
|
||||
},
|
||||
});
|
||||
|
||||
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
|
||||
const PRICE_ID = process.env.PRICE_ID;
|
||||
|
||||
if (STRIPE_SECRET_KEY && PRICE_ID)
|
||||
await updateCustomerEmail(
|
||||
STRIPE_SECRET_KEY,
|
||||
PRICE_ID,
|
||||
sessionUser.email,
|
||||
user.email
|
||||
);
|
||||
|
||||
const { password, ...userInfo } = updatedUser;
|
||||
|
||||
const response: Omit<AccountSettings, "password"> = {
|
||||
|
||||
Reference in New Issue
Block a user