improve typings on "getting started" (#554)
This commit is contained in:
parent
0953c6b541
commit
adff0d0176
1 changed files with 107 additions and 99 deletions
|
@ -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: {
|
||||
|
|
Loading…
Reference in a new issue