@@ -15,7 +15,7 @@ import { schema, zql } from '~/db/schema'
1515const cookies = useCookies ( )
1616
1717export interface ZeroContext {
18- sub : string
18+ userID : string
1919}
2020
2121declare module '@rocicorp/zero' {
@@ -33,9 +33,9 @@ export const mutators = defineMutators({
3333 id : z . string ( ) ,
3434 timestamp : z . number ( ) ,
3535 } ) ,
36- async ( { tx, ctx, args : { mediumID, body, id, timestamp } } ) => {
36+ async ( { tx, ctx : { userID } , args : { mediumID, body, id, timestamp } } ) => {
3737 return tx . mutate . message . insert ( {
38- senderID : ctx . sub ,
38+ senderID : userID ,
3939 mediumID,
4040 body,
4141 id,
@@ -45,15 +45,15 @@ export const mutators = defineMutators({
4545 ) ,
4646 update : defineMutator (
4747 z . object ( { id : z . string ( ) , body : z . string ( ) } ) ,
48- async ( { tx, ctx, args : { id, body } } ) => {
48+ async ( { tx, ctx : { userID } , args : { id, body } } ) => {
4949 const messageToEdit = await tx . run (
5050 zql . message . where ( 'id' , id ) . one ( ) ,
5151 )
5252 if ( ! messageToEdit ) {
5353 throw new Error ( `Message with id ${ id } not found` )
5454 }
5555
56- if ( messageToEdit . senderID !== ctx . sub ) {
56+ if ( messageToEdit . senderID !== userID ) {
5757 throw new Error ( `You aren't allowed to edit this message` )
5858 }
5959
@@ -62,8 +62,8 @@ export const mutators = defineMutators({
6262 ) ,
6363 delete : defineMutator (
6464 z . object ( { id : z . string ( ) } ) ,
65- async ( { tx, ctx, args : { id } } ) => {
66- if ( ! ctx . sub ) {
65+ async ( { tx, ctx : { userID } , args : { id } } ) => {
66+ if ( ! userID ) {
6767 throw new Error ( 'You must be logged in to delete' )
6868 }
6969
@@ -115,6 +115,9 @@ export const { useZero, useQuery } = createZeroComposables(() => {
115115
116116 return {
117117 userID,
118+ context : {
119+ userID,
120+ } ,
118121 // auth: () => encodedJWT || undefined,
119122 server : import . meta. env . VITE_PUBLIC_ZERO_CACHE_URL ,
120123 schema,
0 commit comments