diff --git a/src/lib/types.d.ts b/src/lib/types.d.ts index bb9db56..cd46332 100644 --- a/src/lib/types.d.ts +++ b/src/lib/types.d.ts @@ -1,2 +1,7 @@ export type Question = { id: number; question: string }; export type LocalDoor = { room1_id: number; room2_id: number }; +export type DefinitionDashMap = { + id: number; + data: string; + doors: LocalDoor[]; +}; diff --git a/src/routes/(app)/+layout.server.ts b/src/routes/(app)/+layout.server.ts index 340f534..4afff7d 100644 --- a/src/routes/(app)/+layout.server.ts +++ b/src/routes/(app)/+layout.server.ts @@ -2,15 +2,11 @@ import type { LayoutServerLoad } from "./$types"; import type { User } from "@prisma/client"; import { getMapFor } from "$lib/get-map-for"; import prisma from "$lib/prisma"; +import type { DefinitionDashMap } from "$lib/types"; -type Map = { - id: number; - data: string; - doors: { room1_id: number; room2_id: number }[]; -}; type Props = { user: User; - map?: Map; + map?: DefinitionDashMap; }; export const load: LayoutServerLoad = async ({ locals }) => { const data: Props = { diff --git a/src/routes/login/callback/+server.ts b/src/routes/login/callback/+server.ts index 5873796..bd5c78e 100644 --- a/src/routes/login/callback/+server.ts +++ b/src/routes/login/callback/+server.ts @@ -4,7 +4,6 @@ import { OAuth2Client } from "google-auth-library"; import { PUBLIC_GOOGLE_CLIENT_ID } from "$env/static/public"; import { ALLOWED_DOMAIN } from "$env/static/private"; import prisma from "$lib/prisma"; -import type { School, User } from "@prisma/client"; import { toBuffer } from "uuid-buffer"; import { dev } from "$app/environment"; import { SESSION_COOKIE_KEY, SESSION_DURATION_DAYS } from "$lib/constants"; @@ -30,17 +29,20 @@ export const POST: RequestHandler = async ({ request, cookies }) => { throw error(400, "Failed to verify ID token"); } - let user: User | null = await prisma.user.findFirst({ + let user: { id: number } | null = await prisma.user.findFirst({ where: { google_sub: payload.sub }, + select: { id: true }, }); if (!user) { const domain = payload.hd || ALLOWED_DOMAIN; - let school: School | null = await prisma.school.findUnique({ + let school: { id: number } | null = await prisma.school.findUnique({ where: { domain }, + select: { id: true }, }); if (!school) { school = await prisma.school.create({ data: { domain }, + select: { id: true }, }); } user = await prisma.user.create({ @@ -49,9 +51,10 @@ export const POST: RequestHandler = async ({ request, cookies }) => { google_sub: payload.sub, allowed: payload.hd === ALLOWED_DOMAIN, }, + select: { id: true }, }); } - user = await prisma.user.update({ + await prisma.user.update({ where: { id: user.id, },