Skip to content

Commit 76ce28f

Browse files
authored
Merge pull request #11 from softnetics/yu/feat/auth-2
[DRIZZ-32,DRIZZ-31] Login and Sign Up page
2 parents 9524a3e + df47273 commit 76ce28f

62 files changed

Lines changed: 995 additions & 1184 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/shy-rice-grow.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@example/erp": patch
3+
"@kivotos/core": minor
4+
"@kivotos/next": minor
5+
---
6+
7+
[[DRIZZ-31] Register Page](https://app.plane.so/softnetics/browse/DRIZZ-31/)
8+
[[DRIZZ-32] Login page](https://app.plane.so/softnetics/browse/DRIZZ-32/)

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@
4747
"examples/erp/src/app/global.css": "examples/erp/**",
4848
"examples/erp/src/app/(admin)/admin/tailwind.css": "examples/erp/(admin)/**",
4949
"examples/erp/src/app/(admin)/playground/tailwind.css": "examples/erp/(admin)/playground/**"
50+
},
51+
"[sql]": {
52+
"editor.defaultFormatter": "adpyke.vscode-sql-formatter"
5053
}
5154
}

examples/erp/db/schema/index.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { relations, sql } from 'drizzle-orm'
1+
import { relations } from 'drizzle-orm'
22
import { boolean, pgTable, text, timestamp, uuid, varchar } from 'drizzle-orm/pg-core'
33

44
const timestamps = {
@@ -8,9 +8,7 @@ const timestamps = {
88
}
99

1010
export const users = pgTable('users', {
11-
id: uuid('id')
12-
.primaryKey()
13-
.default(sql`gen_random_uuid()`),
11+
id: uuid('id').primaryKey().defaultRandom(),
1412
name: text('name').notNull(),
1513
email: text('email').notNull().unique(),
1614
emailVerified: boolean('email_verified').notNull().default(false),
@@ -19,7 +17,7 @@ export const users = pgTable('users', {
1917
})
2018

2119
export const sessions = pgTable('session', {
22-
id: text('id').primaryKey(),
20+
id: uuid('id').primaryKey().defaultRandom(),
2321
expiresAt: timestamp('expires_at').notNull(),
2422
token: text('token').notNull().unique(),
2523
ipAddress: text('ip_address'),
@@ -31,7 +29,7 @@ export const sessions = pgTable('session', {
3129
})
3230

3331
export const accounts = pgTable('account', {
34-
id: text('id').primaryKey(),
32+
id: uuid('id').primaryKey().defaultRandom(),
3533
accountId: text('account_id').notNull(),
3634
providerId: text('provider_id').notNull(),
3735
userId: uuid('user_id')
@@ -48,17 +46,15 @@ export const accounts = pgTable('account', {
4846
})
4947

5048
export const verifications = pgTable('verification', {
51-
id: text('id').primaryKey(),
49+
id: uuid('id').primaryKey().defaultRandom(),
5250
identifier: text('identifier').notNull(),
5351
value: text('value').notNull(),
5452
expiresAt: timestamp('expires_at').notNull(),
5553
...timestamps,
5654
})
5755

5856
export const posts = pgTable('posts', {
59-
id: uuid()
60-
.primaryKey()
61-
.default(sql`gen_random_uuid()`),
57+
id: uuid('id').primaryKey().defaultRandom(),
6258
title: varchar(),
6359
content: text(),
6460
authorId: uuid().references(() => users.id),
@@ -76,9 +72,7 @@ export const postsRelations = relations(posts, ({ one }) => ({
7672
}))
7773

7874
export const categories = pgTable('categories', {
79-
id: uuid()
80-
.primaryKey()
81-
.default(sql`gen_random_uuid()`),
75+
id: uuid('id').primaryKey().defaultRandom(),
8276
name: varchar().notNull(),
8377
ownerId: uuid().references(() => users.id),
8478
...timestamps,
@@ -91,9 +85,7 @@ export const categoriesRelations = relations(categories, ({ many, one }) => ({
9185
}))
9286

9387
export const categoryTags = pgTable('categoryTags', {
94-
id: uuid()
95-
.primaryKey()
96-
.default(sql`gen_random_uuid()`),
88+
id: uuid('id').primaryKey().defaultRandom(),
9789
name: varchar().notNull(),
9890
category: uuid().references(() => categories.id),
9991
...timestamps,

examples/erp/drizzle/0000_peaceful_leper_queen.sql renamed to examples/erp/drizzle/0000_freezing_the_order.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CREATE TABLE "account" (
2-
"id" text PRIMARY KEY NOT NULL,
2+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
33
"account_id" text NOT NULL,
44
"provider_id" text NOT NULL,
55
"user_id" uuid NOT NULL,
@@ -45,7 +45,7 @@ CREATE TABLE "posts" (
4545
);
4646
--> statement-breakpoint
4747
CREATE TABLE "session" (
48-
"id" text PRIMARY KEY NOT NULL,
48+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
4949
"expires_at" timestamp NOT NULL,
5050
"token" text NOT NULL,
5151
"ip_address" text,
@@ -70,7 +70,7 @@ CREATE TABLE "users" (
7070
);
7171
--> statement-breakpoint
7272
CREATE TABLE "verification" (
73-
"id" text PRIMARY KEY NOT NULL,
73+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
7474
"identifier" text NOT NULL,
7575
"value" text NOT NULL,
7676
"expires_at" timestamp NOT NULL,

examples/erp/drizzle/meta/0000_snapshot.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "257be8ac-2050-489e-876f-73328184a0bf",
2+
"id": "bf9131bb-df6e-47d0-ad81-e80d0b387a87",
33
"prevId": "00000000-0000-0000-0000-000000000000",
44
"version": "7",
55
"dialect": "postgresql",
@@ -10,9 +10,10 @@
1010
"columns": {
1111
"id": {
1212
"name": "id",
13-
"type": "text",
13+
"type": "uuid",
1414
"primaryKey": true,
15-
"notNull": true
15+
"notNull": true,
16+
"default": "gen_random_uuid()"
1617
},
1718
"account_id": {
1819
"name": "account_id",
@@ -346,9 +347,10 @@
346347
"columns": {
347348
"id": {
348349
"name": "id",
349-
"type": "text",
350+
"type": "uuid",
350351
"primaryKey": true,
351-
"notNull": true
352+
"notNull": true,
353+
"default": "gen_random_uuid()"
352354
},
353355
"expires_at": {
354356
"name": "expires_at",
@@ -510,9 +512,10 @@
510512
"columns": {
511513
"id": {
512514
"name": "id",
513-
"type": "text",
515+
"type": "uuid",
514516
"primaryKey": true,
515-
"notNull": true
517+
"notNull": true,
518+
"default": "gen_random_uuid()"
516519
},
517520
"identifier": {
518521
"name": "identifier",

examples/erp/drizzle/meta/_journal.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
{
66
"idx": 0,
77
"version": "7",
8-
"when": 1747801342316,
9-
"tag": "0000_peaceful_leper_queen",
8+
"when": 1747986947161,
9+
"tag": "0000_freezing_the_order",
1010
"breakpoints": true
1111
}
1212
]

examples/erp/drizzlify/config.ts

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,64 @@
11
import z from 'zod'
22

3-
import { wrapNextJs } from '@kivotos/next'
3+
import { defineServerConfig } from '@kivotos/core'
4+
import { defineNextJsServerConfig } from '@kivotos/next'
45

56
import { categoriesCollection } from './collections/categories'
67
import { postsCollection } from './collections/posts'
78
import { usersCollection } from './collections/users'
89
import { baseConfig, builder } from './helper'
910

10-
const serverConfig = wrapNextJs(
11-
baseConfig.toServerConfig({
12-
collections: [usersCollection, postsCollection, categoriesCollection],
13-
endpoints: {
14-
customOne: builder.endpoint(
15-
{
16-
path: '/hello',
17-
query: z.object({
18-
name: z.string().optional(),
11+
const baseServerConfig = defineServerConfig(baseConfig, {
12+
collections: [usersCollection, postsCollection, categoriesCollection],
13+
endpoints: {
14+
customOne: builder.endpoint(
15+
{
16+
path: '/hello',
17+
query: z.object({
18+
name: z.string().optional(),
19+
}),
20+
method: 'GET',
21+
responses: {
22+
200: z.object({
23+
message: z.string(),
1924
}),
20-
method: 'GET',
21-
responses: {
22-
200: z.object({
23-
message: z.string(),
24-
}),
25-
},
2625
},
27-
({ query }) => {
28-
return {
29-
status: 200 as const,
30-
body: {
31-
message: `Hello ${query.name ?? 'World'}`,
32-
},
33-
}
26+
},
27+
({ query }) => {
28+
return {
29+
status: 200 as const,
30+
body: {
31+
message: `Hello ${query.name ?? 'World'}`,
32+
},
3433
}
35-
),
36-
customTwo: builder.endpoint(
37-
{
38-
path: '/hello2',
39-
query: z.object({
40-
name: z.string().optional(),
34+
}
35+
),
36+
customTwo: builder.endpoint(
37+
{
38+
path: '/hello2',
39+
query: z.object({
40+
name: z.string().optional(),
41+
}),
42+
method: 'GET',
43+
responses: {
44+
200: z.object({
45+
message: z.string(),
4146
}),
42-
method: 'GET',
43-
responses: {
44-
200: z.object({
45-
message: z.string(),
46-
}),
47-
},
4847
},
49-
({ query }) => {
50-
return {
51-
status: 200 as const,
52-
body: {
53-
message: `Hello2 ${query.name ?? 'World'}`,
54-
},
55-
}
48+
},
49+
({ query }) => {
50+
return {
51+
status: 200 as const,
52+
body: {
53+
message: `Hello2 ${query.name ?? 'World'}`,
54+
},
5655
}
57-
),
58-
},
59-
})
60-
)
56+
}
57+
),
58+
},
59+
})
60+
61+
const serverConfig = defineNextJsServerConfig(baseServerConfig)
6162

6263
export type ServerConfig = typeof serverConfig
6364
export { serverConfig }

examples/erp/drizzlify/helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const pool = new Pool({
99
connectionString: process.env.DATABASE_URL,
1010
})
1111

12-
const db = drizzle({ client: pool, schema: schema })
12+
const db = drizzle({ client: pool, schema: schema, logger: true })
1313

1414
export const baseConfig = defineBaseConfig({
1515
db: db,

examples/erp/src/app/(admin)/admin/[...segments]/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { RootPage } from '@kivotos/next'
22

33
import { serverConfig } from '~/drizzlify/config'
44

5+
import { serverFunction } from '../../_helper/server'
6+
57
interface AdminPageProps {
68
params: Promise<{ segments: string[] }>
79
searchParams: Promise<{ [key: string]: string | string[] }>
@@ -11,6 +13,7 @@ export default async function AdminPage(props: AdminPageProps) {
1113
return (
1214
<RootPage
1315
serverConfig={serverConfig}
16+
serverFunction={serverFunction}
1417
paramsPromise={props.params}
1518
searchParamsPromise={props.searchParams}
1619
/>

packages/core/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
},
1818
"dependencies": {
1919
"better-auth": "^1.2.7",
20+
"cookie-es": "^2.0.0",
2021
"drizzle-orm": "^0.41.0",
2122
"remeda": "^2.21.2",
2223
"valibot": "^1.0.0",
23-
"zod": "3.24.4"
24+
"zod": "3.24.4",
25+
"zod-to-json-schema": "^3.24.5"
2426
},
2527
"devDependencies": {
28+
"@types/json-schema": "^7.0.15",
2629
"clsx": "^2.1.1",
2730
"tailwind-merge": "^3.0.2",
2831
"tailwind-variants": "^1.0.0",

0 commit comments

Comments
 (0)