diff --git a/.gitignore b/.gitignore index ffe11f5..7eacb61 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,5 @@ Thumbs.db # Pocketbase backend/* -!backend/pb_migrations \ No newline at end of file +!backend/pb_migrations +!backend/pb_hooks \ No newline at end of file diff --git a/backend/pb_hooks/tracks.pb.js b/backend/pb_hooks/tracks.pb.js new file mode 100644 index 0000000..319d006 --- /dev/null +++ b/backend/pb_hooks/tracks.pb.js @@ -0,0 +1,12 @@ +/// + +// Track creation +onRecordCreateRequest((e) => { + if(e.requestInfo().auth) { + // Set owner to the user who created the track + e.record.set("owner", e.requestInfo().auth.get("id").toString()); + // Activating the track + e.record.set("active", true); + } + e.next() +}, 'tracks'); \ No newline at end of file