fixes
This commit is contained in:
parent
4afc8a9efa
commit
dd0d3126fe
8 changed files with 46 additions and 34 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
|
@ -3,10 +3,10 @@
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun validate-env && bun database:up && bun prisma:generate && bun prisma:push && vite dev",
|
"dev": "bun validate-env && bun database:up && bun prisma:generate && vite dev",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"build-storybook": "storybook build",
|
"build-storybook": "storybook build",
|
||||||
"database:up": "docker compose -p hestia -f devops/docker-compose.dev.yml up -d && docker compose -p hestia -f devops/docker-compose.dev.yml -f devops/docker-compose.wait.yml run --rm wait -c hestia-database:5432",
|
"database:up": "docker compose -p hestia -f devops/docker-compose.dev.yml up -d && docker compose -p hestia -f devops/docker-compose.dev.yml -f devops/docker-compose.wait.yml run --rm wait -c hestia-database:5432 && bun prisma:push",
|
||||||
"database:down": "docker compose -p hestia -f devops/docker-compose.dev.yml down",
|
"database:down": "docker compose -p hestia -f devops/docker-compose.dev.yml down",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
|
|
@ -65,8 +65,7 @@
|
||||||
"vitest": "^2.0.4"
|
"vitest": "^2.0.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@clerk/clerk-js": "^5.43.4",
|
"@clerk/backend": "1.21.4",
|
||||||
"@clerk/express": "^1.3.31",
|
|
||||||
"@clerk/themes": "^2.2.3",
|
"@clerk/themes": "^2.2.3",
|
||||||
"@flaticon/flaticon-uicons": "^3.3.1",
|
"@flaticon/flaticon-uicons": "^3.3.1",
|
||||||
"@inlang/paraglide-sveltekit": "^0.15.0",
|
"@inlang/paraglide-sveltekit": "^0.15.0",
|
||||||
|
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
/*
|
|
||||||
Warnings:
|
|
||||||
|
|
||||||
- You are about to drop the column `password` on the `User` table. All the data in the column will be lost.
|
|
||||||
- You are about to drop the `Session` table. If the table is not empty, all the data it contains will be lost.
|
|
||||||
|
|
||||||
*/
|
|
||||||
-- DropForeignKey
|
|
||||||
ALTER TABLE "Session" DROP CONSTRAINT "Session_userId_fkey";
|
|
||||||
|
|
||||||
-- DropIndex
|
|
||||||
DROP INDEX "User_email_key";
|
|
||||||
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE "User" DROP COLUMN "password";
|
|
||||||
|
|
||||||
-- DropTable
|
|
||||||
DROP TABLE "Session";
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
/*
|
|
||||||
Warnings:
|
|
||||||
|
|
||||||
- Added the required column `clerkId` to the `User` table without a default value. This is not possible if the table is not empty.
|
|
||||||
|
|
||||||
*/
|
|
||||||
-- AlterTable
|
|
||||||
ALTER TABLE "User" ADD COLUMN "clerkId" TEXT NOT NULL;
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `password` on the `User` table. All the data in the column will be lost.
|
||||||
|
- You are about to drop the `Session` table. If the table is not empty, all the data it contains will be lost.
|
||||||
|
- A unique constraint covering the columns `[clerkId]` on the table `User` will be added. If there are existing duplicate values, this will fail.
|
||||||
|
- Added the required column `clerkId` to the `User` table without a default value. This is not possible if the table is not empty.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "Session" DROP CONSTRAINT "Session_userId_fkey";
|
||||||
|
|
||||||
|
-- DropIndex
|
||||||
|
DROP INDEX "User_email_key";
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "User" DROP COLUMN "password",
|
||||||
|
ADD COLUMN "clerkId" TEXT NOT NULL;
|
||||||
|
|
||||||
|
-- DropTable
|
||||||
|
DROP TABLE "Session";
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "User_clerkId_key" ON "User"("clerkId");
|
||||||
|
|
@ -16,7 +16,7 @@ datasource db {
|
||||||
|
|
||||||
model User {
|
model User {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
clerkId String
|
clerkId String @unique
|
||||||
|
|
||||||
email String?
|
email String?
|
||||||
name String
|
name String
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
import { redirect, type ServerLoadEvent } from '@sveltejs/kit';
|
import { redirect, type ServerLoadEvent } from '@sveltejs/kit';
|
||||||
import { prisma } from '../prisma';
|
import { prisma } from '../prisma';
|
||||||
import { createClerkClient } from '@clerk/express';
|
import { createClerkClient } from '@clerk/backend';
|
||||||
import { CLERK_SECRET_KEY } from '$env/static/private';
|
import { CLERK_SECRET_KEY } from '$env/static/private';
|
||||||
import { clerkClient } from 'clerk-sveltekit/server';
|
import { clerkClient } from 'clerk-sveltekit/server';
|
||||||
|
import { logger } from '$lib/server/logger';
|
||||||
|
|
||||||
const clerkSessionClient = createClerkClient({
|
const clerkSessionClient = createClerkClient({
|
||||||
secretKey: CLERK_SECRET_KEY,
|
secretKey: CLERK_SECRET_KEY,
|
||||||
});
|
});
|
||||||
|
|
||||||
export async function validateSession({ locals }: ServerLoadEvent) {
|
export async function validateSession({ locals }: ServerLoadEvent) {
|
||||||
if (!locals.auth.userId) {
|
if (!locals.auth.userId || !locals.auth.sessionId) {
|
||||||
return redirect(307, '/login');
|
return redirect(307, '/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,13 +29,24 @@ export async function validateSession({ locals }: ServerLoadEvent) {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
if (clerkUser.emailAddresses.length === 0) {
|
||||||
|
logger.error('User has no email address');
|
||||||
|
await clerkSessionClient.sessions.revokeSession(locals.auth.sessionId);
|
||||||
|
|
||||||
|
return redirect(307, '/login');
|
||||||
|
}
|
||||||
|
|
||||||
user = await prisma.user.create({
|
user = await prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
clerkId: clerkUser.id,
|
clerkId: clerkUser.id,
|
||||||
email: clerkUser.emailAddresses[0].emailAddress,
|
email: clerkUser.emailAddresses[0].emailAddress,
|
||||||
name: clerkUser.fullName ?? 'Ben the Man',
|
name: clerkUser.fullName ?? '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (clerkUser.fullName === null) {
|
||||||
|
logger.error('User has no name');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the active organization to the first one in the list, this is temporary until we let the user choose the organization
|
||||||
|
*/
|
||||||
try {
|
try {
|
||||||
// Set the active organization to the first one in the list
|
// Set the active organization to the first one in the list
|
||||||
await clerk.setActive({
|
await clerk.setActive({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue