improve typings on "getting started" (#554)

This commit is contained in:
Alex Johansson 2021-09-03 09:45:57 +02:00 committed by GitHub
parent 0953c6b541
commit adff0d0176
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
import Head from "next/head"; import Head from "next/head";
import prisma from "@lib/prisma"; import prisma from "@lib/prisma";
import { getSession, useSession } from "next-auth/client"; import { useSession } from "next-auth/client";
import { import {
EventTypeCreateInput, EventTypeCreateInput,
ScheduleCreateInput, ScheduleCreateInput,
@ -30,6 +30,7 @@ import { Integration } from "pages/integrations";
import { AddCalDavIntegrationRequest } from "../lib/integrations/CalDav/components/AddCalDavIntegration"; import { AddCalDavIntegrationRequest } from "../lib/integrations/CalDav/components/AddCalDavIntegration";
import classnames from "classnames"; import classnames from "classnames";
import { ArrowRightIcon } from "@heroicons/react/outline"; import { ArrowRightIcon } from "@heroicons/react/outline";
import { getSession } from "@lib/auth";
const DEFAULT_EVENT_TYPES = [ const DEFAULT_EVENT_TYPES = [
{ {
@ -610,16 +611,21 @@ export default function Onboarding(props: OnboardingProps) {
export async function getServerSideProps(context: NextPageContext) { export async function getServerSideProps(context: NextPageContext) {
const session = await getSession(context); const session = await getSession(context);
let user: User = null;
let integrations = []; let integrations = [];
let credentials = []; let credentials = [];
let eventTypes = []; let eventTypes = [];
let schedules = []; let schedules = [];
if (!session?.user?.id) {
if (session) { return {
user = await prisma.user.findFirst({ redirect: {
permanent: false,
destination: "/auth/login",
} as const,
};
}
const user = await prisma.user.findFirst({
where: { where: {
email: session.user.email, id: session.user.id,
}, },
select: { select: {
id: true, id: true,
@ -634,6 +640,9 @@ export async function getServerSideProps(context: NextPageContext) {
completedOnboarding: true, completedOnboarding: true,
}, },
}); });
if (!user) {
throw new Error(`Signed in as ${session.user.id} but cannot be found in db`);
}
if (user.completedOnboarding) { if (user.completedOnboarding) {
return { return {
@ -712,7 +721,6 @@ export async function getServerSideProps(context: NextPageContext) {
id: true, id: true,
}, },
}); });
}
return { return {
props: { props: {