diff --git a/src/lib/components/Layout/Sidebar.svelte b/src/lib/components/Layout/Sidebar.svelte index 567accd..69df0f7 100644 --- a/src/lib/components/Layout/Sidebar.svelte +++ b/src/lib/components/Layout/Sidebar.svelte @@ -73,6 +73,23 @@ +
+ +
+ {#if $allTags.length > 0}

Tags

diff --git a/src/routes/api/auth/profile/+server.ts b/src/routes/api/auth/profile/+server.ts new file mode 100644 index 0000000..80452df --- /dev/null +++ b/src/routes/api/auth/profile/+server.ts @@ -0,0 +1,16 @@ +import { json, error } from '@sveltejs/kit'; +import type { RequestHandler } from './$types.js'; +import { getUserId } from '$lib/server/api-utils.js'; +import { updateUserProfile } from '$lib/server/auth.js'; + +export const PUT: RequestHandler = async ({ request, ...event }) => { + const userId = getUserId(event); + const { displayName, email } = await request.json(); + + if (email !== undefined && !email) { + throw error(400, 'Email cannot be empty'); + } + + updateUserProfile(userId, { displayName, email }); + return json({ success: true }); +}; diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte new file mode 100644 index 0000000..5aa3221 --- /dev/null +++ b/src/routes/settings/+page.svelte @@ -0,0 +1,170 @@ + + + + Settings - KeepNotes + + +
+

Settings

+ + +
+

Profile

+ + {#if profileMsg} +
+ {profileMsg} +
+ {/if} + +
+
+ + +
+
+ + +
+ +
+
+ + +
+

Change Password

+ + {#if passwordMsg} +
+ {passwordMsg} +
+ {/if} + +
+ + + + +
+
+ + + {#if data.user?.role === 'admin'} +
+

Administration

+ + Manage users → + +
+ {/if} +
diff --git a/src/routes/settings/users/+page.server.ts b/src/routes/settings/users/+page.server.ts new file mode 100644 index 0000000..4c5bc6d --- /dev/null +++ b/src/routes/settings/users/+page.server.ts @@ -0,0 +1,10 @@ +import { redirect } from '@sveltejs/kit'; +import type { PageServerLoad } from './$types.js'; +import { listUsers } from '$lib/server/auth.js'; + +export const load: PageServerLoad = ({ locals }) => { + if (!locals.user || locals.user.role !== 'admin') { + throw redirect(302, '/settings'); + } + return { users: listUsers() }; +}; diff --git a/src/routes/settings/users/+page.svelte b/src/routes/settings/users/+page.svelte new file mode 100644 index 0000000..e857b7b --- /dev/null +++ b/src/routes/settings/users/+page.svelte @@ -0,0 +1,179 @@ + + + + User Management - KeepNotes + + +
+
+ ← Settings +

User Management

+
+ + +
+

Create User

+ + {#if createMsg} +
+ {createMsg} +
+ {/if} + +
+ + + + + +
+
+ + +
+

Users ({users.length})

+ +
+ {#each users as user (user.id)} +
+
+

+ {user.displayName || user.email} + {#if user.role === 'admin'} + admin + {/if} +

+

{user.email}

+
+
+ + {#if user.id !== data.user?.id} + + {/if} +
+
+ {/each} +
+
+