You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log(`Fetching user with clerkId: ${userId}`); // Log userId
const user = await User.findOne({ clerkId: userId });
if (!user) {
console.error(`User not found with clerkId: ${userId}`); // Log error
throw new Error(`User with clerkId ${userId} not found`);
}
return JSON.parse(JSON.stringify(user));
console.log(`Deleting user with clerkId: ${clerkId}`); // Log clerkId
const userToDelete = await User.findOne({ clerkId });
if (!userToDelete) {
console.error(`User not found for deletion with clerkId: ${clerkId}`); // Log error
throw new Error(`User not found with clerkId ${clerkId}`);
}
const deletedUser = await User.findByIdAndDelete(userToDelete._id);
revalidatePath("/");
return deletedUser ? JSON.parse(JSON.stringify(deletedUser)) : null;
} catch (error) {
handleError(error);
}
}
// USE CREDITS
export async function updateCredits(userId: string, creditFee: number) {
try {
await connectToDatabase();
console.log(`Updating credits for user with _id: ${userId}`); // Log userId
const updatedUserCredits = await User.findOneAndUpdate(
{ _id: userId },
{ $inc: { creditBalance: creditFee }},
{ new: true }
);
if (!updatedUserCredits) {
console.error(`User credits update failed for _id: ${userId}`); // Log error
throw new Error(`User credits update failed for _id ${userId}`);
}
return JSON.parse(JSON.stringify(updatedUserCredits));
i had the same issue i fixed it awaiting the auth in the transformations>add>type>page.tsx, like this const { userId }: { userId: string | null } = await auth();
HERE IS MY CODES " "use server";
import { revalidatePath } from "next/cache";
import User from "../database/models/user.model";
import { connectToDatabase } from "../database/mongose";
import { handleError } from "../utils";
// CREATE
export async function createUser(user: CreateUserParams) {
try {
await connectToDatabase();
} catch (error) {
handleError(error);
}
}
// READ
export async function getUserById(userId: string) {
try {
await connectToDatabase();
} catch (error) {
handleError(error);
}
}
// UPDATE
export async function updateUser(clerkId: string, user: UpdateUserParams) {
try {
await connectToDatabase();
} catch (error) {
handleError(error);
}
}
// DELETE
export async function deleteUser(clerkId: string) {
try {
await connectToDatabase();
} catch (error) {
handleError(error);
}
}
// USE CREDITS
export async function updateCredits(userId: string, creditFee: number) {
try {
await connectToDatabase();
} catch (error) {
handleError(error);
}
}
" @adrianhajdin
The text was updated successfully, but these errors were encountered: