Skip to content

About

A flexible and extensible validation plugin for the Better Auth framework. This package allows developers to validate API request using standard schema library

Resources

Stars

73 stars

Watchers

2 watching

Forks

Repository files navigation

validation-better-auth

A flexible and extensible validation plugin for the Better Auth framework. This package allows developers to validate API request using any standard schema library (e.g. Zod, Valibot, ArkType). We also support Yup by wrapping the schema internally to Standard Schema.

Note: This package is used for type validation for api endpoint backend which used for validate the custom schema rather than normal string validation (e.g: password: John@123)

usage using standardSchema

import { betterAuth } from "better-auth"
import { validator, StandardAdapter} from "validation-better-auth"
 
export const auth = betterAuth({
    // ... other config options
    appName: "My App", // provide your app name. It'll be used as an issuer.
    plugins: [
        validator(
      [
        {
          path: "/sign-up/email", 
          schema: SignupSchema,
          before: (ctx) => {
            console.log(ctx)
          },
          after: (ctx) => {
            console.log(ctx)
          }
        },
        {
          path: "/sign-in/email", 
          schema: SignInSchema,
          before: (ctx) => {
            console.log(ctx)
          },
          after: (ctx) => {
            console.log(ctx)
          }
        },
      ]
    ),
    ]
})

usage using adapters (for non supported standardSchema)

import { betterAuth } from "better-auth"
import { validator, StandardAdapter} from "validation-better-auth"
 
export const auth = betterAuth({
    // ... other config options
    appName: "My App", // provide your app name. It'll be used as an issuer.
    plugins: [
        validator(
      [
        {
          path: "/sign-up/email", 
          adapter: YupAdapter(SignupSchema),
          before: (ctx) => {
            console.log(ctx)
          },
          after: (ctx) => {
            console.log(ctx)
          }
        },
        {
          path: "/sign-in/email", 
          adapter: YupAdapter(SignInSchema),
          before: (ctx) => {
            console.log(ctx)
          },
          after: (ctx) => {
            console.log(ctx)
          }
        },
      ]
    ),
    ]
})

About

A flexible and extensible validation plugin for the Better Auth framework. This package allows developers to validate API request using standard schema library

Resources

Stars

73 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages