race condition security patch

This commit is contained in:
Christian Beutel
2025-04-18 12:59:17 +02:00
parent 29b8a0352e
commit d8f7a862f6
53 changed files with 240 additions and 222 deletions

View File

@@ -1,9 +1,9 @@
import { Comment } from "$lib/models/comment";
import type { Trail } from "$lib/models/trail";
import { pb } from "$lib/pocketbase";
import { APIError } from "$lib/util/api_util";
import { type ListResult } from "pocketbase";
import { writable, type Writable } from "svelte/store";
import { get, writable, type Writable } from "svelte/store";
import { currentUser } from "./user_store";
export const comments: Writable<Comment[]> = writable([])
@@ -28,11 +28,12 @@ export async function comments_index(trail: Trail) {
}
export async function comments_create(comment: Comment) {
if (!pb.authStore.record) {
throw new Error("Unauthenticated");
const user = get(currentUser)
if (!user) {
throw Error("Unauthenticated")
}
comment.author = pb.authStore.record!.id;
comment.author = user.authStore.record!.id;
let r = await fetch('/api/v1/comment', {
method: 'PUT',