Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions examples/erp/drizzlify/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,27 @@ export const baseConfig = defineBaseConfig({
db: db,
schema: schema,
auth: {
user: { model: schema.users },
account: { model: schema.accounts },
session: { model: schema.sessions },
verification: { model: schema.verifications },
secret: 'secret',
user: {
model: schema.users,
},
session: {
model: schema.sessions,
},
account: {
model: schema.accounts,
},
verification: {
model: schema.verifications,
},
emailAndPassword: {
enabled: true,
// sendEmailVerfication(email) {
// console.log('sendEmailVerfication', email)
// },
// skipEmailVerification: false,
},
secret: '',
},
context: {},
})

export const builder = new Builder(baseConfig).$context<typeof baseConfig.context>()
8 changes: 1 addition & 7 deletions examples/erp/src/app/(admin)/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import { RootLayout } from '@kivotos/next'

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

import { serverFunction } from '../_helper/server'

export default function Layout({ children }: { children: React.ReactNode }) {
return (
<RootLayout serverConfig={serverConfig} serverFunction={serverFunction}>
{children}
</RootLayout>
)
return <RootLayout serverConfig={serverConfig}>{children}</RootLayout>
}
11 changes: 11 additions & 0 deletions packages/core/src/auth/handlers/sign-in-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
prefix?: string
}

export function signInEmail<const TOptions extends InternalRouteOptions>(options: TOptions) {

Check warning on line 12 in packages/core/src/auth/handlers/sign-in-email.ts

View workflow job for this annotation

GitHub Actions / ci

'options' is defined but never used. Allowed unused args must match /^_/u
const schema = {
method: 'POST',
path: '/api/auth/sign-in-email',
Expand All @@ -31,6 +31,17 @@
} as const satisfies ApiRouteSchema

const handler: ApiRouteHandler<AuthContext, typeof schema> = async (args) => {
console.log('signInEmail handler', args)

// return {
// status: 200,
// headers: new Headers(),
// body: {
// token: 'test token',
// user: 'test user',
// },
// }

const account = await args.context.internalHandlers.account.findByUserEmailAndProvider(
args.body.email,
AccountProvider.CREDENTIAL
Expand Down
33 changes: 30 additions & 3 deletions packages/core/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createAuthHandlers } from './handlers'

import type { MinimalContext } from '../config'
import type { ApiRouteHandler } from '../endpoint'
import type { Fields } from '../field'

export type AnyTypedColumn<T> = AnyColumn & { _: { data: T; dialect: 'pg' } }
export type WithNotNull<T> = T & { _: { notNull: true } }
Expand Down Expand Up @@ -76,13 +77,16 @@ export interface AuthConfig {
verification: {
model: AnyVerificationTable
}
login?: {
emailAndPassword?: {
enabled: boolean
emailAndPassword?: {
enabled: boolean
signUp?: {
// TODO: Typesafe
additionalFields?: Record<string, Fields>
}
}
oauth2?: {
google?: {
enabled: boolean
clientId: string
clientSecret: string
}
Expand All @@ -93,6 +97,12 @@ export interface AuthConfig {
resetPasswordUrl?: string // default: `/auth/reset-password`
redirectTo?: string // default: `/auth/login`
}
ui?: {
login?: {
strategies?: { style?: string; text: string; href: string }[]
}
signUp?: {}
}
}

type ChangeAuthHandlerContextToMinimalContext<
Expand Down Expand Up @@ -129,6 +139,23 @@ export type Auth<
>
}

export type AuthClient = {
login: {
emailAndPassword: {
enabled: boolean
}
}
resetPassword: {
enabled: boolean
redirectTo: string
}
ui: {
login: {
strategies: { style: string; text: string; href: string }[]
}
}
}

export function createAuth<TContext extends MinimalContext<any> = MinimalContext<any>>(
config: AuthConfig,
context: TContext
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { NodePgDatabase } from 'drizzle-orm/node-postgres'
import * as R from 'remeda'
import type { Simplify } from 'type-fest'

import { type AuthConfig, createAuth } from './auth'
import { type AuthClient, type AuthConfig, createAuth } from './auth'
import {
type ClientCollection,
type Collection,
Expand Down Expand Up @@ -118,6 +118,7 @@ export interface ClientConfig<
TCollections extends ClientCollection[] = ClientCollection[],
TApiRouter extends ClientApiRouter = ClientApiRouter,
> {
auth: AuthClient
collections: TCollections
$types: {
endpoints: TApiRouter
Expand All @@ -126,7 +127,7 @@ export interface ClientConfig<

export function getBaseField<const TField extends Field>(name: string, field: TField): FieldClient {
if (isRelationField(field)) {
if (['connect', 'connectOrCreate', 'create'].includes(field.type)) {
if (field.type === 'create' || field.type === 'connectOrCreate') {
const sanitizedFields = Object.fromEntries(
Object.entries(field.fields).map(([key, value]) => {
return [key, getBaseField(key, value)]
Expand Down Expand Up @@ -184,6 +185,8 @@ export function getClientConfig<const TServerConfig extends ServerConfig<any, an
const collections = serverConfig.collections

return {
// TODO: Fix this
auth: {},
collections: collections.map(getClientCollection) as ToClientCollectionList<
TServerConfig['collections']
>,
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@
verification: {
model: schema.verifications,
},
login: {
emailAndPassword: {
emailAndPassword: {
enabled: true,
},
oauth2: {
google: {
enabled: true,
clientId: '',
clientSecret: '',
},
},
secret: '',
Expand Down Expand Up @@ -145,8 +150,8 @@
}),
},
},
({ context, body }) => {

Check warning on line 153 in packages/core/src/spec.ts

View workflow job for this annotation

GitHub Actions / ci

'context' is defined but never used. Allowed unused args must match /^_/u
const name = body.name

Check warning on line 154 in packages/core/src/spec.ts

View workflow job for this annotation

GitHub Actions / ci

'name' is assigned a value but never used. Allowed unused vars must match /^_/u
return {
status: 200 as const,
body: {
Expand Down
9 changes: 7 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@hookform/resolvers": "^5.0.1",
"@intentui/icons": "^1.10.31",
"@kivotos/core": "workspace:^",
"@phosphor-icons/react": "^2.1.8",
"@radix-ui/react-slot": "^1.2.0",
"@phosphor-icons/react": "^2.1.8",
"@kivotos/core": "workspace:^",
"@tanstack/react-query": "^5.71.5",
"@tanstack/react-table": "^8.21.2",
"@tanstack/react-virtual": "^3.13.6",
"class-variance-authority": "^0.7.1",
"deepmerge-ts": "^7.1.5",
"drizzle-orm": "^0.41.0",
"input-otp": "^1.4.2",
"motion": "^12.7.4",
"next": "15.2.2",
"radix3": "^1.1.2",
"react": "^19.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import React from 'react'
import { DatabaseIcon } from '@phosphor-icons/react'
import { usePathname } from 'next/navigation'

import { SidebarItem } from '../../../intentui/ui/sidebar'
import {
SidebarDisclosure,
SidebarDisclosurePanel,
SidebarDisclosureTrigger,
SidebarItem,
SidebarLabel,
} from '../../../intentui/ui/sidebar'
import { SidebarDisclosure } from '../../../intentui/ui/sidebar'
import { formatSlug } from '../../../utils/format-slug'
import { BaseIcon } from '../../primitives/base-icon'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use client'

import { CompassIcon } from '@phosphor-icons/react/dist/ssr'
import { usePathname } from 'next/navigation'

import {
SidebarDisclosure,
SidebarDisclosurePanel,
SidebarDisclosureTrigger,
SidebarItem,
SidebarLabel,
} from '../../../intentui/ui/sidebar'
import { SidebarDisclosure } from '../../../intentui/ui/sidebar'
import { SidebarItem } from '../../../intentui/ui/sidebar'
import { BaseIcon } from '../../primitives/base-icon'

export const NavigationSection = ({ id }: { id: number }) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/components/nav.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client'

import { useParams } from 'next/navigation'

interface NavProps {}
Expand Down
2 changes: 0 additions & 2 deletions packages/next/src/components/primitives/typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { cn } from '../../utils/cn'

type TypographyTag = 'h1' | 'h2' | 'h3' | 'h4' | 'body' | 'label' | 'caption'

type TypographyWeight = 'normal' | 'medium' | 'semibold' | 'bold'

const nativeElementsMap: Record<TypographyTag, React.ElementType> = {
h1: 'h1',
h2: 'h2',
Expand Down
8 changes: 7 additions & 1 deletion packages/next/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
export { AutoField } from './components/auto-field'
export { Nav } from './components/nav'
export { RootLayout } from './layouts/root'
export { RootCollectionLayout as RootLayout } from './layouts/root-collection'
export { ForgotPasswordPage } from './pages/auth/forgot-password'
export { LoginPage } from './pages/auth/login/index'
export { RegisterPage } from './pages/auth/register/index'
export { ResetPasswordConfirmPage } from './pages/auth/reset-password'
export { RootAuthPage } from './pages/auth/root-auth'
export { RootPage } from './pages/root'
export { RootCollectionPage } from './pages/root-collection'
export { UIPlayground } from './pages/ui-playground'
export { createApiResourceRouter } from './resource'
export { handleServerFunction, type ServerFunction } from './server-function'
Expand Down
Loading
Loading