race condition security patch
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user