Skip to content

Conversation

@saenyakorn
Copy link
Member

Why I did

  • To make basic authentication (e.g. login with email and password, sign up with email and password) works.
  • To guard collection pages (only authenticated and have ENOUGH permission can enter the page).
  • To guard

What I did

  • Integrated login and sign up page with serverFunction
  • Fixed login and sign up API
  • Fixed setting up cookie in NextJS server function
  • Changed field_.fieldName to field.fieldName
  • Introduced NextJsServerConfig which enhance serverConfig from core package
  • Make endpoints sendable to client-side with JSONSchema7 specification. (serialize zod to JSONSchema7)

@saenyakorn saenyakorn requested a review from Copilot May 23, 2025 12:09
@changeset-bot
Copy link

changeset-bot bot commented May 23, 2025

🦋 Changeset detected

Latest commit: df47273

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@saenyakorn saenyakorn requested review from SupakornNetsuwan and Copilot and removed request for SupakornNetsuwan and Copilot May 23, 2025 12:09
@saenyakorn saenyakorn changed the base branch from main to yu/feat/auth May 23, 2025 12:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements basic authentication for login and sign up, along with guarding collection pages based on user permissions. Key changes include updating authentication handlers and endpoints, integrating serverFunction into Next.js layouts, and refining type and cookie handling for sessions.

Reviewed Changes

Copilot reviewed 70 out of 70 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/core/src/builder.handler.ts Updates field property references to remove the underscore prefix.
packages/core/src/auth/utils.ts Refactors cookie handling with the new cookie-es package and updates getSessionCookie.
packages/core/src/auth/index.ts Updates table types and introduces getAuthClient with enhanced type definitions.
packages/core/src/auth/handlers/sign-up.ts Implements password length validation and adds secure cookie header in the response.
packages/core/src/auth/handlers/login-email.ts Renames signInEmail to loginEmail and updates session creation to use account.user.id.
packages/core/src/auth/handlers/index.ts Updates handler mapping for login to use the new loginEmail function.
packages/core/src/auth/context.ts Modifies session retrieval to use tokens and renames findUserBySessionId accordingly.
packages/core/src/mocks/complex-schema.ts Adjusts mock schema to use uuid with default random generation instead of text.
packages/core/package.json Adds dependencies for cookie-es, zod-to-json-schema, and @types/json-schema.
examples/erp/src/app/(admin)/api/[...segments]/route.ts Switches from createApiResourceRouter to using serverConfig.resourceRouter.
examples/erp/src/app/(admin)/admin/layout.ts Updates import paths and adds serverFunction to the layout configuration.
examples/erp/src/app/(admin)/admin/[...segments]/page.tsx Adds serverFunction property to the RootPage for proper configuration.
examples/erp/drizzlify/helper.ts Enables logging on the drizzle client configuration for debugging.
examples/erp/drizzlify/config.ts Adopts Next.js server config by composing with defineNextJsServerConfig.
examples/erp/drizzle/meta and schema files Updates database schema and migration files to use uuid defaults.
.vscode/settings.json & .changeset/polite-games-help.md Minor configuration and changelog updates.
Comments suppressed due to low confidence (2)

packages/core/src/auth/handlers/login-email.ts:45

  • Replace the current password comparison logic with a proper hashing mechanism to securely compare the submitted password with the stored hash.
if (account.password !== hashPassword) {

packages/core/src/auth/index.ts:22

  • Confirm that switching to an auto-generated UUID (using WithHasDefault) for the 'id' field does not conflict with any downstream logic that might expect manual ID assignment.
id: WithHasDefault<WithNotNull<AnyTypedColumn<string>>>,

Base automatically changed from yu/feat/auth to main May 26, 2025 06:04
Copy link
Contributor

@miello miello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Sign up form does not have validation yet
image

@saenyakorn
Copy link
Member Author

  • Sign up form does not have validation yet

TODO here: https://app.plane.so/softnetics/browse/DRIZZ-76/

}
emailAndPassword?: {
enabled: boolean
passwordHasher?: (password: string) => Promise<string> // default: bcrypt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
passwordHasher?: (password: string) => Promise<string> // default: bcrypt
passwordHasher?: (password: string) => Promise<string> // default: scrypt

@saenyakorn saenyakorn merged commit 76ce28f into main May 27, 2025
1 check passed
@saenyakorn saenyakorn deleted the yu/feat/auth-2 branch May 27, 2025 12:34
This was referenced Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants