Lucia Authentication #8

Merged
DanMihailescu merged 18 commits from undoPretty into master 2024-12-19 20:06:45 -05:00
11 changed files with 108 additions and 72 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -52,6 +52,7 @@
"vitest": "^2.0.4"
},
"dependencies": {
"@lucia-auth/adapter-prisma": "^4.0.1",
"@pothos/core": "^4.3.0",
"@pothos/plugin-prisma": "^4.4.0",
"@prisma/client": "6.0.1",
@ -59,9 +60,11 @@
"dayjs": "^1.11.13",
"graphql": "^16.9.0",
"graphql-yoga": "^5.10.4",
"lucia": "^3.2.2",
"oslo": "^1.2.1",
"pino": "^9.5.0",
"pino-pretty": "^13.0.0",
"tailwind-merge": "^2.5.5",
"zod": "^3.24.0"
}
}
}

Binary file not shown.

View file

@ -1,19 +0,0 @@
-- CreateTable
CREATE TABLE "User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"email" TEXT NOT NULL,
"name" TEXT
);
-- CreateTable
CREATE TABLE "Post" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"title" TEXT NOT NULL,
"content" TEXT,
"published" BOOLEAN NOT NULL DEFAULT false,
"authorId" INTEGER NOT NULL,
CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

View file

@ -1,37 +0,0 @@
/*
Warnings:
- Made the column `content` on table `Post` required. This step will fail if there are existing NULL values in that column.
- Made the column `name` on table `User` required. This step will fail if there are existing NULL values in that column.
*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Post" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"title" TEXT NOT NULL,
"content" TEXT NOT NULL,
"published" BOOLEAN DEFAULT false,
"authorId" INTEGER NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Post" ("authorId", "content", "id", "published", "title") SELECT "authorId", "content", "id", "published", "title" FROM "Post";
DROP TABLE "Post";
ALTER TABLE "new_Post" RENAME TO "Post";
CREATE TABLE "new_User" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"email" TEXT,
"name" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO "new_User" ("email", "id", "name") SELECT "email", "id", "name" FROM "User";
DROP TABLE "User";
ALTER TABLE "new_User" RENAME TO "User";
CREATE UNIQUE INDEX "User_id_key" ON "User"("id");
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View file

@ -0,0 +1,24 @@
/*
Warnings:
- The primary key for the `Post` table will be changed. If it partially fails, the table could be left without primary key constraint.
*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Post" (
"id" TEXT NOT NULL PRIMARY KEY,
"title" TEXT NOT NULL,
"content" TEXT NOT NULL,
"published" BOOLEAN DEFAULT false,
"authorId" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Post" ("authorId", "content", "createdAt", "id", "published", "title", "updatedAt") SELECT "authorId", "content", "createdAt", "id", "published", "title", "updatedAt" FROM "Post";
DROP TABLE "Post";
ALTER TABLE "new_Post" RENAME TO "Post";
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View file

@ -15,21 +15,34 @@ datasource db {
}
model User {
id Int @id @default(autoincrement()) @unique
email String? @unique
id String @id @default(uuid())
email String? @unique
name String
password String
posts Post[]
sessions Session[]
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}
model Session {
id String @id @default(uuid())
expiresAt DateTime
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
userId String
user User @relation(references: [id], fields: [userId])
}
BenjaminPalko commented 2024-12-17 14:10:51 -05:00 (Migrated from github.com)
Review

NIT: references and fields is backwards from how post shows it, can we keep them consistent

NIT: references and fields is backwards from how post shows it, can we keep them consistent
model Post {
id Int @id @default(autoincrement())
id String @id @default(uuid())
title String
content String
published Boolean? @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
author User @relation(references: [id], fields: [authorId])
authorId String
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
}

6
src/app.d.ts vendored
View file

@ -2,8 +2,12 @@
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
interface Locals {
user: import("lucia").User | null;
session: import('lucia').Session | null;
}
// interface PageData {}
// interface PageState {}
// interface Platform {}

31
src/lib/server/lucia.ts Normal file
View file

@ -0,0 +1,31 @@
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
import { Lucia } from 'lucia';
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
import { PrismaAdapter } from '@lucia-auth/adapter-prisma';
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
import { prisma } from '$lib/server/prisma';
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
const adapter = new PrismaAdapter(prisma.session, prisma.user);
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
// expect error (see next section)
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
export const auth = new Lucia(adapter, {
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
sessionCookie: {
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
attributes: {
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
secure: process.env.NODE_ENV === 'production'
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
}
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
},
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
getUserAttributes: (attributes) => {
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
return {
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
email: attributes.email
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
};
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
}
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
});
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
declare module 'lucia' {
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
interface Register {
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
Lucia: typeof Lucia;
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
DatabaseUserAttributes: DatabaseUserAttributes;
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
}
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
}
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
interface DatabaseUserAttributes {
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
email: string;
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
}
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...
export type Auth = typeof auth;
BenjaminPalko commented 2024-12-17 14:11:26 -05:00 (Migrated from github.com)
Review

Reuse the $lib/server/prisma client plz

Reuse the `$lib/server/prisma` client plz
BenjaminPalko commented 2024-12-18 12:33:08 -05:00 (Migrated from github.com)
Review

You dont need to set it to a const...

You dont need to set it to a const...

View file

@ -1,18 +1,17 @@
BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls
BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls
import { prisma } from '$lib/server/prisma';
BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls
export async function load(event) {
const userId = event.cookies.get('user');
if (!userId && isNaN(Number(userId))) {
BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls
if (!userId) {
BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls
return {
authenticated: false
};
}
const user = await prisma.user.findUnique({
where: {
id: Number(userId)
BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls
id: userId
BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls
}
});
return {
authenticated: !!user
};
}
BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls
}
BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls

BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls
BenjaminPalko commented 2024-12-17 14:14:38 -05:00 (Migrated from github.com)
Review

I dont think you can type event as a a Session, from the app typedefs you made it should be event.locals.[session or user idk]

I dont think you can type event as a a Session, from the app typedefs you made it should be _event.locals.[session or user idk]_
BenjaminPalko commented 2024-12-17 14:14:57 -05:00 (Migrated from github.com)
Review
https://github.com/Machinata/hestia/pull/8/files#diff-b07092d78bfaa239d6ad0d01b0897c3ef49533b08512622d83c6f4e1dd3b363e
DanMihailescu commented 2024-12-18 10:07:50 -05:00 (Migrated from github.com)
Review

switched back to any type

switched back to any type
BenjaminPalko commented 2024-12-18 12:34:07 -05:00 (Migrated from github.com)
Review

Use the logger pls

Use the logger pls

View file

@ -1,6 +1,8 @@
import { logger } from '$lib/server/logger';
import { prisma } from '$lib/server/prisma';
import { error, redirect, type Actions } from '@sveltejs/kit';
import { Argon2id } from 'oslo/password';
import { auth } from '$lib/server/lucia.js';
export const actions = {
login: async (event) => {
@ -17,30 +19,46 @@ export const actions = {
logger.error('User not found! ${user}');
return error(401);
}
event.cookies.set('user', String(user.id), {
const password = form.get('password') as string;
if (!password) {
return error(401, 'Password is required');
}
const validPassword = await new Argon2id().verify(user.password, password);
if (!validPassword) {
return error(400, 'Password is incorrect!');
}
const session = await auth.createSession(user.id, []);
const sessionCookie = auth.createSessionCookie(session.id);
event.cookies.set(sessionCookie.name, sessionCookie.value, {
path: '/',
maxAge: 120
});
redirect(302, '/');
},
register: async (event) => {
const form = await event.request.formData();
if (!form.has('email') || !form.has('name')) {
if (!form.has('email') || !form.has('name') || !form.has('password')) {
return error(400);
}
const password = form.get('password') as string;
const hashedPassword = await new Argon2id().hash(password);
const user = await prisma.user.create({
data: {
email: form.get('email') as string,
name: form.get('name') as string
name: form.get('name') as string,
password: hashedPassword
}
});
const session = await auth.createSession(user.id.toString(), {});
const sessionCookie = auth.createSessionCookie(session.id);
if (!user) {
return error(500);
}
event.cookies.set('user', String(user.id), {
event.cookies.set(sessionCookie.name, sessionCookie.value, {
path: '/',
maxAge: 120
});
redirect(302, '/');
}
} satisfies Actions;
} satisfies Actions;