feat: add auth to zero queries
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
import { syncedQuery } from "@rocicorp/zero";
|
||||
import { syncedQueryWithContext } from "@rocicorp/zero";
|
||||
import { z } from "zod";
|
||||
import { builder } from "@money/shared";
|
||||
import type { AuthData } from "./auth";
|
||||
import { isLoggedIn } from "./zql";
|
||||
|
||||
export const queries = {
|
||||
allTransactions: syncedQuery('allTransactions', z.tuple([]), () =>
|
||||
builder.transaction.limit(10)
|
||||
allTransactions: syncedQueryWithContext('allTransactions', z.tuple([]), (authData: AuthData | null) => {
|
||||
isLoggedIn(authData);
|
||||
return builder.transaction
|
||||
.where('user_id', '=', authData.user.id)
|
||||
.limit(10)
|
||||
}
|
||||
),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user