diff --git a/src/app.d.ts b/src/app.d.ts index 4353151..1562080 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -2,7 +2,7 @@ // for information about these interfaces // and what to do when importing types -import type { PrismaClient, User } from '@prisma/client'; +import type { User } from '@prisma/client'; type User = Omit; @@ -14,7 +14,6 @@ declare global { } interface Locals { auth: import('lucia').AuthRequest; - prisma: PrismaClient; user: Lucia.UserAttributes; startTimer: number; error: string; @@ -32,6 +31,11 @@ declare global { errorId?: string; } } + + interface Document { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + startViewTransition: (callback: any) => void; // Add your custom property/method here + } } // interface PageData {} diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 25d470c..f52e6af 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -16,12 +16,8 @@ export const authentication: Handle = async function ({ event, resolve }) { event.locals.auth = auth.handleRequest(event); if (event?.locals?.auth) { - console.log('auth not empty'); - console.log('auth', event.locals.auth); try { const session = await event.locals.auth.validate(); - console.log('user', session?.user); - console.log('session', JSON.stringify(session, null, 2)); event.locals.user = session?.user; // if (event.route.id?.startsWith('/(protected)')) { // if (!user) throw redirect(302, '/sign-in'); @@ -36,22 +32,5 @@ export const authentication: Handle = async function ({ event, resolve }) { return await resolve(event); }; -// This hook is used to pass our prisma instance to each action, load, and endpoint -// export const prisma: Handle = async function ({ event, resolve }) { -// try { -// const ip = event.request.headers.get('x-forwarded-for') as string; -// const country = event.request.headers.get('x-vercel-ip-country') as string; -// event.locals.prisma = prisma_client; -// event.locals.session = { -// ...event.locals.session, -// ip, -// country -// }; -// } catch (error) { -// console.error(error); -// } -// return await resolve(event); -// }; - export const handle: Handle = sequence(sequence(Sentry.sentryHandle(), authentication)); export const handleError = Sentry.handleErrorWithSentry(); \ No newline at end of file diff --git a/src/lib/page_loading_indicator.svelte b/src/lib/page_loading_indicator.svelte new file mode 100644 index 0000000..7b1f203 --- /dev/null +++ b/src/lib/page_loading_indicator.svelte @@ -0,0 +1,63 @@ + + +
+
+
+ + diff --git a/src/lib/server/lucia.ts b/src/lib/server/lucia.ts index 6da4c5c..f5be73f 100644 --- a/src/lib/server/lucia.ts +++ b/src/lib/server/lucia.ts @@ -5,8 +5,6 @@ import { prisma } from '@lucia-auth/adapter-prisma'; import { dev } from '$app/environment'; import prisma_client from '$lib/prisma'; -// export const prisma_client = new PrismaClient(); - export const auth = lucia({ env: dev ? 'DEV' : 'PROD', middleware: sveltekit(), diff --git a/src/lib/styles/app.pcss b/src/lib/styles/app.pcss index 7c93cee..6ed26cf 100644 --- a/src/lib/styles/app.pcss +++ b/src/lib/styles/app.pcss @@ -11,6 +11,7 @@ --popover: 0 0% 100%; --popover-foreground: 20 14.3% 4.1%; --primary: 47.9 95.8% 53.1%; + --primary-hex: #facc15; --primary-foreground: 26 83.3% 14.1%; --secondary: 60 4.8% 95.9%; --secondary-foreground: 24 9.8% 10%; diff --git a/src/routes/(app)/(protected)/admin/+layout.server.ts b/src/routes/(app)/(protected)/admin/+layout.server.ts index 51ade48..e40a706 100644 --- a/src/routes/(app)/(protected)/admin/+layout.server.ts +++ b/src/routes/(app)/(protected)/admin/+layout.server.ts @@ -1,5 +1,6 @@ import { redirect } from '@sveltejs/kit'; +import type { PageServerData } from './$types'; -export const load = async function ({ locals }) { +export const load: PageServerData = async function ({ locals }) { if (!locals?.user?.role?.includes('admin')) throw redirect(302, '/'); }; diff --git a/src/routes/(app)/(protected)/collection/+page.server.ts b/src/routes/(app)/(protected)/collection/+page.server.ts index 8f13710..61c8ea0 100644 --- a/src/routes/(app)/(protected)/collection/+page.server.ts +++ b/src/routes/(app)/(protected)/collection/+page.server.ts @@ -1,9 +1,9 @@ -import { error, fail, redirect } from '@sveltejs/kit'; +import { type Actions, error, fail, redirect } from "@sveltejs/kit"; import { superValidate } from 'sveltekit-superforms/server'; -import type { PageServerLoad } from '../../$types.js'; import prisma from '$lib/prisma'; import { modifyListGameSchema, type ListGame } from '$lib/config/zod-schemas.js'; import { search_schema } from '$lib/zodValidation.js'; +import type { PageServerLoad } from "./$types"; export const load: PageServerLoad = async ({ fetch, url, locals }) => { const session = await locals.auth.validate(); @@ -97,7 +97,7 @@ export const load: PageServerLoad = async ({ fetch, url, locals }) => { }; }; -export const actions = { +export const actions: Actions = { // Add game to a wishlist add: async (event) => { const { params, locals, request } = event; diff --git a/src/routes/(app)/(protected)/list/[id]/+page.server.ts b/src/routes/(app)/(protected)/list/[id]/+page.server.ts index 502cf87..13bece7 100644 --- a/src/routes/(app)/(protected)/list/[id]/+page.server.ts +++ b/src/routes/(app)/(protected)/list/[id]/+page.server.ts @@ -1,4 +1,4 @@ -import { fail, redirect } from '@sveltejs/kit'; +import { type Actions, fail, redirect } from "@sveltejs/kit"; import { superValidate } from 'sveltekit-superforms/server'; import prisma from '$lib/prisma'; @@ -40,7 +40,7 @@ export async function load({ params, locals }) { } } -export const actions = { +export const actions: Actions = { // Add game to a wishlist add: async (event) => { const { params, locals, request } = event; diff --git a/src/routes/(app)/(protected)/password/change/+page.server.ts b/src/routes/(app)/(protected)/password/change/+page.server.ts index 8154fd9..d918fde 100644 --- a/src/routes/(app)/(protected)/password/change/+page.server.ts +++ b/src/routes/(app)/(protected)/password/change/+page.server.ts @@ -1,9 +1,10 @@ -import { fail, redirect } from '@sveltejs/kit'; +import { fail, redirect, type Actions } from "@sveltejs/kit"; import { message, setError, superValidate } from 'sveltekit-superforms/server'; import { changeUserPasswordSchema } from '$lib/config/zod-schemas.js'; import { auth } from '$lib/server/lucia.js'; +import type { PageServerLoad } from "./$types"; -export const load = async (event) => { +export const load: PageServerLoad = async (event) => { const form = await superValidate(event, changeUserPasswordSchema); const session = await event.locals.auth.validate(); @@ -23,7 +24,7 @@ export const load = async (event) => { }; }; -export const actions = { +export const actions: Actions = { default: async (event) => { const form = await superValidate(event, changeUserPasswordSchema); //console.log(form); diff --git a/src/routes/(app)/(protected)/profile/+page.server.ts b/src/routes/(app)/(protected)/profile/+page.server.ts index 290d72c..0d35505 100644 --- a/src/routes/(app)/(protected)/profile/+page.server.ts +++ b/src/routes/(app)/(protected)/profile/+page.server.ts @@ -1,8 +1,9 @@ -import { fail, redirect } from '@sveltejs/kit'; +import { fail, redirect, type Actions } from '@sveltejs/kit'; import { message, setError, superValidate } from 'sveltekit-superforms/server'; +import { LuciaError } from 'lucia'; import { userSchema } from '$lib/config/zod-schemas'; import { auth } from '$lib/server/lucia.js'; -import { LuciaError } from 'lucia'; +import type { PageServerLoad } from './$types'; const profileSchema = userSchema.pick({ firstName: true, @@ -11,7 +12,7 @@ const profileSchema = userSchema.pick({ username: true }); -export const load = async (event) => { +export const load: PageServerLoad = async (event) => { const form = await superValidate(event, profileSchema); const session = await event.locals.auth.validate(); @@ -32,7 +33,7 @@ export const load = async (event) => { }; }; -export const actions = { +export const actions: Actions = { default: async (event) => { const form = await superValidate(event, profileSchema); diff --git a/src/routes/(app)/(protected)/wishlist/+page.server.ts b/src/routes/(app)/(protected)/wishlist/+page.server.ts index e8e1931..2ff504d 100644 --- a/src/routes/(app)/(protected)/wishlist/+page.server.ts +++ b/src/routes/(app)/(protected)/wishlist/+page.server.ts @@ -1,4 +1,4 @@ -import { error, redirect } from '@sveltejs/kit'; +import { error, redirect, type Actions } from '@sveltejs/kit'; import { superValidate } from 'sveltekit-superforms/server'; import prisma from '$lib/prisma'; import { modifyListGameSchema } from '$lib/config/zod-schemas.js'; @@ -46,7 +46,7 @@ export async function load({ params, locals }) { redirect(302, '/404'); } -export const actions = { +export const actions: Actions = { // Add game to a wishlist add: async (event) => { const { params, locals, request } = event; diff --git a/src/routes/(app)/+page.server.ts b/src/routes/(app)/+page.server.ts index aed9e57..27f8ab2 100644 --- a/src/routes/(app)/+page.server.ts +++ b/src/routes/(app)/+page.server.ts @@ -1,8 +1,9 @@ import { superValidate } from 'sveltekit-superforms/server'; import { search_schema } from '$lib/zodValidation'; import type { MetaTagsProps } from 'svelte-meta-tags'; +import type { PageServerLoad } from './$types'; -export const load = async ({ fetch, url }) => { +export const load: PageServerLoad = async ({ fetch, url }) => { const image = { url: `${ new URL(url.pathname, url.origin).href @@ -42,10 +43,3 @@ export const load = async ({ fetch, url }) => { console.log('form', form); return { form, metaTagsChild: metaTags }; }; - -// export const actions = { -// default: async ({ request, locals }): Promise => { -// // Do things in here -// return {}; -// } -// }; diff --git a/src/routes/(app)/game/[id]/+page.server.ts b/src/routes/(app)/game/[id]/+page.server.ts index d9a1c30..1c4a227 100644 --- a/src/routes/(app)/game/[id]/+page.server.ts +++ b/src/routes/(app)/game/[id]/+page.server.ts @@ -11,8 +11,9 @@ import { } from '$lib/utils/dbUtils.js'; import { mapAPIGameToBoredGame } from '$lib/utils/gameMapper.js'; import prisma from '$lib/prisma'; +import type { PageServerLoad } from './$types'; -export const load = async ({ params, locals, fetch }) => { +export const load: PageServerLoad = async ({ params, locals, fetch }) => { try { const { user } = locals; const { id } = params; diff --git a/src/routes/(auth)/login/+page.server.ts b/src/routes/(auth)/login/+page.server.ts index 9593a62..869bcdf 100644 --- a/src/routes/(auth)/login/+page.server.ts +++ b/src/routes/(auth)/login/+page.server.ts @@ -1,16 +1,17 @@ -import { fail } from '@sveltejs/kit'; +import { fail, type Actions } from '@sveltejs/kit'; import { setError, superValidate } from 'sveltekit-superforms/server'; import { redirect } from 'sveltekit-flash-message/server'; import prisma from '$lib/prisma'; import { auth } from '$lib/server/lucia'; import { userSchema } from '$lib/config/zod-schemas'; +import type { PageServerLoad } from './$types'; const signInSchema = userSchema.pick({ username: true, password: true }); -export const load = async (event) => { +export const load: PageServerLoad = async (event) => { const form = await superValidate(event, signInSchema); try { console.log('login load event', event); @@ -29,7 +30,7 @@ export const load = async (event) => { } }; -export const actions = { +export const actions: Actions = { default: async (event) => { const { locals } = event; const form = await superValidate(event, signInSchema); diff --git a/src/routes/(auth)/logout/+page.server.ts b/src/routes/(auth)/logout/+page.server.ts index 780fe73..b7b002d 100644 --- a/src/routes/(auth)/logout/+page.server.ts +++ b/src/routes/(auth)/logout/+page.server.ts @@ -1,7 +1,7 @@ +import { redirect, type Actions } from '@sveltejs/kit'; import { auth } from '$lib/server/lucia'; -import { redirect } from '@sveltejs/kit'; -export const actions = { +export const actions: Actions = { default: async ({ locals }) => { console.log('Signing out user'); const session = await locals.auth.validate(); diff --git a/src/routes/(auth)/sign-up/+page.server.ts b/src/routes/(auth)/sign-up/+page.server.ts index f73b455..e9e3d2d 100644 --- a/src/routes/(auth)/sign-up/+page.server.ts +++ b/src/routes/(auth)/sign-up/+page.server.ts @@ -1,6 +1,7 @@ -import { fail, redirect, error } from '@sveltejs/kit'; +import {fail, error, type Actions} from '@sveltejs/kit'; import { superValidate } from 'sveltekit-superforms/server'; import { LuciaError } from 'lucia'; +import type { PageServerLoad } from './$types'; import prisma from '$lib/prisma'; import { auth } from '$lib/server/lucia'; import { userSchema } from '$lib/config/zod-schemas'; @@ -19,11 +20,6 @@ const signUpSchema = userSchema }) .superRefine(({ confirm_password, password }, ctx) => { if (confirm_password !== password) { - // ctx.addIssue({ - // code: 'custom', - // message: 'Password and Confirm Password must match', - // path: ['password'] - // }); ctx.addIssue({ code: 'custom', message: 'Password and Confirm Password must match', @@ -32,7 +28,7 @@ const signUpSchema = userSchema } }); -export const load = async (event) => { +export const load: PageServerLoad = async (event) => { console.log('sign up load event', event); // const session = await event.locals.auth.validate(); // if (session) { @@ -43,7 +39,7 @@ export const load = async (event) => { }; }; -export const actions = { +export const actions: Actions = { default: async (event) => { const form = await superValidate(event, signUpSchema); diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 010f245..4b37f20 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -3,11 +3,13 @@ import { onMount } from "svelte"; // import { getFlash } from 'sveltekit-flash-message/client'; import toast, { Toaster } from 'svelte-french-toast'; - import { page } from '$app/stores'; import { MetaTags } from 'svelte-meta-tags'; import 'iconify-icon'; + import { page } from '$app/stores'; + import { onNavigate } from "$app/navigation"; import Analytics from '$lib/components/analytics.svelte'; import { theme } from '$state/theme'; + import PageLoadingIndicator from '$lib/page_loading_indicator.svelte'; const dev = process.env.NODE_ENV !== 'production'; @@ -70,6 +72,17 @@ // // be required here to avoid double-toasting. // flash.set(undefined); // }); + + onNavigate(async (navigation) => { + if (!document.startViewTransition) return; + + return new Promise((oldStateCaptureResolve) => { + document.startViewTransition(async () => { + oldStateCaptureResolve(); + await navigation.complete; + }) + }) + }); {#if !dev} @@ -78,6 +91,8 @@ + +