{#if collections.length === 0}
You have no collections
{:else}
{#each collections as collection}
-
+
+
+ {collection.name}
+
+
+ Number of items:
+ Created at: {new Date(collection.createdAt).toLocaleString()}
+
+
+
{/each}
{/if}
@@ -30,10 +40,6 @@
width: 100%;
}
- .collections {
- margin: 2rem 0;
- }
-
.collection-list {
display: grid;
grid-template-columns: repeat(3, minmax(200px, 1fr));
diff --git a/src/routes/(app)/(protected)/collections/[cuid]/+page.server.ts b/src/routes/(app)/(protected)/collections/[cuid]/+page.server.ts
index fff5ac2..488fbb1 100644
--- a/src/routes/(app)/(protected)/collections/[cuid]/+page.server.ts
+++ b/src/routes/(app)/(protected)/collections/[cuid]/+page.server.ts
@@ -1,13 +1,12 @@
import { notSignedInMessage } from '$lib/flashMessages.js'
+import { collection_items, collections, gamesTable } from '$lib/server/api/databases/tables'
import { db } from '$lib/server/api/packages/drizzle'
-import { userNotAuthenticated } from '$lib/server/auth-utils'
import { modifyListGameSchema } from '$lib/validations/zod-schemas'
-import { type Actions, error, fail } from '@sveltejs/kit'
+import { type Actions, error } from '@sveltejs/kit'
import { and, eq } from 'drizzle-orm'
import { redirect } from 'sveltekit-flash-message/server'
import { zod } from 'sveltekit-superforms/adapters'
import { superValidate } from 'sveltekit-superforms/server'
-import { collection_items, collections, games } from '../../../../../lib/server/api/databases/tables'
export async function load(event) {
const { params, locals } = event
@@ -131,15 +130,16 @@ export const actions: Actions = {
// Add game to a wishlist
add: async (event) => {
const { locals } = event
- const { user, session } = locals
- if (userNotAuthenticated(user, session)) {
- return fail(401)
+
+ const authedUser = await locals.getAuthedUser()
+ if (!authedUser) {
+ throw redirect(302, '/login', notSignedInMessage, event)
}
const form = await superValidate(event, zod(modifyListGameSchema))
- const game = await db.query.games.findFirst({
- where: eq(games.id, form.data.id),
+ const game = await db.query.gamesTable.findFirst({
+ where: eq(gamesTable.id, form.data.id),
})
if (!game) {
@@ -154,7 +154,7 @@ export const actions: Actions = {
try {
const collection = await db.query.collections.findFirst({
- where: eq(collections.user_id, user!.id!),
+ where: eq(collections.user_id, authedUser.id),
})
if (!collection) {
@@ -179,32 +179,36 @@ export const actions: Actions = {
// Create new wishlist
create: async (event) => {
const { locals } = event
- const { user, session } = locals
- if (userNotAuthenticated(user, session)) {
- return fail(401)
+
+ const authedUser = await locals.getAuthedUser()
+ if (!authedUser) {
+ throw redirect(302, '/login', notSignedInMessage, event)
}
return error(405, 'Method not allowed')
},
// Delete a wishlist
delete: async (event) => {
const { locals } = event
- const { user, session } = locals
- if (userNotAuthenticated(user, session)) {
- return fail(401)
+
+ const authedUser = await locals.getAuthedUser()
+ if (!authedUser) {
+ throw redirect(302, '/login', notSignedInMessage, event)
}
return error(405, 'Method not allowed')
},
// Remove game from a wishlist
remove: async (event) => {
const { locals } = event
- const { user, session } = locals
- if (userNotAuthenticated(user, session)) {
- return fail(401)
+
+ const authedUser = await locals.getAuthedUser()
+ if (!authedUser) {
+ throw redirect(302, '/login', notSignedInMessage, event)
}
+
const form = await superValidate(event, zod(modifyListGameSchema))
- const game = await db.query.games.findFirst({
- where: eq(games.id, form.data.id),
+ const game = await db.query.gamesTable.findFirst({
+ where: eq(gamesTable.id, form.data.id),
})
if (!game) {
@@ -214,7 +218,7 @@ export const actions: Actions = {
try {
const collection = await db.query.collections.findFirst({
- where: eq(collections.user_id, user!.id!),
+ where: eq(collections.user_id, authedUser.id),
})
if (!collection) {
diff --git a/src/routes/(app)/(protected)/collections/[cuid]/+page.svelte b/src/routes/(app)/(protected)/collections/[cuid]/+page.svelte
index 3cb772d..70a1054 100644
--- a/src/routes/(app)/(protected)/collections/[cuid]/+page.svelte
+++ b/src/routes/(app)/(protected)/collections/[cuid]/+page.svelte
@@ -1,33 +1,33 @@
diff --git a/src/routes/(app)/(protected)/collections/add/+page.server.ts b/src/routes/(app)/(protected)/collections/add/+page.server.ts
index 174fbbc..76af777 100644
--- a/src/routes/(app)/(protected)/collections/add/+page.server.ts
+++ b/src/routes/(app)/(protected)/collections/add/+page.server.ts
@@ -1,13 +1,14 @@
-import { redirect } from 'sveltekit-flash-message/server';
-import { notSignedInMessage } from '$lib/flashMessages';
-import { userNotAuthenticated } from '$lib/server/auth-utils';
+import { notSignedInMessage } from '$lib/flashMessages'
+import { userNotAuthenticated } from '$lib/server/auth-utils'
+import { redirect } from 'sveltekit-flash-message/server'
export async function load(event) {
- const { locals } = event;
- const { user, session } = locals;
- if (userNotAuthenticated(user, session)) {
- redirect(302, '/login', notSignedInMessage, event);
+ const { locals } = event
+
+ const authedUser = await locals.getAuthedUser()
+ if (!authedUser) {
+ throw redirect(302, '/login', notSignedInMessage, event)
}
- return {};
+ return {}
}
diff --git a/src/routes/(app)/(protected)/collections/add/bgg/+page.server.ts b/src/routes/(app)/(protected)/collections/add/bgg/+page.server.ts
index 4150aea..e4c350f 100644
--- a/src/routes/(app)/(protected)/collections/add/bgg/+page.server.ts
+++ b/src/routes/(app)/(protected)/collections/add/bgg/+page.server.ts
@@ -1,19 +1,20 @@
-import { redirect } from '@sveltejs/kit';
-import { superValidate } from 'sveltekit-superforms/server';
-import { zod } from 'sveltekit-superforms/adapters';
-import type { PageServerLoad } from '../$types';
-import { BggForm } from '$lib/zodValidation';
-import { userNotAuthenticated } from '$lib/server/auth-utils';
-import { notSignedInMessage } from '$lib/flashMessages';
+import { notSignedInMessage } from '$lib/flashMessages'
+import { userNotAuthenticated } from '$lib/server/auth-utils'
+import { BggForm } from '$lib/zodValidation'
+import { redirect } from '@sveltejs/kit'
+import { zod } from 'sveltekit-superforms/adapters'
+import { superValidate } from 'sveltekit-superforms/server'
+import type { PageServerLoad } from '../$types'
export const load: PageServerLoad = async (event) => {
- const { locals } = event;
- const { user, session } = locals;
- if (userNotAuthenticated(user, session)) {
- redirect(302, '/login', notSignedInMessage, event);
+ const { locals } = event
+
+ const authedUser = await locals.getAuthedUser()
+ if (!authedUser) {
+ throw redirect(302, '/login', notSignedInMessage, event)
}
- const form = await superValidate({}, zod(BggForm));
+ const form = await superValidate({}, zod(BggForm))
- return { form };
-};
+ return { form }
+}
diff --git a/src/routes/(app)/(protected)/list/+layout.server.ts b/src/routes/(app)/(protected)/list/+layout.server.ts
index 30ca610..fd76692 100644
--- a/src/routes/(app)/(protected)/list/+layout.server.ts
+++ b/src/routes/(app)/(protected)/list/+layout.server.ts
@@ -1,5 +1,5 @@
import { notSignedInMessage } from '$lib/flashMessages'
-import { wishlists } from '$lib/server/api/databases/tables'
+import { wishlistsTable } from '$lib/server/api/databases/tables'
import { db } from '$lib/server/api/packages/drizzle'
import { eq } from 'drizzle-orm'
import { redirect } from 'sveltekit-flash-message/server'
@@ -14,7 +14,7 @@ export async function load(event) {
try {
const dbWishlists = await db.query.wishlists.findMany({
- where: eq(wishlists.user_id, authedUser.id),
+ where: eq(wishlistsTable.user_id, authedUser.id),
})
return {
diff --git a/src/routes/(app)/(protected)/list/+layout.svelte b/src/routes/(app)/(protected)/list/+layout.svelte
index 6d59e3a..21bc4cf 100644
--- a/src/routes/(app)/(protected)/list/+layout.svelte
+++ b/src/routes/(app)/(protected)/list/+layout.svelte
@@ -1,8 +1,8 @@
\ No newline at end of file
diff --git a/src/routes/(app)/(protected)/profile/security/+layout.server.ts b/src/routes/(app)/(protected)/profile/security/+layout.server.ts
deleted file mode 100644
index e2ef8d4..0000000
--- a/src/routes/(app)/(protected)/profile/security/+layout.server.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export const load = async () => {
- return {}
-}
diff --git a/src/routes/(app)/(protected)/profile/security/+layout.svelte b/src/routes/(app)/(protected)/profile/security/+layout.svelte
deleted file mode 100644
index c3382ba..0000000
--- a/src/routes/(app)/(protected)/profile/security/+layout.svelte
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
- {@render children()}
-
diff --git a/src/routes/(app)/(protected)/profile/security/mfa/+page.svelte b/src/routes/(app)/(protected)/profile/security/mfa/+page.svelte
deleted file mode 100644
index 0182587..0000000
--- a/src/routes/(app)/(protected)/profile/security/mfa/+page.svelte
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/routes/(app)/(protected)/profile/security/password/change/+page.server.ts b/src/routes/(app)/(protected)/profile/security/password/change/+page.server.ts
deleted file mode 100644
index c2b9f75..0000000
--- a/src/routes/(app)/(protected)/profile/security/password/change/+page.server.ts
+++ /dev/null
@@ -1,123 +0,0 @@
-import { notSignedInMessage } from '$lib/flashMessages'
-import { db } from '$lib/server/api/packages/drizzle'
-import { changeUserPasswordSchema } from '$lib/validations/account'
-import { type Actions, fail } from '@sveltejs/kit'
-import { eq } from 'drizzle-orm'
-import type { Cookie } from 'lucia'
-import { Argon2id } from 'oslo/password'
-import { redirect } from 'sveltekit-flash-message/server'
-import { zod } from 'sveltekit-superforms/adapters'
-import { setError, superValidate } from 'sveltekit-superforms/server'
-import type { PageServerLoad } from '../../../$types'
-import { usersTable } from '../../../../../../../lib/server/api/databases/tables'
-
-export const load: PageServerLoad = async (event) => {
- const { locals } = event
-
- const authedUser = await locals.getAuthedUser()
- if (!authedUser) {
- throw redirect(302, '/login', notSignedInMessage, event)
- }
-
- const form = await superValidate(event, zod(changeUserPasswordSchema))
-
- form.data = {
- current_password: '',
- password: '',
- confirm_password: '',
- }
- return {
- form,
- }
-}
-
-export const actions: Actions = {
- default: async (event) => {
- const { locals } = event
-
- const authedUser = await locals.getAuthedUser()
- if (!authedUser) {
- throw redirect(302, '/login', notSignedInMessage, event)
- }
-
- const form = await superValidate(event, zod(changeUserPasswordSchema))
-
- if (!form.valid) {
- return fail(400, {
- form,
- })
- }
-
- console.log('updating profile')
- if (!event.locals.user) {
- redirect(302, '/login', notSignedInMessage, event)
- }
-
- if (!event.locals.session) {
- return fail(401)
- }
-
- const dbUser = await db.query.usersTable.findFirst({
- where: eq(usersTable.id, authedUser.id),
- })
-
- // if (!dbUser?.hashed_password) {
- // form.data.password = '';
- // form.data.confirm_password = '';
- // form.data.current_password = '';
- // return setError(
- // form,
- // 'Error occurred. Please try again or contact support if you need further help.',
- // );
- // }
-
- const currentPasswordVerified = await new Argon2id().verify(
- // dbUser.hashed_password,
- form.data.current_password,
- )
-
- if (!currentPasswordVerified) {
- return setError(form, 'current_password', 'Your password is incorrect')
- }
- if (authedUser?.username) {
- let sessionCookie: Cookie
- try {
- if (form.data.password !== form.data.confirm_password) {
- return setError(form, 'Password and confirm password do not match')
- }
- const hashedPassword = await new Argon2id().hash(form.data.password)
- await lucia.invalidateUserSessions(authedUser.id)
- // await db
- // .update(usersTable)
- // .set({ hashed_password: hashedPassword })
- // .where(eq(usersTable.id, user.id));
- await lucia.createSession(user.id, {
- country: event.locals.session?.ipCountry ?? 'unknown',
- })
- sessionCookie = lucia.createBlankSessionCookie()
- } catch (e) {
- console.error(e)
- form.data.password = ''
- form.data.confirm_password = ''
- form.data.current_password = ''
- return setError(form, 'current_password', 'Your password is incorrect.')
- }
- event.cookies.set(sessionCookie.name, sessionCookie.value, {
- path: '.',
- ...sessionCookie.attributes,
- })
-
- const message = {
- type: 'success',
- message: 'Password Updated. Please sign in.',
- } as const
- redirect(302, '/login', message, event)
- }
- return setError(form, 'Error occurred. Please try again or contact support if you need further help.')
- // TODO: Add toast instead?
- // form.data.password = '';
- // form.data.confirm_password = '';
- // form.data.current_password = '';
- // return message(form, 'Profile updated successfully.');
- },
-}
diff --git a/src/routes/(app)/(protected)/profile/security/password/change/+page.svelte b/src/routes/(app)/(protected)/profile/security/password/change/+page.svelte
deleted file mode 100644
index e5c7422..0000000
--- a/src/routes/(app)/(protected)/profile/security/password/change/+page.svelte
+++ /dev/null
@@ -1,60 +0,0 @@
-
-
-
-
- Current Password
-
-
-
-
-
-
- New Password
-
-
-
-
-
-
- Confirm New Password
-
-
-
-
-
Submit
-
-
-
\ No newline at end of file
diff --git a/src/lib/components/LeftNav.svelte b/src/routes/(app)/(protected)/settings/+layout.svelte
similarity index 61%
rename from src/lib/components/LeftNav.svelte
rename to src/routes/(app)/(protected)/settings/+layout.svelte
index 40f2ac0..81483b4 100644
--- a/src/lib/components/LeftNav.svelte
+++ b/src/routes/(app)/(protected)/settings/+layout.svelte
@@ -1,20 +1,24 @@