Skip to content

Commit

Permalink
Migrate to SvelteKit v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Yureien committed Mar 29, 2024
1 parent b0e6d9c commit 3b0ab45
Show file tree
Hide file tree
Showing 11 changed files with 1,010 additions and 580 deletions.
60 changes: 31 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,43 @@
"postinstall": "prisma generate --schema=./src/lib/server/prisma/schema.prisma"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/adapter-node": "^1.2.4",
"@sveltejs/adapter-vercel": "^3.0.3",
"@sveltejs/kit": "^1.5.0",
"@types/node-cron": "^3.0.7",
"@types/nodemailer": "^6.4.11",
"@types/prismjs": "^1.26.0",
"@types/sanitize-html": "^2.9.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"autoprefixer": "^10.4.14",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.26.0",
"postcss": "^8.4.31",
"prettier": "3.1.1",
"prettier-plugin-svelte": "3.1.2",
"prisma": "^4.15.0",
"svelte": "^3.54.0",
"svelte-check": "^3.0.1",
"svelte-select": "^5.6.1",
"tailwindcss": "^3.3.2",
"@sveltejs/adapter-auto": "^3.2.0",
"@sveltejs/adapter-node": "^5.0.1",
"@sveltejs/adapter-vercel": "^5.2.0",
"@sveltejs/kit": "^2.5.5",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@types/node-cron": "^3.0.11",
"@types/nodemailer": "^6.4.14",
"@types/prismjs": "^1.26.3",
"@types/sanitize-html": "^2.11.0",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"autoprefixer": "^10.4.19",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"postcss": "^8.4.38",
"postcss-import": "^16.1.0",
"prettier": "3.2.5",
"prettier-plugin-svelte": "3.2.2",
"prisma": "^5.11.0",
"svelte": "^4.2.12",
"svelte-check": "^3.6.8",
"svelte-select": "^5.8.3",
"tailwindcss": "^3.4.3",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^4.5.2"
"typescript": "^5.4.3",
"vite": "^5.2.7"
},
"type": "module",
"dependencies": {
"@prisma/client": "^4.15.0",
"@prisma/client": "^5.11.0",
"base64-js": "^1.5.1",
"nanoid": "^5.0.1",
"node-cron": "^3.0.2",
"nodemailer": "^6.9.5",
"nanoid": "^5.0.6",
"node-cron": "^3.0.3",
"nodemailer": "^6.9.13",
"prism-themes": "^1.9.0",
"prismjs": "^1.29.0",
"sanitize-html": "^2.10.0"
"sanitize-html": "^2.13.0"
}
}
4 changes: 2 additions & 2 deletions src/lib/server/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function getPaste(key: string) {
},
});

if (!data) throw error(404, 'Not found');
if (!data) error(404, 'Not found');

data = await prisma.paste.update({
where: { key },
Expand All @@ -26,7 +26,7 @@ export async function getPaste(key: string) {
const { expiresCount, readCount } = data;
if (expiresCount !== null && expiresCount < readCount) {
await prisma.paste.delete({ where: { key } });
throw error(404, 'Not found');
error(404, 'Not found');
}

const {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(auth)/forgot-password/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { sendResetEmail } from '$lib/server/email/reset-password';

export const load: PageServerLoad = async () => {
if (env.MAIL_ENABLED === 'false') {
throw redirect(303, '/');
redirect(303, '/');
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/routes/(auth)/login/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getUserIdFromCookie } from '$lib/server/auth';

export const load: PageServerLoad = async ({ cookies }) => {
const userId = await getUserIdFromCookie(cookies);
if (userId) throw redirect(303, '/');
if (userId) redirect(303, '/');
};
export const actions: Actions = {
default: async ({ cookies, request }) => {
Expand Down Expand Up @@ -78,6 +78,6 @@ export const actions: Actions = {
sameSite: 'strict',
});

throw redirect(303, '/');
redirect(303, '/');
},
};
6 changes: 3 additions & 3 deletions src/routes/(auth)/logout/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { redirect, type Actions } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ cookies }) => {
cookies.delete('token');
throw redirect(303, '/');
/* @migration task: add path argument */ cookies.delete('token');
redirect(303, '/');
};

export const actions: Actions = {
default({ cookies }) {
cookies.delete('token');
throw redirect(303, '/');
redirect(303, '/');
},
};
2 changes: 1 addition & 1 deletion src/routes/(auth)/register/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const actions: Actions = {
sameSite: 'strict',
});

throw redirect(303, '/');
redirect(303, '/');
}

return { success: false, errors: ['Unknown error'] };
Expand Down
12 changes: 6 additions & 6 deletions src/routes/(auth)/reset-password/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const load: PageServerLoad = async ({ url }) => {
const token = url.searchParams.get('token');

if (!userId || !token) {
throw error(404, 'Not found');
error(404, 'Not found');
}

const user = await prisma.user.findUnique({ where: { id: userId } });
Expand All @@ -20,21 +20,21 @@ export const load: PageServerLoad = async ({ url }) => {
});

if (!user || !resetToken) {
throw error(404, 'Not found');
error(404, 'Not found');
}

if (resetToken.expiresAt <= new Date()) {
throw error(404, 'Expired link');
error(404, 'Expired link');
}
};

export const actions: Actions = {
default: async ({ url, request }) => {
const userId = url.searchParams.get('userId');
if (!userId) throw error(404, 'Not found');
if (!userId) error(404, 'Not found');

const user = await prisma.user.findUnique({ where: { id: userId } });
if (!user) throw error(404, 'Not found');
if (!user) error(404, 'Not found');

const data = await request.formData();
const newPassword = data.get('new-password');
Expand Down Expand Up @@ -80,7 +80,7 @@ export const actions: Actions = {
data: { password: newPasswordHash },
});
await prisma.resetToken.delete({ where: { userId: userId } });
throw redirect(303, '/login');
redirect(303, '/login');
}

return { success: false, errors: ['Unknown error'] };
Expand Down
6 changes: 3 additions & 3 deletions src/routes/(auth)/validate/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const load: PageServerLoad = async ({ url }) => {
const hash = url.searchParams.get('hash');

if (!userId || !hash) {
throw error(404, 'Not found');
error(404, 'Not found');
}

const isValid = await validateVerificationHash(
Expand All @@ -16,8 +16,8 @@ export const load: PageServerLoad = async ({ url }) => {
);

if (!isValid) {
throw error(404, 'Not found');
error(404, 'Not found');
}

throw redirect(303, '/login');
redirect(303, '/login');
};
4 changes: 2 additions & 2 deletions src/routes/dashboard/settings/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { UserSettings } from '$lib/types';

export const load: PageServerLoad = async ({ cookies }) => {
const userId = await getUserIdFromCookie(cookies);
if (!userId) throw redirect(303, '/login');
if (!userId) redirect(303, '/login');

const user = await prisma.user.findUnique({
where: { id: userId },
Expand All @@ -19,7 +19,7 @@ export const load: PageServerLoad = async ({ cookies }) => {
export const actions: Actions = {
defaults: async ({ cookies, request }) => {
const userId = await getUserIdFromCookie(cookies);
if (!userId) throw redirect(303, '/login');
if (!userId) redirect(303, '/login');

const formData = await request.formData();
const expiresAfterSeconds = parseInt(
Expand Down
2 changes: 1 addition & 1 deletion svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import adapter from '@sveltejs/adapter-node';
import adapterVercel from '@sveltejs/adapter-vercel';
import { vitePreprocess } from '@sveltejs/kit/vite';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/adapter-vercel').Config} */
export const adapterVercelConfig = {
Expand Down
Loading

0 comments on commit 3b0ab45

Please sign in to comment.