Add optional 30-day remembered sessions
CI / checks (push) Successful in 6m29s

This commit is contained in:
2026-10-13 14:42:53 -04:00
parent e85dc58130
commit 82e07ea33e
13 changed files with 677 additions and 72 deletions
+6 -1
View File
@@ -7,7 +7,12 @@ export const POST: RequestHandler = async ({ request, cookies, locals, url, getC
consumeAuthAttempt(getClientAddress(), user.id, 'password');
const body = await authBody(request);
return sessionResponse(
await changePassword(user.id, body.currentPassword, body.newPassword),
await changePassword(
user.id,
body.currentPassword,
body.newPassword,
locals.sessionHash ?? ''
),
cookies,
url
);
+7 -2
View File
@@ -2,10 +2,15 @@ import { json, type RequestHandler } from '@sveltejs/kit';
import { createUser, listUsers } from '$lib/server/auth/index.js';
import { authBody, authError, requireUser } from '$lib/server/auth/http.js';
export const GET: RequestHandler = () => json({ users: listUsers() });
export const POST: RequestHandler = async ({ request, locals }) => {
export const POST: RequestHandler = async ({ request, locals, getClientAddress }) => {
try {
return json(
{ user: await createUser(requireUser(locals.user).id, await authBody(request)) },
{
user: await createUser(requireUser(locals.user).id, await authBody(request), {
tokenHash: locals.sessionHash ?? '',
clientAddress: getClientAddress()
})
},
{ status: 201 }
);
} catch (cause) {
+10 -2
View File
@@ -2,10 +2,18 @@ import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { updateUser } from '$lib/server/auth/index.js';
import { authBody, authError, requireUser } from '$lib/server/auth/http.js';
export const PATCH: RequestHandler = async ({ request, params, locals }) => {
export const PATCH: RequestHandler = async ({ request, params, locals, getClientAddress }) => {
try {
return json({
user: await updateUser(requireUser(locals.user).id, params.id, await authBody(request))
user: await updateUser(
requireUser(locals.user).id,
params.id,
await authBody(request),
{
tokenHash: locals.sessionHash ?? '',
clientAddress: getClientAddress()
}
)
});
} catch (cause) {
return authError(cause);