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