Fix/user creds (#8393)

* fix-user-creds

* Type fixes

* Type fixes

* Type fixes

---------

Co-authored-by: Alex van Andel <me@alexvanandel.com>
This commit is contained in:
alannncandAlex van Andel authored and GitHub committed 2023-04-20 15:55:19 +00:00
1 parent c1c95f711b
commit fe996b4e41
13 files changed
+92 -39

No files matched your search

@@ -18,7 +18,7 @@ export const getStaticProps: GetStaticProps<
{ user: string }
> = async (context) => {
const { user: username, month } = paramsSchema.parse(context.params);
const user = await prisma.user.findUnique({
const userWithCredentials = await prisma.user.findUnique({
where: {
username,
},
@@ -34,14 +34,15 @@ export const getStaticProps: GetStaticProps<
).startOf("day");
const endDate = startDate.endOf("month");
try {
const results = user?.credentials
const results = userWithCredentials?.credentials
? await getCachedResults(
user?.credentials,
userWithCredentials?.credentials,
startDate.format(),
endDate.format(),
user?.selectedCalendars
userWithCredentials?.selectedCalendars
)
: [];
return {
props: { results, date: new Date().toISOString() },
revalidate: 1,
+4 -4
View File
@@ -14,7 +14,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return;
}
const user = await prisma.user.findUnique({
const userWithCredentials = await prisma.user.findUnique({
where: {
id: session.user.id,
},
@@ -25,11 +25,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
selectedCalendars: true,
},
});
if (!user) {
if (!userWithCredentials) {
res.status(401).json({ message: "Not authenticated" });
return;
}
const { credentials, ...user } = userWithCredentials;
if (req.method === "POST") {
await prisma.selectedCalendar.upsert({
@@ -80,7 +80,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
// get user's credentials + their connected integrations
const calendarCredentials = getCalendarCredentials(user.credentials);
const calendarCredentials = getCalendarCredentials(credentials);
// get all the connected integrations' calendars (from third party)
const { connectedCalendars } = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);
const calendars = connectedCalendars.flatMap((c) => c.calendars).filter(notEmpty);
@@ -54,7 +54,6 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
user: {
select: {
id: true,
credentials: true,
timeZone: true,
email: true,
name: true,
-1
View File
@@ -282,7 +282,6 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
user: {
select: {
id: true,
credentials: true,
timeZone: true,
name: true,
email: true,