Skip to content

Commit 68fc047

Browse files
committed
update to latest zenstack
1 parent 9dbc344 commit 68fc047

File tree

9 files changed

+339
-169
lines changed

9 files changed

+339
-169
lines changed

.env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# When adding additional env variables, the schema in /env/schema.mjs should be updated accordingly
2+
3+
# Prisma
4+
DATABASE_URL=file:./db.sqlite
5+
6+
DISCORD_CLIENT_ID=
7+
DISCORD_CLIENT_SECRET=
8+
9+
# Next Auth
10+
# You can generate the secret via 'openssl rand -base64 32' on Linux
11+
# More info: https://next-auth.js.org/configuration/options#secret
12+
NEXTAUTH_URL=http://localhost:3000
13+
14+
NEXTAUTH_SECRET=abc123

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ yarn-error.log*
3232

3333
# local env files
3434
# do not commit any .env files to git, except for the .env.example file. https://create.t3.gg/en/usage/env-variables#using-environment-variables
35-
.env
3635
.env*.local
3736

3837
# vercel

package-lock.json

Lines changed: 299 additions & 128 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
"postinstall": "prisma generate",
1010
"lint": "next lint",
1111
"start": "next start",
12-
"update": "npm i @zenstackhq/runtime@canary @zenstackhq/next@canary && npm i -D zenstack@canary"
12+
"update": "npm i @zenstackhq/runtime@latest @zenstackhq/next@latest && npm i -D zenstack@latest"
1313
},
1414
"dependencies": {
1515
"@next-auth/prisma-adapter": "^1.0.5",
1616
"@prisma/client": "^4.5.0",
17-
"@zenstackhq/next": "^0.6.0-pre.18",
18-
"@zenstackhq/runtime": "^0.6.0-pre.18",
17+
"@zenstackhq/next": "^1.0.0-alpha.28",
18+
"@zenstackhq/react": "^1.0.0-alpha.28",
19+
"@zenstackhq/runtime": "^1.0.0-alpha.28",
1920
"next": "13.0.2",
2021
"next-auth": "^4.18.3",
2122
"react": "18.2.0",
@@ -37,7 +38,7 @@
3738
"prisma": "^4.5.0",
3839
"tailwindcss": "^3.2.0",
3940
"typescript": "^4.8.4",
40-
"zenstack": "^0.6.0-pre.18"
41+
"zenstack": "^1.0.0-alpha.28"
4142
},
4243
"ct3aMetadata": {
4344
"initVersion": "6.11.3"

prisma/schema.prisma

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
//////////////////////////////////////////////////////////////////////////////////////////////
2+
// DO NOT MODIFY THIS FILE //
3+
// This file is automatically generated by ZenStack CLI and should not be manually updated. //
4+
//////////////////////////////////////////////////////////////////////////////////////////////
5+
16
datasource db {
27
provider="sqlite"
38
url=env("DATABASE_URL")
@@ -13,6 +18,8 @@ model Example {
1318
updatedAt DateTime @updatedAt()
1419
}
1520

21+
/// @@allow('all', auth() == author)
22+
/// @@allow('read', auth() != null && published)
1623
model Post {
1724
id String @id() @default(cuid())
1825
createdAt DateTime @default(now())
@@ -51,11 +58,15 @@ model Session {
5158
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
5259
}
5360

61+
/// @@allow('create,read', true)
62+
/// @@allow('update,delete', auth() == this)
5463
model User {
5564
id String @id() @default(cuid())
5665
name String?
5766
email String? @unique()
5867
emailVerified DateTime?
68+
/// @password
69+
/// @omit
5970
password String
6071
posts Post[]
6172
image String?

schema.zmodel

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ datasource db {
1414
url = env("DATABASE_URL")
1515
}
1616

17-
plugin nestjs {
18-
provider = '@zenstack/react-hooks'
17+
plugin reactHooks {
18+
provider = '@zenstackhq/react'
1919
output = "./src/lib/hooks"
2020
}
2121

@@ -56,7 +56,6 @@ model Account {
5656
id_token String? // @db.Text
5757
session_state String?
5858
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
59-
6059
@@unique([provider, providerAccountId])
6160
}
6261

@@ -91,6 +90,5 @@ model VerificationToken {
9190
identifier String
9291
token String @unique
9392
expires DateTime
94-
9593
@@unique([identifier, token])
9694
}

src/lib/hooks/post.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
/* eslint-disable */
12
import type { Prisma, Post } from "@prisma/client";
23
import { useContext } from 'react';
3-
import { RequestHandlerContext } from '@zenstackhq/next/client';
4-
import { request, type RequestOptions } from '@zenstackhq/runtime/client';
4+
import { RequestHandlerContext, type RequestOptions } from '@zenstackhq/react/runtime';
5+
import * as request from '@zenstackhq/react/runtime';
56

67
export function usePost() {
78
const { endpoint } = useContext(RequestHandlerContext);
@@ -21,10 +22,6 @@ export function usePost() {
2122
}
2223
}
2324

24-
async function createMany<T extends Prisma.PostCreateManyArgs>(args: Prisma.SelectSubset<T, Prisma.PostCreateManyArgs>) {
25-
return await request.post<Prisma.SelectSubset<T, Prisma.PostCreateManyArgs>, Prisma.BatchPayload>(`${endpoint}/post/createMany`, args, mutate);
26-
}
27-
2825
function findMany<T extends Prisma.PostFindManyArgs>(args?: Prisma.SelectSubset<T, Prisma.PostFindManyArgs>, options?: RequestOptions<Array<Prisma.PostGetPayload<T>>>) {
2926
return request.get<Array<Prisma.PostGetPayload<T>>>(`${endpoint}/post/findMany`, args, options);
3027
}
@@ -132,9 +129,5 @@ export function usePost() {
132129
}[OrderFields]>(args: Prisma.SubsetIntersection<T, Prisma.PostGroupByArgs, OrderByArg> & InputErrors, options?: RequestOptions<{} extends InputErrors ? Prisma.GetPostGroupByPayload<T> : InputErrors>) {
133130
return request.get<{} extends InputErrors ? Prisma.GetPostGroupByPayload<T> : InputErrors>(`${endpoint}/post/groupBy`, args, options);
134131
}
135-
136-
function count<T extends Prisma.PostCountArgs>(args: Prisma.Subset<T, Prisma.PostCountArgs>, options?: RequestOptions<T extends { select: any; } ? T['select'] extends true ? number : Prisma.GetScalarType<T['select'], Prisma.PostCountAggregateOutputType> : number>) {
137-
return request.get<T extends { select: any; } ? T['select'] extends true ? number : Prisma.GetScalarType<T['select'], Prisma.PostCountAggregateOutputType> : number>(`${endpoint}/post/count`, args, options);
138-
}
139-
return { create, createMany, findMany, findUnique, findFirst, update, updateMany, upsert, del, deleteMany, aggregate, groupBy, count };
132+
return { create, findMany, findUnique, findFirst, update, updateMany, upsert, del, deleteMany, aggregate, groupBy };
140133
}

src/lib/hooks/user.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
/* eslint-disable */
12
import type { Prisma, User } from "@prisma/client";
23
import { useContext } from 'react';
3-
import { RequestHandlerContext } from '@zenstackhq/next/client';
4-
import { request, type RequestOptions } from '@zenstackhq/runtime/client';
4+
import { RequestHandlerContext, type RequestOptions } from '@zenstackhq/react/runtime';
5+
import * as request from '@zenstackhq/react/runtime';
56

67
export function useUser() {
78
const { endpoint } = useContext(RequestHandlerContext);
@@ -21,10 +22,6 @@ export function useUser() {
2122
}
2223
}
2324

24-
async function createMany<T extends Prisma.UserCreateManyArgs>(args: Prisma.SelectSubset<T, Prisma.UserCreateManyArgs>) {
25-
return await request.post<Prisma.SelectSubset<T, Prisma.UserCreateManyArgs>, Prisma.BatchPayload>(`${endpoint}/user/createMany`, args, mutate);
26-
}
27-
2825
function findMany<T extends Prisma.UserFindManyArgs>(args?: Prisma.SelectSubset<T, Prisma.UserFindManyArgs>, options?: RequestOptions<Array<Prisma.UserGetPayload<T>>>) {
2926
return request.get<Array<Prisma.UserGetPayload<T>>>(`${endpoint}/user/findMany`, args, options);
3027
}
@@ -132,9 +129,5 @@ export function useUser() {
132129
}[OrderFields]>(args: Prisma.SubsetIntersection<T, Prisma.UserGroupByArgs, OrderByArg> & InputErrors, options?: RequestOptions<{} extends InputErrors ? Prisma.GetUserGroupByPayload<T> : InputErrors>) {
133130
return request.get<{} extends InputErrors ? Prisma.GetUserGroupByPayload<T> : InputErrors>(`${endpoint}/user/groupBy`, args, options);
134131
}
135-
136-
function count<T extends Prisma.UserCountArgs>(args: Prisma.Subset<T, Prisma.UserCountArgs>, options?: RequestOptions<T extends { select: any; } ? T['select'] extends true ? number : Prisma.GetScalarType<T['select'], Prisma.UserCountAggregateOutputType> : number>) {
137-
return request.get<T extends { select: any; } ? T['select'] extends true ? number : Prisma.GetScalarType<T['select'], Prisma.UserCountAggregateOutputType> : number>(`${endpoint}/user/count`, args, options);
138-
}
139-
return { create, createMany, findMany, findUnique, findFirst, update, updateMany, upsert, del, deleteMany, aggregate, groupBy, count };
132+
return { create, findMany, findUnique, findFirst, update, updateMany, upsert, del, deleteMany, aggregate, groupBy };
140133
}

src/pages/api/auth/[...nextauth].ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,6 @@ export const authOptions: NextAuthOptions = {
2525
// Configure one or more authentication providers
2626
adapter: PrismaAdapter(prisma),
2727
providers: [
28-
// highlight-start
29-
// Remove DiscordProvider below:
30-
// DiscordProvider({
31-
// clientId: env.DISCORD_CLIENT_ID,
32-
// clientSecret: env.DISCORD_CLIENT_SECRET,
33-
// }),
34-
// highlight-end
35-
36-
// highlight-start
3728
CredentialsProvider({
3829
credentials: {
3930
email: {
@@ -45,7 +36,6 @@ export const authOptions: NextAuthOptions = {
4536
},
4637
authorize: authorize(prisma),
4738
}),
48-
// highlight-end
4939
],
5040
};
5141

0 commit comments

Comments
 (0)