troy
troy
TTCTheo's Typesafe Cult
Created by troy on 8/1/2023 in #questions
csv uploads
Trying to upload a csv file with UploadThing and keep running into this error, should it be a different file type?
export const ourFileRouter = {
// Define as many FileRoutes as you like, each with a unique routeSlug
csvUploader: f(["text/plain", "text/csv"], ["csv"])
// Set permissions and file types for this FileRoute
.middleware(async ({ req, res }) => {
// This code runs on your server before upload
const user = await auth(req, res);

// If you throw, the user will not be able to upload
if (!user) throw new Error("Unauthorized");

// Whatever is returned here is accessible in onUploadComplete as `metadata`
return { userId: user.id };
})
.onUploadComplete(async ({ metadata, file }) => {
// This code RUNS ON YOUR SERVER after upload
console.log("Upload complete for userId:", metadata.userId);

console.log("file url", file.url);
}),
} satisfies FileRouter;
export const ourFileRouter = {
// Define as many FileRoutes as you like, each with a unique routeSlug
csvUploader: f(["text/plain", "text/csv"], ["csv"])
// Set permissions and file types for this FileRoute
.middleware(async ({ req, res }) => {
// This code runs on your server before upload
const user = await auth(req, res);

// If you throw, the user will not be able to upload
if (!user) throw new Error("Unauthorized");

// Whatever is returned here is accessible in onUploadComplete as `metadata`
return { userId: user.id };
})
.onUploadComplete(async ({ metadata, file }) => {
// This code RUNS ON YOUR SERVER after upload
console.log("Upload complete for userId:", metadata.userId);

console.log("file url", file.url);
}),
} satisfies FileRouter;
Downloads file --mime-type Speedtest\ Results\ Export-2023_07_31.csv
Speedtest Results Export-2023_07_31.csv: text/plain
Downloads file --mime-type Speedtest\ Results\ Export-2023_07_31.csv
Speedtest Results Export-2023_07_31.csv: text/plain
<Error><Code>AccessDenied</Code><Message>Invalid according to Policy: Policy Condition failed: ["eq", "$Content-Type", "text/csv"]</Message><RequestId>JEZTTVM0B2KSBX4R</RequestId><HostId>PgY/8AqUcarif231bRI5/ppS46NG4/NLhxAGPF0EwzC0Kff2yTJF4/xWwgKTxMg8JPHaDc36avE=</HostId></Error>
3 replies
TTCTheo's Typesafe Cult
Created by troy on 7/25/2023 in #questions
next auth vercel
Trying to deploy an app on vercel that use getServerSideProps, code seems to work fine on development but failing after deployment, doesn't seem to be finding the session i tried setting all the required ENV varaibles, could anyone assist?!
export const getServerSideProps: GetServerSideProps<{ user: User }> = async (context) => {
const session = await getServerAuthSession(context)

if (!session) {
return {
redirect: {
destination: '/?errorMessage=session',
permanent: false,
},
}
}

const data = await prisma.orgUsers.findUnique({
where: {
orgId_userId: {
orgId: context.params?.id as string,
userId: session.user.id
}
}
})

if (!data || data.role != 'ADMIN') {
return {
redirect: {
destination: '/?errorMessage=notAdmin',
permanent: false,
},
}
}

return {
props: {
user: session.user
},
}
}
export const getServerSideProps: GetServerSideProps<{ user: User }> = async (context) => {
const session = await getServerAuthSession(context)

if (!session) {
return {
redirect: {
destination: '/?errorMessage=session',
permanent: false,
},
}
}

const data = await prisma.orgUsers.findUnique({
where: {
orgId_userId: {
orgId: context.params?.id as string,
userId: session.user.id
}
}
})

if (!data || data.role != 'ADMIN') {
return {
redirect: {
destination: '/?errorMessage=notAdmin',
permanent: false,
},
}
}

return {
props: {
user: session.user
},
}
}
4 replies