diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 9ab5773..770ef68 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -11,23 +11,20 @@ module.exports = { parserOptions: { sourceType: 'module', ecmaVersion: 2020, - project: './tsconfig.json', - extraFileExtensions: ['.svelte'] // This is a required setting in `@typescript-eslint/parser` v4.24.0. + extraFileExtensions: ['.svelte'] }, - ignorePatterns: ['*.cjs'], - overrides: [ - { - files: ['*.svelte'], - parser: 'svelte-eslint-parser', - // Parse the `
-
{ - boredState.update((n) => ({ ...n, loading: true })); return async ({ result }) => { console.log(result); if (result.type === 'success' || result.type === 'redirect') { @@ -73,7 +70,6 @@ } await invalidateAll(); await applyAction(result); - boredState.update((n) => ({ ...n, loading: true })); }; }} action="/logout" diff --git a/src/lib/components/loading.svelte b/src/lib/components/Loading.svelte similarity index 100% rename from src/lib/components/loading.svelte rename to src/lib/components/Loading.svelte diff --git a/src/lib/components/header/svelte-logo.svg b/src/lib/components/header/svelte-logo.svg deleted file mode 100644 index 49492a8..0000000 --- a/src/lib/components/header/svelte-logo.svg +++ /dev/null @@ -1 +0,0 @@ -svelte-logo \ No newline at end of file diff --git a/src/lib/components/ui/form/form-native-select.svelte b/src/lib/components/ui/form/form-native-select.svelte index af2a1c4..0443efb 100644 --- a/src/lib/components/ui/form/form-native-select.svelte +++ b/src/lib/components/ui/form/form-native-select.svelte @@ -11,14 +11,16 @@ export { className as class }; - - - - +
+ + + + +
diff --git a/src/lib/components/ui/form/form-select-trigger.svelte b/src/lib/components/ui/form/form-select-trigger.svelte index 5950967..de71fbf 100644 --- a/src/lib/components/ui/form/form-select-trigger.svelte +++ b/src/lib/components/ui/form/form-select-trigger.svelte @@ -11,7 +11,13 @@ export let placeholder = ""; - + diff --git a/src/lib/components/ui/form/form-select.svelte b/src/lib/components/ui/form/form-select.svelte index f747b6b..ff022bb 100644 --- a/src/lib/components/ui/form/form-select.svelte +++ b/src/lib/components/ui/form/form-select.svelte @@ -3,7 +3,7 @@ import { getFormField } from "formsnap"; import type { Select as SelectPrimitive } from "bits-ui"; - type $$Props = SelectPrimitive.Props; + type $$Props = SelectPrimitive.Props; const { setValue, name, value } = getFormField(); export let onSelectedChange: $$Props["onSelectedChange"] = undefined; diff --git a/src/lib/components/ui/select/index.ts b/src/lib/components/ui/select/index.ts index b3bc630..e8a5497 100644 --- a/src/lib/components/ui/select/index.ts +++ b/src/lib/components/ui/select/index.ts @@ -1,15 +1,16 @@ import { Select as SelectPrimitive } from "bits-ui"; -import Root from "./select.svelte"; import Label from "./select-label.svelte"; import Item from "./select-item.svelte"; import Content from "./select-content.svelte"; import Trigger from "./select-trigger.svelte"; import Separator from "./select-separator.svelte"; +const Root = SelectPrimitive.Root; const Group = SelectPrimitive.Group; const Input = SelectPrimitive.Input; const Value = SelectPrimitive.Value; + export { Root, Group, diff --git a/src/lib/components/ui/select/select-content.svelte b/src/lib/components/ui/select/select-content.svelte index e527bdc..5c6cae5 100644 --- a/src/lib/components/ui/select/select-content.svelte +++ b/src/lib/components/ui/select/select-content.svelte @@ -5,6 +5,8 @@ type $$Props = SelectPrimitive.ContentProps; type $$Events = SelectPrimitive.ContentEvents; + + export let sideOffset: $$Props["sideOffset"] = 4; export let inTransition: $$Props["inTransition"] = flyAndScale; export let inTransitionConfig: $$Props["inTransitionConfig"] = undefined; export let outTransition: $$Props["outTransition"] = scale; @@ -23,6 +25,7 @@ {inTransitionConfig} {outTransition} {outTransitionConfig} + {sideOffset} class={cn( "relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md outline-none", className diff --git a/src/lib/components/ui/toggle/toggle.svelte b/src/lib/components/ui/toggle/toggle.svelte index 0ff497a..244c85a 100644 --- a/src/lib/components/ui/toggle/toggle.svelte +++ b/src/lib/components/ui/toggle/toggle.svelte @@ -20,7 +20,7 @@ bind:pressed class={cn(toggleVariants({ variant, size, className }))} {...$$restProps} - on:m-click + on:click > diff --git a/src/routes/(app)/(protected)/password/change/+page.server.ts b/src/routes/(app)/(protected)/password/change/+page.server.ts index d918fde..2b2e6e6 100644 --- a/src/routes/(app)/(protected)/password/change/+page.server.ts +++ b/src/routes/(app)/(protected)/password/change/+page.server.ts @@ -1,19 +1,19 @@ import { fail, redirect, type Actions } from "@sveltejs/kit"; import { message, setError, superValidate } from 'sveltekit-superforms/server'; +import { Argon2id } from "oslo/password"; import { changeUserPasswordSchema } from '$lib/config/zod-schemas.js'; -import { auth } from '$lib/server/lucia.js'; +import { lucia } from '$lib/server/auth.js'; import type { PageServerLoad } from "./$types"; +import prisma from "$lib/prisma"; export const load: PageServerLoad = async (event) => { const form = await superValidate(event, changeUserPasswordSchema); - const session = await event.locals.auth.validate(); + const user = event.locals.user; - if (!session) { + if (!user) { throw redirect(302, '/login'); } - const { user } = session; - form.data = { current_password: '', password: '', @@ -27,7 +27,6 @@ export const load: PageServerLoad = async (event) => { export const actions: Actions = { default: async (event) => { const form = await superValidate(event, changeUserPasswordSchema); - //console.log(form); if (!form.valid) { return fail(400, { @@ -35,23 +34,61 @@ export const actions: Actions = { }); } - //add user to db - try { - console.log('updating profile'); - const session = await event.locals.auth.validate(); + console.log('updating profile'); + if (!event.locals.user) { + throw redirect(302, '/login'); + } - if (!session) { - throw redirect(302, '/login'); + const user = event.locals.user; + + const dbUser = await prisma.user.findUnique({ + where: { + id: user.id } + }); - const user = session.user; + if (!dbUser || !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.'); + } + + try { if (user?.username) { if (form.data.password !== form.data.confirm_password) { return setError(form, 'Password and confirm password do not match'); } - await auth.useKey('username', user.username, form.data.current_password); - await auth.updateKeyPassword('username', user.username, form.data.password); + const hashedPassword = await new Argon2id().hash(form.data.password); + await lucia.invalidateUserSessions(user.id); + await prisma.user.update({ + where: { + id: user.id + }, + data: { + hashed_password: hashedPassword + } + }); + const session = await lucia.createSession(user.id, { + country: event.locals.session.ip, + }); + const sessionCookie = lucia.createSessionCookie(session.id); + return new Response(null, { + status: 302, + headers: { + Location: '/login', + 'Set-Cookie': sessionCookie.serialize() + } + }); } else { return setError( form, @@ -67,9 +104,9 @@ export const actions: Actions = { } // TODO: Add toast instead? - form.data.password = ''; - form.data.confirm_password = ''; - form.data.current_password = ''; - return message(form, 'Profile updated successfully.'); + // 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/+page.server.ts b/src/routes/(app)/(protected)/profile/+page.server.ts index db7dfc0..36598b5 100644 --- a/src/routes/(app)/(protected)/profile/+page.server.ts +++ b/src/routes/(app)/(protected)/profile/+page.server.ts @@ -1,8 +1,7 @@ -import { fail, redirect, type Actions } from '@sveltejs/kit'; +import { fail, type Actions } from '@sveltejs/kit'; import { message, setError, superValidate } from 'sveltekit-superforms/server'; -// import { LuciaError } from 'lucia'; +import { redirect } from 'sveltekit-flash-message/server'; import { userSchema } from '$lib/config/zod-schemas'; -import { Lucia } from '$lib/server/auth.js'; import type { PageServerLoad } from './$types'; import prisma from '$lib/prisma'; @@ -17,7 +16,8 @@ export const load: PageServerLoad = async (event) => { const form = await superValidate(event, profileSchema); if (!event.locals.user) { - throw redirect(302, '/login'); + const message = { type: 'error', message: 'You are not signed in' } as const; + throw redirect(302, '/login', message, event); } const { user } = event.locals; diff --git a/src/routes/(app)/(protected)/profile/+page.svelte b/src/routes/(app)/(protected)/profile/+page.svelte index c86e693..e8ae518 100644 --- a/src/routes/(app)/(protected)/profile/+page.svelte +++ b/src/routes/(app)/(protected)/profile/+page.svelte @@ -1,12 +1,12 @@ diff --git a/src/routes/(app)/search/+page.svelte b/src/routes/(app)/search/+page.svelte index 756ba6a..8f32214 100644 --- a/src/routes/(app)/search/+page.svelte +++ b/src/routes/(app)/search/+page.svelte @@ -30,29 +30,6 @@ defaultPage: 1, siblingCount: 1 }); - - // async function handleNextPageEvent(event: CustomEvent) { - // if (+event?.detail?.page === page + 1) { - // page += 1; - // } - // await tick(); - // submitButton.click(); - // } - - // async function handlePreviousPageEvent(event: CustomEvent) { - // if (+event?.detail?.page === page - 1) { - // page -= 1; - // } - // await tick(); - // submitButton.click(); - // } - - // async function handlePerPageEvent(event: CustomEvent) { - // page = 1; - // pageSize = event.detail.pageSize; - // await tick(); - // submitButton.click(); - // }