@next-safe-action/adapter-better-auth 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Auth, BetterAuthOptions } from \"better-auth\";\nimport { createMiddleware } from \"next-safe-action\";\nimport type { MiddlewareFn } from \"next-safe-action\";\nimport { headers } from \"next/headers\";\nimport { unauthorized } from \"next/navigation\";\nimport type { BetterAuthContext, BetterAuthOpts } from \"./index.types\";\n\n/**\n * Creates a next-safe-action middleware that integrates with better-auth.\n *\n * Default behavior: fetches the session via `auth.api.getSession()`, calls `unauthorized()` if\n * no session exists, and injects `{ auth: { user, session } }` into the action context.\n *\n * Pass an `authorize` callback to customize the authorization flow. The session is pre-fetched\n * and passed to the callback, so common customizations (e.g. role checks) don't need to re-fetch.\n *\n * Note: `unauthorized()` requires `experimental.authInterrupts: true` in your `next.config.ts` file.\n *\n * @example\n * ```ts\n * // Default: fetch session, unauthorized() if absent\n * actionClient.use(betterAuth(auth));\n *\n * // Custom: check role\n * actionClient.use(betterAuth(auth, {\n * authorize: ({ authData, next }) => {\n * if (!authData || authData.user.role !== \"admin\") {\n * unauthorized();\n * }\n * return next({ ctx: { auth: authData } });\n * },\n * }));\n * ```\n */\nexport function betterAuth<O extends BetterAuthOptions>(\n\tauth: Auth<O>\n): MiddlewareFn<any, any, object, BetterAuthContext<O>>;\nexport function betterAuth<O extends BetterAuthOptions, NC extends object, Ctx extends object>(\n\tauth: Auth<O>,\n\topts: BetterAuthOpts<O, NC, Ctx>\n): MiddlewareFn<any, any, Ctx, NC>;\nexport function betterAuth<O extends BetterAuthOptions>(\n\tauth: Auth<O>,\n\topts?: BetterAuthOpts<O, any, any>\n) {\n\treturn createMiddleware().define(async ({ ctx, next }) => {\n\t\tconst authData = await auth.api.getSession({ headers: await headers() });\n\n\t\tif (opts?.authorize) {\n\t\t\treturn opts.authorize({ authData, ctx, next });\n\t\t}\n\n\t\tif (!authData) {\n\t\t\tunauthorized();\n\t\t}\n\n\t\treturn next({ ctx: { auth: { user: authData.user, session: authData.session } } });\n\t});\n}\n\nexport type { AuthorizeFn, BetterAuthContext, BetterAuthOpts } from \"./index.types\";\n"],"mappings":";;;;AAyCA,SAAgB,WACf,MACA,MACC;AACD,QAAO,kBAAkB,CAAC,OAAO,OAAO,EAAE,KAAK,WAAW;EACzD,MAAM,WAAW,MAAM,KAAK,IAAI,WAAW,EAAE,SAAS,MAAM,SAAS,EAAE,CAAC;AAExE,MAAI,MAAM,UACT,QAAO,KAAK,UAAU;GAAE;GAAU;GAAK;GAAM,CAAC;AAG/C,MAAI,CAAC,SACJ,eAAc;AAGf,SAAO,KAAK,EAAE,KAAK,EAAE,MAAM;GAAE,MAAM,SAAS;GAAM,SAAS,SAAS;GAAS,EAAE,EAAE,CAAC;GACjF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Auth, BetterAuthOptions } from \"better-auth\";\nimport { createMiddleware } from \"next-safe-action\";\nimport type { MiddlewareFn } from \"next-safe-action\";\nimport { headers } from \"next/headers\";\nimport { unauthorized } from \"next/navigation\";\nimport type { BetterAuthContext, BetterAuthOpts, BetterAuthSessionApi } from \"./index.types\";\n\n/**\n * Creates a next-safe-action middleware that integrates with better-auth.\n *\n * Default behavior: fetches the session via `auth.api.getSession()`, calls `unauthorized()` if\n * no session exists, and injects `{ auth: { user, session } }` into the action context.\n *\n * Pass an `authorize` callback to customize the authorization flow. The session is pre-fetched\n * and passed to the callback, so common customizations (e.g. role checks) don't need to re-fetch.\n *\n * Note: `unauthorized()` requires `experimental.authInterrupts: true` in your `next.config.ts` file.\n *\n * @example\n * ```ts\n * // Default: fetch session, unauthorized() if absent\n * actionClient.use(betterAuth(auth));\n *\n * // Custom: check role\n * actionClient.use(betterAuth(auth, {\n * authorize: ({ authData, next }) => {\n * if (!authData || authData.user.role !== \"admin\") {\n * unauthorized();\n * }\n * return next({ ctx: { auth: authData } });\n * },\n * }));\n * ```\n */\nexport function betterAuth<O extends BetterAuthOptions>(\n\tauth: Auth<O>\n): MiddlewareFn<any, any, object, BetterAuthContext<O>>;\nexport function betterAuth<O extends BetterAuthOptions, NC extends object, Ctx extends object>(\n\tauth: Auth<O>,\n\topts: BetterAuthOpts<O, NC, Ctx>\n): MiddlewareFn<any, any, Ctx, NC>;\nexport function betterAuth<O extends BetterAuthOptions>(auth: Auth<O>, opts?: BetterAuthOpts<O, any, any>) {\n\treturn createMiddleware().define(async ({ ctx, next }) => {\n\t\tconst api = auth.api as unknown as BetterAuthSessionApi<O>;\n\t\tconst authData = await api.getSession({ headers: await headers() });\n\n\t\tif (opts?.authorize) {\n\t\t\treturn opts.authorize({ authData, ctx, next });\n\t\t}\n\n\t\tif (!authData) {\n\t\t\tunauthorized();\n\t\t}\n\t\treturn next({\n\t\t\tctx: { auth: { user: authData.user, session: authData.session } },\n\t\t});\n\t});\n}\n\nexport type { AuthorizeFn, BetterAuthContext, BetterAuthOpts } from \"./index.types\";\n"],"mappings":";;;;AAyCA,SAAgB,WAAwC,MAAe,MAAoC;AAC1G,QAAO,kBAAkB,CAAC,OAAO,OAAO,EAAE,KAAK,WAAW;EAEzD,MAAM,WAAW,MADL,KAAK,IACU,WAAW,EAAE,SAAS,MAAM,SAAS,EAAE,CAAC;AAEnE,MAAI,MAAM,UACT,QAAO,KAAK,UAAU;GAAE;GAAU;GAAK;GAAM,CAAC;AAG/C,MAAI,CAAC,SACJ,eAAc;AAEf,SAAO,KAAK,EACX,KAAK,EAAE,MAAM;GAAE,MAAM,SAAS;GAAM,SAAS,SAAS;GAAS,EAAE,EACjE,CAAC;GACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next-safe-action/adapter-better-auth",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "description": "Better Auth adapter for next-safe-action.",
6
6
  "main": "./dist/index.mjs",
@@ -55,7 +55,7 @@
55
55
  "license": "MIT",
56
56
  "devDependencies": {
57
57
  "@types/node": "^24",
58
- "better-auth": "^1.5.6",
58
+ "better-auth": "^1.6.0",
59
59
  "next": "^16",
60
60
  "oxlint": "^1.57.0",
61
61
  "oxlint-tsgolint": "^0.15.0",