Fixing linting issues.

This commit is contained in:
Bradley Shellnut 2024-03-10 23:19:55 -07:00
parent e7d1df356e
commit 527906b451
14 changed files with 42 additions and 56 deletions

View file

@ -39,11 +39,12 @@ export const authentication: Handle = async function ({ event, resolve }) {
...sessionCookie.attributes
});
}
console.log('session from hooks', JSON.stringify(session, null, 2));
if (!session) {
const sessionCookie = lucia.createBlankSessionCookie();
console.log('blank sessionCookie', JSON.stringify(sessionCookie, null, 2));
event.cookies.set(sessionCookie.name, sessionCookie.value, {
path: ".",
path: '.',
...sessionCookie.attributes
});
}
@ -57,4 +58,4 @@ export const handle: Handle = sequence(
// Sentry.sentryHandle(),
authentication
);
// export const handleError = Sentry.handleErrorWithSentry();
// export const handleError = Sentry.handleErrorWithSentry();

View file

@ -6,9 +6,11 @@
import * as Avatar from "$components/ui/avatar";
import { invalidateAll } from '$app/navigation';
import Logo from '$components/logo.svelte';
import type { Users } from '../../schema';
import type { Users } from "../../schema";
export let user: Users;
export let user: Users | null = null;
console.log('header user', user);
let avatar: string;
let loggedIn = false;
@ -30,7 +32,7 @@
</div>
<!-- <TextSearch /> -->
<nav>
{#if loggedIn}
{#if user}
<a href="/collection" title="Go to your collection" data-sveltekit-preload-data>Collection</a>
<a href="/wishlist" title="Go to your wishlist" data-sveltekit-preload-data>Wishlist</a>
<DropdownMenu.Root>
@ -95,8 +97,7 @@
</DropdownMenu.Group>
</DropdownMenu.Content>
</DropdownMenu.Root>
{/if}
{#if !loggedIn}
{:else}
<a href="/login">
<span class="flex-auto">Login</span></a
>

View file

@ -1,9 +1,9 @@
import { error } from '@sveltejs/kit';
import { eq } from 'drizzle-orm';
import kebabCase from 'just-kebab-case';
import { PUBLIC_SITE_URL } from '$env/static/public';
import db from '$lib/drizzle';
import { externalIds, type Mechanics, type Categories, categories, categoriesToExternalIds } from '../../../schema';
import { eq } from 'drizzle-orm';
import { error } from '@sveltejs/kit';
import { PUBLIC_SITE_URL } from '$env/static/public';
export async function createCategory(locals: App.Locals, category: Categories, externalId: string) {
if (!category || !externalId || externalId === '') {
@ -44,7 +44,7 @@ export async function createCategory(locals: App.Locals, category: Categories, e
.insert(categories)
.values({
name: category.name,
slug: kebabCase(category.name || category.slug || '')
slug: kebabCase(category.name ?? category.slug ?? '')
})
.returning();
const dbExternalIds = await transaction

View file

@ -0,0 +1 @@
<h1>At the admin page yo!</h1>

View file

@ -1,9 +1,10 @@
import { type Actions, fail, redirect } from "@sveltejs/kit";
import { and, eq } from "drizzle-orm";
import db from "$lib/drizzle.js";
import { superValidate } from 'sveltekit-superforms/server';
import { games, wishlist_items, wishlists } from "../../../../../schema.js";
import { eq } from "drizzle-orm";
import { zod } from "sveltekit-superforms/adapters";
import { superValidate } from 'sveltekit-superforms/server';
import db from "$lib/drizzle.js";
import { modifyListGameSchema } from "$lib/validations/zod-schemas";
import { games, wishlist_items, wishlists } from "../../../../../schema.js";
export async function load({ params, locals }) {
const user = locals.user;
@ -14,31 +15,16 @@ export async function load({ params, locals }) {
try {
const wishlist = await db.select({
wishlistId: wishlists.id,
wishlistName: wishlists.name,
wishlistItems: {
id: wishlist_items.id,
gameId: wishlist_items.game_id,
gameName: games.name,
gameThumbUrl: games.thumb_url
},
}).from(wishlists).leftJoin(wishlist_items, eq(wishlists.id, wishlist_items.wishlist_id)).leftJoin(games, eq(games.id, wishlist_items.game_id)).where(eq(wishlists.id, params.id));
// let wishlist = await db.query.wishlists.findFirst({
// where: and(eq(wishlists.id, params.id), eq(wishlists.user_id, user.id)),
// with: {
// : {
// include: {
// game: {
// select: {
// id: true,
// name: true,
// thumb_url: true
// }
// }
// }
// }
// }
// });
}).from(wishlists)
.leftJoin(wishlist_items, eq(wishlists.id, wishlist_items.wishlist_id))
.leftJoin(games, eq(games.id, wishlist_items.game_id))
.where(eq(wishlists.id, params.id));
return {
wishlist
};
@ -69,11 +55,6 @@ export const actions: Actions = {
});
if (!game) {
// game = await prisma.game.create({
// data: {
// name: form.name
// }
// });
return fail(400, {
message: 'Game not found'
});

View file

@ -55,7 +55,7 @@ export const actions: Actions = {
where: eq(users.id, user.id)
});
if (!dbUser || !dbUser.hashed_password) {
if (!dbUser?.hashed_password) {
form.data.password = '';
form.data.confirm_password = '';
form.data.current_password = '';
@ -81,8 +81,8 @@ export const actions: Actions = {
await db.update(users)
.set({ hashed_password: hashedPassword })
.where(eq(users.id, user.id));
const session = await lucia.createSession(user.id, {
country: event.locals.session?.ip,
await lucia.createSession(user.id, {
country: event.locals.session?.ipCountry ?? 'unknown',
});
sessionCookie = lucia.createBlankSessionCookie();
} catch (e) {

View file

@ -25,14 +25,14 @@ export const load: PageServerLoad = async (event) => {
const profileForm = await superValidate(zod(profileSchema), {
defaults: {
firstName: dbUser?.first_name || '',
lastName: dbUser?.last_name || '',
username: dbUser?.username || '',
firstName: dbUser?.first_name ?? '',
lastName: dbUser?.last_name ?? '',
username: dbUser?.username ?? '',
}
});
const emailForm = await superValidate(zod(changeEmailSchema), {
defaults: {
email: dbUser?.email || '',
email: dbUser?.email ?? '',
}
});
@ -66,7 +66,6 @@ export const actions: Actions = {
console.log('updating profile');
const user = event.locals.user;
const newUsername = form.data.username;
const existingUser = await db.query
.users
@ -102,7 +101,7 @@ export const actions: Actions = {
const form = await superValidate(event, zod(changeEmailSchema));
const newEmail = form.data?.email;
if (!form.valid || !newEmail || (newEmail !== '' && changeEmailIfNotEmpty.safeParse(form.data).success === false)) {
if (!form.valid || !newEmail || (newEmail !== '' && !changeEmailIfNotEmpty.safeParse(form.data).success)) {
return fail(400, {
form
});

View file

@ -2,6 +2,7 @@ import { loadFlash } from 'sveltekit-flash-message/server';
import type { LayoutServerLoad } from '../$types';
export const load: LayoutServerLoad = loadFlash(async ({ url, locals }) => {
console.log('user from app', locals.user);
return {
url: url.pathname,
user: locals.user

View file

@ -4,6 +4,8 @@
import Footer from '$components/Footer.svelte';
export let data;
console.log('layout data user', data.user);
</script>
<Header user={data.user} />

View file

@ -3,9 +3,6 @@ import { notSignedInMessage } from '$lib/flashMessages';
export async function load(event) {
const { url, locals } = event;
if (locals.user) {
redirect(302, '/', notSignedInMessage, event);
}
return {
url: url.pathname,

View file

@ -77,7 +77,9 @@ export const actions: Actions = {
ip_country: locals.country,
ip_address: locals.ip
});
console.log('logging in session', session);
sessionCookie = lucia.createSessionCookie(session.id);
console.log('logging in session cookie', sessionCookie);
} catch (e) {
// TODO: need to return error message to the client
console.error(e);
@ -93,6 +95,6 @@ export const actions: Actions = {
form.data.username = '';
form.data.password = '';
const message = { type: 'success', message: 'Signed In!' } as const;
redirect('/', message, event);
redirect(302, '/', message, event);
}
};

View file

@ -1,8 +1,8 @@
import { fail } from '@sveltejs/kit';
import { lucia } from '$lib/server/auth';
import type { Actions } from "./$types";
import { redirect } from 'sveltekit-flash-message/server';
import { lucia } from '$lib/server/auth';
import { notSignedInMessage } from '$lib/flashMessages';
import type { Actions } from "./$types";
export const actions: Actions = {
default: async (event) => {

View file

@ -23,7 +23,7 @@ const signUpDefaults = {
};
export const load: PageServerLoad = async (event) => {
redirect(302, '/waitlist', { type: 'error', message: 'Sign-up not yet available. Please add your email to the waitlist!' }, event);
// redirect(302, '/waitlist', { type: 'error', message: 'Sign-up not yet available. Please add your email to the waitlist!' }, event);
if (event.locals.user) {
const message = { type: 'success', message: 'You are already signed in' } as const;
@ -39,7 +39,7 @@ export const load: PageServerLoad = async (event) => {
export const actions: Actions = {
default: async (event) => {
fail(401, { message: 'Sign-up not yet available. Please add your email to the waitlist!' });
// fail(401, { message: 'Sign-up not yet available. Please add your email to the waitlist!' });
const form = await superValidate(event, zod(signUpSchema));
if (!form.valid) {
form.data.password = '';

View file

@ -5,6 +5,7 @@
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"useUnknownInCatchVariables": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,