better-auth 0.2.3-beta.8 → 0.2.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.
package/dist/next-js.js CHANGED
@@ -1 +1,34 @@
1
- import{betterFetch as a}from"@better-fetch/fetch";import{NextResponse as n}from"next/server";function l(e){let r=async t=>"handler"in e?e.handler(t):e(t);return{GET:r,POST:r}}function m(e){return async r=>{let t=new URL(r.url).origin,o=e?.baePath||"/api/auth",i=`${t}${o}/session`,s=(await a(i,{headers:r.headers})).data||null;return e.customRedirect?e.customRedirect(s,r):s?n.next():n.redirect(new URL(e.redirectTo||"/",t))}}export{m as authMiddleware,l as toNextJsHandler};
1
+ // src/integrations/next-js.ts
2
+ import { betterFetch } from "@better-fetch/fetch";
3
+ import { NextResponse } from "next/server";
4
+ function toNextJsHandler(auth) {
5
+ const handler = async (request) => {
6
+ return "handler" in auth ? auth.handler(request) : auth(request);
7
+ };
8
+ return {
9
+ GET: handler,
10
+ POST: handler
11
+ };
12
+ }
13
+ function authMiddleware(options) {
14
+ return async (request) => {
15
+ const url = new URL(request.url).origin;
16
+ const basePath = options?.baePath || "/api/auth";
17
+ const fullURL = `${url}${basePath}/session`;
18
+ const res = await betterFetch(fullURL, {
19
+ headers: request.headers
20
+ });
21
+ const session = res.data || null;
22
+ if (options.customRedirect) {
23
+ return options.customRedirect(session, request);
24
+ }
25
+ if (!session) {
26
+ return NextResponse.redirect(new URL(options.redirectTo || "/", url));
27
+ }
28
+ return NextResponse.next();
29
+ };
30
+ }
31
+ export {
32
+ authMiddleware,
33
+ toNextJsHandler
34
+ };
package/dist/node.js CHANGED
@@ -1 +1,8 @@
1
- import{toNodeHandler as r}from"better-call";var t=o=>"handler"in o?r(o.handler):r(o);export{t as toNodeHandler};
1
+ // src/integrations/node.ts
2
+ import { toNodeHandler as toNode } from "better-call";
3
+ var toNodeHandler = (auth) => {
4
+ return "handler" in auth ? toNode(auth.handler) : toNode(auth);
5
+ };
6
+ export {
7
+ toNodeHandler
8
+ };