fix: some prisma shenanigans

This commit is contained in:
2025-03-23 00:43:54 +01:00
parent f2c0abbcdc
commit ede61678aa
26 changed files with 65 additions and 7397 deletions

View File

@@ -6,6 +6,7 @@
"dev": "tsx watch src/index.ts"
},
"dependencies": {
"@hctv/auth": "*",
"@hctv/db": "*",
"@hono/node-server": "^1.14.0",
"@hono/node-ws": "^1.1.0",

View File

@@ -2,6 +2,8 @@ import { serve } from '@hono/node-server'
import { createNodeWebSocket } from '@hono/node-ws'
import { Hono } from 'hono'
import { readFile } from 'node:fs/promises'
import { lucia } from '@hctv/auth'
import { getCookie } from 'hono/cookie'
const threed = await readFile('./src/3d.txt', 'utf-8')
@@ -19,6 +21,18 @@ app.get(
}))
)
app.get('/authed', async (c) => {
const token = getCookie(c, 'auth_session')
if (!token) {
return c.text('Unauthorized', 401)
}
const { user } = await lucia.validateSession(token)
if (!user) {
return c.text('Unauthorized', 401)
}
return c.json(user)
})
serve({
fetch: app.fetch,
port: 8000,

View File

@@ -4,7 +4,7 @@
"private": true,
"scripts": {
"dd": "docker compose --file ../../dev/docker-compose.yml up -d",
"dev": "next dev",
"dev": "next dev --turbo",
"donly": "docker compose --file ../../dev/docker-compose.yml up",
"build": "next build",
"start": "next start",

View File

@@ -1,5 +1,5 @@
import LiveStream from "@/components/app/Livestream/Livestream";
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
export default async function Page({ params }: { params: Promise<{ username: string }> }) {
const { username } = await params;

View File

@@ -1,4 +1,4 @@
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
import { NextRequest } from 'next/server';
export async function POST(request: NextRequest) {

View File

@@ -1,5 +1,5 @@
import { validateRequest } from '@/lib/auth/validate';
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
import { NextRequest } from "next/server";
export async function POST(request: NextRequest) {

View File

@@ -1,5 +1,5 @@
import { lucia } from '@hctv/auth';
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
import { resolveUserPersonalChannel } from '@/lib/db/resolve';
import type { WebSocket } from 'ws';

View File

@@ -1,5 +1,5 @@
import { validateRequest } from '@/lib/auth/validate';
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
import { NextRequest } from 'next/server';
export async function GET(request: NextRequest) {

View File

@@ -1,5 +1,5 @@
import { validateRequest } from '@/lib/auth/validate';
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
import type { NextRequest } from 'next/server';
export async function GET(request: NextRequest) {

View File

@@ -2,7 +2,7 @@ import { slack, lucia } from '@hctv/auth';
import { cookies as nextCookies } from 'next/headers';
import { decodeIdToken, OAuth2RequestError } from 'arctic';
import { generateIdFromEntropySize } from 'lucia';
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
export async function GET(request: Request): Promise<Response> {
const cookies = await nextCookies();

View File

@@ -2,7 +2,7 @@ import LandingPage from '@/components/app/LandingPage/LandingPage';
import { Card, CardContent } from '@/components/ui/card';
import ConfusedDino from '@/components/ui/confuseddino';
import { validateRequest } from '@/lib/auth/validate';
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
import { Avatar, AvatarImage, AvatarFallback } from '@radix-ui/react-avatar';
import Image from 'next/image';
import Link from 'next/link';

View File

@@ -1,5 +1,5 @@
import { validateRequest } from '@/lib/auth/validate';
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
import EditLivestreamDialog from './dialog';
export default async function EditLivestream() {

View File

@@ -1,7 +1,8 @@
'use server';
import { cookies } from 'next/headers';
import { lucia, validateRequest } from '.';
import { lucia } from '@hctv/auth';
import { validateRequest } from '@/lib/auth/validate';
import { redirect } from 'next/navigation';
export async function logout() {

View File

@@ -1,39 +0,0 @@
import { PrismaAdapter } from '@lucia-auth/adapter-prisma';
import { Lucia } from 'lucia';
import prisma from '@hctv/db';
import { Slack } from 'arctic';
const adapter = new PrismaAdapter(prisma.session, prisma.user);
export const slack = new Slack(process.env.SLACK_ID!, process.env.SLACK_SECRET!, process.env.SLACK_REDIRECT_URI!);
export const lucia = new Lucia(adapter, {
sessionCookie: {
// this sets cookies with super long expiration
// since Next.js doesn't allow Lucia to extend cookie expiration when rendering pages
expires: false,
attributes: {
// set to `true` when using HTTPS
secure: process.env.NODE_ENV === 'production',
},
},
getUserAttributes: (attributes) => {
return {
slack_id: attributes.slack_id,
pfpUrl: attributes.pfpUrl,
hasOnboarded: attributes.hasOnboarded,
};
},
});
declare module 'lucia' {
interface Register {
Lucia: typeof lucia;
DatabaseUserAttributes: DatabaseUserAttributes;
}
}
interface DatabaseUserAttributes {
slack_id: string;
pfpUrl: string;
hasOnboarded: boolean;
}

View File

@@ -1,5 +1,5 @@
import { validateRequest } from '@/lib/auth/validate';
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
export async function getPersonalChannel(id?: string) {
const { user } = await validateRequest();

View File

@@ -2,7 +2,7 @@
import { revalidatePath } from 'next/cache';
import { validateRequest } from '@/lib/auth/validate';
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
import zodVerify from '../zodVerify';
import { onboardSchema, streamInfoEditSchema } from './zod';
import { initializeStreamInfo } from '../instrumentation/streamInfo';

View File

@@ -1,4 +1,4 @@
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
import { HttpFlv } from '../types/liveBackendJson';
export default async function runner() {

View File

@@ -4,6 +4,7 @@
"exports": {
".": "./src/index.ts"
},
"type": "module",
"dependencies": {
"@hctv/db": "*",
"@lucia-auth/adapter-prisma": "^4.0.1",

View File

@@ -1,6 +1,6 @@
import { PrismaAdapter } from '@lucia-auth/adapter-prisma';
import { Lucia } from 'lucia';
import prisma from '@hctv/db';
import { prisma } from '@hctv/db';
import { Slack } from 'arctic';
const adapter = new PrismaAdapter(prisma.session, prisma.user);

View File

@@ -2,8 +2,12 @@
"name": "@hctv/db",
"version": "0.0.0",
"exports": {
".": "./src/index.ts"
".": {
"types": "./src/index.d.ts",
"default": "./src/index.ts"
}
},
"type": "module",
"dependencies": {
"@prisma/client": "^6.5.0",
"prisma": "^6.5.0"
@@ -11,6 +15,10 @@
"scripts": {
"db:generate": "prisma generate",
"db:migrate": "prisma migrate dev",
"db:deploy": "prisma migrate deploy"
"db:deploy": "prisma migrate deploy",
"build": "tsc"
},
"devDependencies": {
"typescript": "^5.8.2"
}
}

View File

@@ -1,4 +1,4 @@
import { PrismaClient } from "../generated/client";
import { PrismaClient } from "../generated/client/default.js";
const globalForPrisma = global as unknown as { prisma: PrismaClient };

View File

@@ -1,7 +1,4 @@
// from https://www.prisma.io/docs/guides/turborepo
import { prisma } from './client'
export { prisma } from './client' // exports instance of prisma
export * from "../generated/client" // exports generated types from prisma
export default prisma;
export { prisma } from './client.js' // exports instance of prisma
export * from "../generated/client/default.js" // exports generated types from prisma

18
packages/db/tsconfig.json Normal file
View File

@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"outDir": "dist",
"declaration": true,
"sourceMap": true,
"resolveJsonModule": true,
"rootDir": "src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}

7333
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -17,7 +17,7 @@
"dependsOn": ["^check-types"]
},
"dev": {
"dependsOn": ["dd", "db:generate"],
"dependsOn": ["dd", "^db:generate"],
"persistent": true,
"cache": false
},

View File

@@ -5206,7 +5206,7 @@ typed-emitter@^2.1.0:
optionalDependencies:
rxjs "^7.5.2"
typescript@^5:
typescript@^5, typescript@^5.8.2:
version "5.8.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.8.2.tgz#8170b3702f74b79db2e5a96207c15e65807999e4"
integrity sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==