const {data: userData} = trpc.getUsers.useQuery();
let users = userData ? userData.data : [];
if (users !== undefined) {
console.log("users", users)
} const {data: userData} = trpc.getUsers.useQuery();
let users = userData ? userData.data : [];
if (users !== undefined) {
console.log("users", users)
}getUsers: privateProcedure
.query(async ({ ctx }) => {
try{
const { userEmail } = ctx;
await dbConnect();
const foundUser = await userModel.findOne({ email: userEmail });
if (!foundUser) throw new TRPCError({ code: "UNAUTHORIZED" })
const users = await userModel.find({ team: foundUser.team });
// console.log("backend data: ", users)
return {
data: users, status: 200, success: true
};
} catch (err) {
console.log(err)
return { data: [], status: 500, success: false };
}
})getUsers: privateProcedure
.query(async ({ ctx }) => {
try{
const { userEmail } = ctx;
await dbConnect();
const foundUser = await userModel.findOne({ email: userEmail });
if (!foundUser) throw new TRPCError({ code: "UNAUTHORIZED" })
const users = await userModel.find({ team: foundUser.team });
// console.log("backend data: ", users)
return {
data: users, status: 200, success: true
};
} catch (err) {
console.log(err)
return { data: [], status: 500, success: false };
}
})ResponseResponse or a NextResponseNextResponse in all branches of your handler.Join the Discord to ask follow-up questions and connect with the community