;
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();
- // }
diff --git a/src/routes/(auth)/login/+page.server.ts b/src/routes/(auth)/login/+page.server.ts
index b515cc6..8271031 100644
--- a/src/routes/(auth)/login/+page.server.ts
+++ b/src/routes/(auth)/login/+page.server.ts
@@ -28,7 +28,7 @@ export const load: PageServerLoad = async (event) => {
export const actions: Actions = {
default: async (event) => {
- const { cookies, locals } = event;
+ const { locals } = event;
const form = await superValidate(event, signInSchema);
if (!form.valid) {
@@ -61,7 +61,7 @@ export const actions: Actions = {
}
session = await lucia.createSession(user.id, {
- country: locals.session.ip,
+ country: locals.session.ip
});
sessionCookie = lucia.createSessionCookie(session.id);
@@ -93,7 +93,7 @@ export const actions: Actions = {
form.data.password = '';
return setError(form, '', 'Your username or password is incorrect.');
}
-
+
event.cookies.set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes);
form.data.username = '';
form.data.password = '';
diff --git a/src/routes/(auth)/login/+page.svelte b/src/routes/(auth)/login/+page.svelte
index 572bc5f..b20a484 100644
--- a/src/routes/(auth)/login/+page.svelte
+++ b/src/routes/(auth)/login/+page.svelte
@@ -2,7 +2,6 @@
import { page } from '$app/stores';
import { superForm } from 'sveltekit-superforms/client';
import * as flashModule from 'sveltekit-flash-message/client';
- import toast from 'svelte-french-toast';
import { AlertCircle } from "lucide-svelte";
import { signInSchema } from '$lib/config/zod-schemas.js';
import { Label } from '$components/ui/label';
@@ -31,16 +30,6 @@
validationMethod: 'oninput',
delayMs: 0,
});
-
- // const flash = flashModule.getFlash(page);
-
- // $: {
- // if ($flash) {
- // toast.error($flash.message, {
- // duration: 5000
- // });
- // }
- // }
diff --git a/src/routes/(auth)/sign-up/+page.svelte b/src/routes/(auth)/sign-up/+page.svelte
index f9eec81..430289a 100644
--- a/src/routes/(auth)/sign-up/+page.svelte
+++ b/src/routes/(auth)/sign-up/+page.svelte
@@ -33,15 +33,6 @@
let collapsibleOpen = true;
- // const flash = flashModule.getFlash(page);
-
- // $: {
- // if ($flash) {
- // toast.error($flash.message, {
- // duration: 5000
- // });
- // }
- // }
onMount(() => {
collapsibleOpen = false;
});
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 9ba4fd5..0eb5c51 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -1,18 +1,16 @@