@saas-maker/auth-preset 0.1.0

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/client.js ADDED
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/client.ts
21
+ var client_exports = {};
22
+ __export(client_exports, {
23
+ AuthProvider: () => AuthProvider,
24
+ createFoundryAuthClient: () => createFoundryAuthClient,
25
+ useAuthClient: () => useAuthClient,
26
+ useSession: () => useSession
27
+ });
28
+ module.exports = __toCommonJS(client_exports);
29
+ var import_react = require("react");
30
+ var import_react2 = require("better-auth/react");
31
+ function resolveBaseURL(opts = {}) {
32
+ if (opts.baseURL)
33
+ return opts.baseURL;
34
+ if (typeof window !== "undefined")
35
+ return window.location.origin;
36
+ if (typeof process !== "undefined") {
37
+ return process.env?.["AUTH_URL"] ?? process.env?.["NEXTAUTH_URL"];
38
+ }
39
+ return void 0;
40
+ }
41
+ function createFoundryAuthClient(opts = {}) {
42
+ return (0, import_react2.createAuthClient)({ baseURL: resolveBaseURL(opts) });
43
+ }
44
+ var AuthClientContext = (0, import_react.createContext)(null);
45
+ function AuthProvider({ client, children, ...opts }) {
46
+ const value = client ?? createFoundryAuthClient(opts);
47
+ return (0, import_react.createElement)(AuthClientContext.Provider, { value }, children);
48
+ }
49
+ function useAuthClient() {
50
+ const ctx = (0, import_react.useContext)(AuthClientContext);
51
+ if (!ctx) {
52
+ throw new Error("useAuthClient() called outside <AuthProvider>");
53
+ }
54
+ return ctx;
55
+ }
56
+ function useSession() {
57
+ const client = useAuthClient();
58
+ return client.useSession();
59
+ }
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ AuthProvider,
63
+ createFoundryAuthClient,
64
+ useAuthClient,
65
+ useSession
66
+ });
67
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts"],"sourcesContent":["/**\n * Browser entrypoint — better-auth React client + <AuthProvider> + useSession() hook.\n */\n\nimport { createContext, createElement, useContext, type ReactNode } from 'react';\nimport { createAuthClient } from 'better-auth/react';\n\ndeclare const process: { env?: Record<string, string | undefined> } | undefined;\n\nexport interface AuthClientOpts {\n /** baseURL of your auth-bearing app. Falls back to window.location.origin or AUTH_URL. */\n baseURL?: string;\n}\n\nfunction resolveBaseURL(opts: AuthClientOpts = {}): string | undefined {\n if (opts.baseURL) return opts.baseURL;\n if (typeof window !== 'undefined') return window.location.origin;\n if (typeof process !== 'undefined') {\n return process.env?.['AUTH_URL'] ?? process.env?.['NEXTAUTH_URL'];\n }\n return undefined;\n}\n\nexport function createFoundryAuthClient(opts: AuthClientOpts = {}) {\n return createAuthClient({ baseURL: resolveBaseURL(opts) });\n}\n\nexport type FoundryAuthClient = ReturnType<typeof createFoundryAuthClient>;\n\nconst AuthClientContext = createContext<FoundryAuthClient | null>(null);\n\nexport interface AuthProviderProps extends AuthClientOpts {\n client?: FoundryAuthClient;\n children: ReactNode;\n}\n\n/**\n * Provides a single auth client instance to the React tree.\n * Pass an existing `client` to share with non-React code, or let the provider create one.\n */\nexport function AuthProvider({ client, children, ...opts }: AuthProviderProps) {\n const value = client ?? createFoundryAuthClient(opts);\n return createElement(AuthClientContext.Provider, { value }, children);\n}\n\nexport function useAuthClient(): FoundryAuthClient {\n const ctx = useContext(AuthClientContext);\n if (!ctx) {\n throw new Error('useAuthClient() called outside <AuthProvider>');\n }\n return ctx;\n}\n\n/**\n * Returns the current session via better-auth's useSession.\n */\nexport function useSession() {\n const client = useAuthClient();\n return client.useSession();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAyE;AACzE,IAAAA,gBAAiC;AASjC,SAAS,eAAe,OAAuB,CAAC,GAAuB;AACrE,MAAI,KAAK;AAAS,WAAO,KAAK;AAC9B,MAAI,OAAO,WAAW;AAAa,WAAO,OAAO,SAAS;AAC1D,MAAI,OAAO,YAAY,aAAa;AAClC,WAAO,QAAQ,MAAM,UAAU,KAAK,QAAQ,MAAM,cAAc;AAAA,EAClE;AACA,SAAO;AACT;AAEO,SAAS,wBAAwB,OAAuB,CAAC,GAAG;AACjE,aAAO,gCAAiB,EAAE,SAAS,eAAe,IAAI,EAAE,CAAC;AAC3D;AAIA,IAAM,wBAAoB,4BAAwC,IAAI;AAW/D,SAAS,aAAa,EAAE,QAAQ,UAAU,GAAG,KAAK,GAAsB;AAC7E,QAAM,QAAQ,UAAU,wBAAwB,IAAI;AACpD,aAAO,4BAAc,kBAAkB,UAAU,EAAE,MAAM,GAAG,QAAQ;AACtE;AAEO,SAAS,gBAAmC;AACjD,QAAM,UAAM,yBAAW,iBAAiB;AACxC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE;AACA,SAAO;AACT;AAKO,SAAS,aAAa;AAC3B,QAAM,SAAS,cAAc;AAC7B,SAAO,OAAO,WAAW;AAC3B;","names":["import_react"]}
@@ -0,0 +1,39 @@
1
+ // src/client.ts
2
+ import { createContext, createElement, useContext } from "react";
3
+ import { createAuthClient } from "better-auth/react";
4
+ function resolveBaseURL(opts = {}) {
5
+ if (opts.baseURL)
6
+ return opts.baseURL;
7
+ if (typeof window !== "undefined")
8
+ return window.location.origin;
9
+ if (typeof process !== "undefined") {
10
+ return process.env?.["AUTH_URL"] ?? process.env?.["NEXTAUTH_URL"];
11
+ }
12
+ return void 0;
13
+ }
14
+ function createFoundryAuthClient(opts = {}) {
15
+ return createAuthClient({ baseURL: resolveBaseURL(opts) });
16
+ }
17
+ var AuthClientContext = createContext(null);
18
+ function AuthProvider({ client, children, ...opts }) {
19
+ const value = client ?? createFoundryAuthClient(opts);
20
+ return createElement(AuthClientContext.Provider, { value }, children);
21
+ }
22
+ function useAuthClient() {
23
+ const ctx = useContext(AuthClientContext);
24
+ if (!ctx) {
25
+ throw new Error("useAuthClient() called outside <AuthProvider>");
26
+ }
27
+ return ctx;
28
+ }
29
+ function useSession() {
30
+ const client = useAuthClient();
31
+ return client.useSession();
32
+ }
33
+ export {
34
+ AuthProvider,
35
+ createFoundryAuthClient,
36
+ useAuthClient,
37
+ useSession
38
+ };
39
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts"],"sourcesContent":["/**\n * Browser entrypoint — better-auth React client + <AuthProvider> + useSession() hook.\n */\n\nimport { createContext, createElement, useContext, type ReactNode } from 'react';\nimport { createAuthClient } from 'better-auth/react';\n\ndeclare const process: { env?: Record<string, string | undefined> } | undefined;\n\nexport interface AuthClientOpts {\n /** baseURL of your auth-bearing app. Falls back to window.location.origin or AUTH_URL. */\n baseURL?: string;\n}\n\nfunction resolveBaseURL(opts: AuthClientOpts = {}): string | undefined {\n if (opts.baseURL) return opts.baseURL;\n if (typeof window !== 'undefined') return window.location.origin;\n if (typeof process !== 'undefined') {\n return process.env?.['AUTH_URL'] ?? process.env?.['NEXTAUTH_URL'];\n }\n return undefined;\n}\n\nexport function createFoundryAuthClient(opts: AuthClientOpts = {}) {\n return createAuthClient({ baseURL: resolveBaseURL(opts) });\n}\n\nexport type FoundryAuthClient = ReturnType<typeof createFoundryAuthClient>;\n\nconst AuthClientContext = createContext<FoundryAuthClient | null>(null);\n\nexport interface AuthProviderProps extends AuthClientOpts {\n client?: FoundryAuthClient;\n children: ReactNode;\n}\n\n/**\n * Provides a single auth client instance to the React tree.\n * Pass an existing `client` to share with non-React code, or let the provider create one.\n */\nexport function AuthProvider({ client, children, ...opts }: AuthProviderProps) {\n const value = client ?? createFoundryAuthClient(opts);\n return createElement(AuthClientContext.Provider, { value }, children);\n}\n\nexport function useAuthClient(): FoundryAuthClient {\n const ctx = useContext(AuthClientContext);\n if (!ctx) {\n throw new Error('useAuthClient() called outside <AuthProvider>');\n }\n return ctx;\n}\n\n/**\n * Returns the current session via better-auth's useSession.\n */\nexport function useSession() {\n const client = useAuthClient();\n return client.useSession();\n}\n"],"mappings":";AAIA,SAAS,eAAe,eAAe,kBAAkC;AACzE,SAAS,wBAAwB;AASjC,SAAS,eAAe,OAAuB,CAAC,GAAuB;AACrE,MAAI,KAAK;AAAS,WAAO,KAAK;AAC9B,MAAI,OAAO,WAAW;AAAa,WAAO,OAAO,SAAS;AAC1D,MAAI,OAAO,YAAY,aAAa;AAClC,WAAO,QAAQ,MAAM,UAAU,KAAK,QAAQ,MAAM,cAAc;AAAA,EAClE;AACA,SAAO;AACT;AAEO,SAAS,wBAAwB,OAAuB,CAAC,GAAG;AACjE,SAAO,iBAAiB,EAAE,SAAS,eAAe,IAAI,EAAE,CAAC;AAC3D;AAIA,IAAM,oBAAoB,cAAwC,IAAI;AAW/D,SAAS,aAAa,EAAE,QAAQ,UAAU,GAAG,KAAK,GAAsB;AAC7E,QAAM,QAAQ,UAAU,wBAAwB,IAAI;AACpD,SAAO,cAAc,kBAAkB,UAAU,EAAE,MAAM,GAAG,QAAQ;AACtE;AAEO,SAAS,gBAAmC;AACjD,QAAM,MAAM,WAAW,iBAAiB;AACxC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE;AACA,SAAO;AACT;AAKO,SAAS,aAAa;AAC3B,QAAM,SAAS,cAAc;AAC7B,SAAO,OAAO,WAAW;AAC3B;","names":[]}
@@ -0,0 +1,105 @@
1
+ import * as better_auth from 'better-auth';
2
+
3
+ /**
4
+ * Foundry auth defaults — applied by createAuth() before the user-supplied opts.
5
+ *
6
+ * The actual better-auth instance is constructed in `index.ts` (server) and
7
+ * `client.ts` (browser). This file isolates the defaults so they can be
8
+ * unit-tested without pulling in the full better-auth dependency tree.
9
+ */
10
+ interface FoundryAuthOpts {
11
+ /** D1 binding from the Cloudflare context, e.g. env.DB. */
12
+ d1: unknown;
13
+ /** Drizzle schema for auth tables (user / session / account / verification). */
14
+ schema: Record<string, unknown>;
15
+ /** Optional secret. Reads BETTER_AUTH_SECRET / AUTH_SECRET if omitted. */
16
+ secret?: string;
17
+ /** Public base URL of your auth-bearing app. Reads AUTH_URL if omitted. */
18
+ baseURL?: string;
19
+ /** Google OAuth credentials. Reads GOOGLE_CLIENT_ID / SECRET if omitted. */
20
+ google?: {
21
+ clientId?: string;
22
+ clientSecret?: string;
23
+ };
24
+ /** Trusted redirect origins. */
25
+ trustedOrigins?: string[];
26
+ /** Override session cookie name. Defaults to 'foundry.session'. */
27
+ sessionCookieName?: string;
28
+ /** Set to 'production' to force secure cookies. Reads NODE_ENV otherwise. */
29
+ env?: 'development' | 'production' | 'test';
30
+ }
31
+ interface ResolvedAuthConfig {
32
+ secret: string;
33
+ baseURL: string;
34
+ socialProviders: {
35
+ google: {
36
+ clientId: string;
37
+ clientSecret: string;
38
+ };
39
+ };
40
+ trustedOrigins: string[];
41
+ advanced: {
42
+ cookies: {
43
+ session_token: {
44
+ name: string;
45
+ attributes: {
46
+ secure: boolean;
47
+ sameSite: 'lax';
48
+ httpOnly: true;
49
+ };
50
+ };
51
+ };
52
+ crossSubDomainCookies: {
53
+ enabled: false;
54
+ };
55
+ useSecureCookies: boolean;
56
+ };
57
+ }
58
+ /**
59
+ * Resolves the Foundry auth defaults. Pure function — call this from createAuth()
60
+ * to get the config object, then pass it to betterAuth() with your `database`.
61
+ */
62
+ declare function resolveAuthConfig(opts: FoundryAuthOpts): ResolvedAuthConfig;
63
+
64
+ /**
65
+ * Create a Foundry-standard better-auth instance.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import { createAuth } from '@saas-maker/auth-preset';
70
+ * import * as schema from './auth-schema';
71
+ *
72
+ * const auth = createAuth({ d1: env.DB, schema });
73
+ * ```
74
+ */
75
+ declare function createAuth(opts: FoundryAuthOpts): better_auth.Auth<{
76
+ database: (options: better_auth.BetterAuthOptions) => better_auth.DBAdapter<better_auth.BetterAuthOptions>;
77
+ secret: string;
78
+ baseURL: string;
79
+ socialProviders: {
80
+ google: {
81
+ clientId: string;
82
+ clientSecret: string;
83
+ };
84
+ };
85
+ trustedOrigins: string[];
86
+ advanced: {
87
+ cookies: {
88
+ session_token: {
89
+ name: string;
90
+ attributes: {
91
+ secure: boolean;
92
+ sameSite: "lax";
93
+ httpOnly: true;
94
+ };
95
+ };
96
+ };
97
+ crossSubDomainCookies: {
98
+ enabled: false;
99
+ };
100
+ useSecureCookies: boolean;
101
+ };
102
+ }>;
103
+ type FoundryAuth = ReturnType<typeof createAuth>;
104
+
105
+ export { type FoundryAuth, type FoundryAuthOpts, type ResolvedAuthConfig, createAuth, resolveAuthConfig };
@@ -0,0 +1,105 @@
1
+ import * as better_auth from 'better-auth';
2
+
3
+ /**
4
+ * Foundry auth defaults — applied by createAuth() before the user-supplied opts.
5
+ *
6
+ * The actual better-auth instance is constructed in `index.ts` (server) and
7
+ * `client.ts` (browser). This file isolates the defaults so they can be
8
+ * unit-tested without pulling in the full better-auth dependency tree.
9
+ */
10
+ interface FoundryAuthOpts {
11
+ /** D1 binding from the Cloudflare context, e.g. env.DB. */
12
+ d1: unknown;
13
+ /** Drizzle schema for auth tables (user / session / account / verification). */
14
+ schema: Record<string, unknown>;
15
+ /** Optional secret. Reads BETTER_AUTH_SECRET / AUTH_SECRET if omitted. */
16
+ secret?: string;
17
+ /** Public base URL of your auth-bearing app. Reads AUTH_URL if omitted. */
18
+ baseURL?: string;
19
+ /** Google OAuth credentials. Reads GOOGLE_CLIENT_ID / SECRET if omitted. */
20
+ google?: {
21
+ clientId?: string;
22
+ clientSecret?: string;
23
+ };
24
+ /** Trusted redirect origins. */
25
+ trustedOrigins?: string[];
26
+ /** Override session cookie name. Defaults to 'foundry.session'. */
27
+ sessionCookieName?: string;
28
+ /** Set to 'production' to force secure cookies. Reads NODE_ENV otherwise. */
29
+ env?: 'development' | 'production' | 'test';
30
+ }
31
+ interface ResolvedAuthConfig {
32
+ secret: string;
33
+ baseURL: string;
34
+ socialProviders: {
35
+ google: {
36
+ clientId: string;
37
+ clientSecret: string;
38
+ };
39
+ };
40
+ trustedOrigins: string[];
41
+ advanced: {
42
+ cookies: {
43
+ session_token: {
44
+ name: string;
45
+ attributes: {
46
+ secure: boolean;
47
+ sameSite: 'lax';
48
+ httpOnly: true;
49
+ };
50
+ };
51
+ };
52
+ crossSubDomainCookies: {
53
+ enabled: false;
54
+ };
55
+ useSecureCookies: boolean;
56
+ };
57
+ }
58
+ /**
59
+ * Resolves the Foundry auth defaults. Pure function — call this from createAuth()
60
+ * to get the config object, then pass it to betterAuth() with your `database`.
61
+ */
62
+ declare function resolveAuthConfig(opts: FoundryAuthOpts): ResolvedAuthConfig;
63
+
64
+ /**
65
+ * Create a Foundry-standard better-auth instance.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * import { createAuth } from '@saas-maker/auth-preset';
70
+ * import * as schema from './auth-schema';
71
+ *
72
+ * const auth = createAuth({ d1: env.DB, schema });
73
+ * ```
74
+ */
75
+ declare function createAuth(opts: FoundryAuthOpts): better_auth.Auth<{
76
+ database: (options: better_auth.BetterAuthOptions) => better_auth.DBAdapter<better_auth.BetterAuthOptions>;
77
+ secret: string;
78
+ baseURL: string;
79
+ socialProviders: {
80
+ google: {
81
+ clientId: string;
82
+ clientSecret: string;
83
+ };
84
+ };
85
+ trustedOrigins: string[];
86
+ advanced: {
87
+ cookies: {
88
+ session_token: {
89
+ name: string;
90
+ attributes: {
91
+ secure: boolean;
92
+ sameSite: "lax";
93
+ httpOnly: true;
94
+ };
95
+ };
96
+ };
97
+ crossSubDomainCookies: {
98
+ enabled: false;
99
+ };
100
+ useSecureCookies: boolean;
101
+ };
102
+ }>;
103
+ type FoundryAuth = ReturnType<typeof createAuth>;
104
+
105
+ export { type FoundryAuth, type FoundryAuthOpts, type ResolvedAuthConfig, createAuth, resolveAuthConfig };
package/dist/index.js ADDED
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ createAuth: () => createAuth,
24
+ resolveAuthConfig: () => resolveAuthConfig
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+ var import_better_auth = require("better-auth");
28
+ var import_drizzle = require("better-auth/adapters/drizzle");
29
+ var import_d1 = require("drizzle-orm/d1");
30
+
31
+ // src/config.ts
32
+ function readEnv(key) {
33
+ if (typeof process === "undefined" || !process.env)
34
+ return void 0;
35
+ return process.env[key];
36
+ }
37
+ function resolveAuthConfig(opts) {
38
+ const secret = opts.secret ?? readEnv("BETTER_AUTH_SECRET") ?? readEnv("AUTH_SECRET");
39
+ if (!secret) {
40
+ throw new Error(
41
+ "[auth-preset] missing secret \u2014 set BETTER_AUTH_SECRET or pass `secret` to createAuth()"
42
+ );
43
+ }
44
+ const baseURL = opts.baseURL ?? readEnv("AUTH_URL") ?? readEnv("NEXTAUTH_URL") ?? readEnv("BETTER_AUTH_URL");
45
+ if (!baseURL) {
46
+ throw new Error(
47
+ "[auth-preset] missing baseURL \u2014 set AUTH_URL or pass `baseURL` to createAuth()"
48
+ );
49
+ }
50
+ const googleId = opts.google?.clientId ?? readEnv("GOOGLE_CLIENT_ID") ?? readEnv("AUTH_GOOGLE_ID") ?? "";
51
+ const googleSecret = opts.google?.clientSecret ?? readEnv("GOOGLE_CLIENT_SECRET") ?? readEnv("AUTH_GOOGLE_SECRET") ?? "";
52
+ const env = opts.env ?? readEnv("NODE_ENV") ?? "development";
53
+ const isProd = env === "production";
54
+ return {
55
+ secret,
56
+ baseURL,
57
+ socialProviders: {
58
+ google: { clientId: googleId, clientSecret: googleSecret }
59
+ },
60
+ trustedOrigins: opts.trustedOrigins ?? [baseURL],
61
+ advanced: {
62
+ cookies: {
63
+ session_token: {
64
+ name: opts.sessionCookieName ?? "foundry.session",
65
+ attributes: { secure: isProd, sameSite: "lax", httpOnly: true }
66
+ }
67
+ },
68
+ crossSubDomainCookies: { enabled: false },
69
+ useSecureCookies: isProd
70
+ }
71
+ };
72
+ }
73
+
74
+ // src/index.ts
75
+ function createAuth(opts) {
76
+ const cfg = resolveAuthConfig(opts);
77
+ const db = (0, import_d1.drizzle)(opts.d1, { schema: opts.schema });
78
+ return (0, import_better_auth.betterAuth)({
79
+ database: (0, import_drizzle.drizzleAdapter)(db, { provider: "sqlite", schema: opts.schema }),
80
+ secret: cfg.secret,
81
+ baseURL: cfg.baseURL,
82
+ socialProviders: cfg.socialProviders,
83
+ trustedOrigins: cfg.trustedOrigins,
84
+ advanced: cfg.advanced
85
+ });
86
+ }
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ createAuth,
90
+ resolveAuthConfig
91
+ });
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/config.ts"],"sourcesContent":["/**\n * Server entrypoint — wires better-auth with Foundry defaults + D1 adapter.\n */\n\nimport { betterAuth } from 'better-auth';\nimport { drizzleAdapter } from 'better-auth/adapters/drizzle';\nimport { drizzle } from 'drizzle-orm/d1';\nimport { resolveAuthConfig, type FoundryAuthOpts } from './config.js';\n\nexport type { FoundryAuthOpts, ResolvedAuthConfig } from './config.js';\nexport { resolveAuthConfig } from './config.js';\n\n/**\n * Create a Foundry-standard better-auth instance.\n *\n * @example\n * ```ts\n * import { createAuth } from '@saas-maker/auth-preset';\n * import * as schema from './auth-schema';\n *\n * const auth = createAuth({ d1: env.DB, schema });\n * ```\n */\nexport function createAuth(opts: FoundryAuthOpts) {\n const cfg = resolveAuthConfig(opts);\n const db = drizzle(opts.d1 as Parameters<typeof drizzle>[0], { schema: opts.schema });\n\n return betterAuth({\n database: drizzleAdapter(db, { provider: 'sqlite', schema: opts.schema }),\n secret: cfg.secret,\n baseURL: cfg.baseURL,\n socialProviders: cfg.socialProviders,\n trustedOrigins: cfg.trustedOrigins,\n advanced: cfg.advanced,\n });\n}\n\nexport type FoundryAuth = ReturnType<typeof createAuth>;\n","/**\n * Foundry auth defaults — applied by createAuth() before the user-supplied opts.\n *\n * The actual better-auth instance is constructed in `index.ts` (server) and\n * `client.ts` (browser). This file isolates the defaults so they can be\n * unit-tested without pulling in the full better-auth dependency tree.\n */\n\ndeclare const process: { env?: Record<string, string | undefined> } | undefined;\n\nexport interface FoundryAuthOpts {\n /** D1 binding from the Cloudflare context, e.g. env.DB. */\n d1: unknown;\n /** Drizzle schema for auth tables (user / session / account / verification). */\n schema: Record<string, unknown>;\n /** Optional secret. Reads BETTER_AUTH_SECRET / AUTH_SECRET if omitted. */\n secret?: string;\n /** Public base URL of your auth-bearing app. Reads AUTH_URL if omitted. */\n baseURL?: string;\n /** Google OAuth credentials. Reads GOOGLE_CLIENT_ID / SECRET if omitted. */\n google?: { clientId?: string; clientSecret?: string };\n /** Trusted redirect origins. */\n trustedOrigins?: string[];\n /** Override session cookie name. Defaults to 'foundry.session'. */\n sessionCookieName?: string;\n /** Set to 'production' to force secure cookies. Reads NODE_ENV otherwise. */\n env?: 'development' | 'production' | 'test';\n}\n\nexport interface ResolvedAuthConfig {\n secret: string;\n baseURL: string;\n socialProviders: {\n google: { clientId: string; clientSecret: string };\n };\n trustedOrigins: string[];\n advanced: {\n cookies: {\n session_token: { name: string; attributes: { secure: boolean; sameSite: 'lax'; httpOnly: true } };\n };\n crossSubDomainCookies: { enabled: false };\n useSecureCookies: boolean;\n };\n}\n\nfunction readEnv(key: string): string | undefined {\n if (typeof process === 'undefined' || !process.env) return undefined;\n return process.env[key];\n}\n\n/**\n * Resolves the Foundry auth defaults. Pure function — call this from createAuth()\n * to get the config object, then pass it to betterAuth() with your `database`.\n */\nexport function resolveAuthConfig(opts: FoundryAuthOpts): ResolvedAuthConfig {\n const secret = opts.secret ?? readEnv('BETTER_AUTH_SECRET') ?? readEnv('AUTH_SECRET');\n if (!secret) {\n throw new Error(\n '[auth-preset] missing secret — set BETTER_AUTH_SECRET or pass `secret` to createAuth()',\n );\n }\n\n const baseURL =\n opts.baseURL ??\n readEnv('AUTH_URL') ??\n readEnv('NEXTAUTH_URL') ??\n readEnv('BETTER_AUTH_URL');\n if (!baseURL) {\n throw new Error(\n '[auth-preset] missing baseURL — set AUTH_URL or pass `baseURL` to createAuth()',\n );\n }\n\n const googleId =\n opts.google?.clientId ?? readEnv('GOOGLE_CLIENT_ID') ?? readEnv('AUTH_GOOGLE_ID') ?? '';\n const googleSecret =\n opts.google?.clientSecret ??\n readEnv('GOOGLE_CLIENT_SECRET') ??\n readEnv('AUTH_GOOGLE_SECRET') ??\n '';\n\n const env = opts.env ?? (readEnv('NODE_ENV') as FoundryAuthOpts['env']) ?? 'development';\n const isProd = env === 'production';\n\n return {\n secret,\n baseURL,\n socialProviders: {\n google: { clientId: googleId, clientSecret: googleSecret },\n },\n trustedOrigins: opts.trustedOrigins ?? [baseURL],\n advanced: {\n cookies: {\n session_token: {\n name: opts.sessionCookieName ?? 'foundry.session',\n attributes: { secure: isProd, sameSite: 'lax', httpOnly: true },\n },\n },\n crossSubDomainCookies: { enabled: false },\n useSecureCookies: isProd,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,yBAA2B;AAC3B,qBAA+B;AAC/B,gBAAwB;;;ACuCxB,SAAS,QAAQ,KAAiC;AAChD,MAAI,OAAO,YAAY,eAAe,CAAC,QAAQ;AAAK,WAAO;AAC3D,SAAO,QAAQ,IAAI,GAAG;AACxB;AAMO,SAAS,kBAAkB,MAA2C;AAC3E,QAAM,SAAS,KAAK,UAAU,QAAQ,oBAAoB,KAAK,QAAQ,aAAa;AACpF,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UACJ,KAAK,WACL,QAAQ,UAAU,KAClB,QAAQ,cAAc,KACtB,QAAQ,iBAAiB;AAC3B,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WACJ,KAAK,QAAQ,YAAY,QAAQ,kBAAkB,KAAK,QAAQ,gBAAgB,KAAK;AACvF,QAAM,eACJ,KAAK,QAAQ,gBACb,QAAQ,sBAAsB,KAC9B,QAAQ,oBAAoB,KAC5B;AAEF,QAAM,MAAM,KAAK,OAAQ,QAAQ,UAAU,KAAgC;AAC3E,QAAM,SAAS,QAAQ;AAEvB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,MACf,QAAQ,EAAE,UAAU,UAAU,cAAc,aAAa;AAAA,IAC3D;AAAA,IACA,gBAAgB,KAAK,kBAAkB,CAAC,OAAO;AAAA,IAC/C,UAAU;AAAA,MACR,SAAS;AAAA,QACP,eAAe;AAAA,UACb,MAAM,KAAK,qBAAqB;AAAA,UAChC,YAAY,EAAE,QAAQ,QAAQ,UAAU,OAAO,UAAU,KAAK;AAAA,QAChE;AAAA,MACF;AAAA,MACA,uBAAuB,EAAE,SAAS,MAAM;AAAA,MACxC,kBAAkB;AAAA,IACpB;AAAA,EACF;AACF;;;AD/EO,SAAS,WAAW,MAAuB;AAChD,QAAM,MAAM,kBAAkB,IAAI;AAClC,QAAM,SAAK,mBAAQ,KAAK,IAAqC,EAAE,QAAQ,KAAK,OAAO,CAAC;AAEpF,aAAO,+BAAW;AAAA,IAChB,cAAU,+BAAe,IAAI,EAAE,UAAU,UAAU,QAAQ,KAAK,OAAO,CAAC;AAAA,IACxE,QAAQ,IAAI;AAAA,IACZ,SAAS,IAAI;AAAA,IACb,iBAAiB,IAAI;AAAA,IACrB,gBAAgB,IAAI;AAAA,IACpB,UAAU,IAAI;AAAA,EAChB,CAAC;AACH;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,66 @@
1
+ // src/index.ts
2
+ import { betterAuth } from "better-auth";
3
+ import { drizzleAdapter } from "better-auth/adapters/drizzle";
4
+ import { drizzle } from "drizzle-orm/d1";
5
+
6
+ // src/config.ts
7
+ function readEnv(key) {
8
+ if (typeof process === "undefined" || !process.env)
9
+ return void 0;
10
+ return process.env[key];
11
+ }
12
+ function resolveAuthConfig(opts) {
13
+ const secret = opts.secret ?? readEnv("BETTER_AUTH_SECRET") ?? readEnv("AUTH_SECRET");
14
+ if (!secret) {
15
+ throw new Error(
16
+ "[auth-preset] missing secret \u2014 set BETTER_AUTH_SECRET or pass `secret` to createAuth()"
17
+ );
18
+ }
19
+ const baseURL = opts.baseURL ?? readEnv("AUTH_URL") ?? readEnv("NEXTAUTH_URL") ?? readEnv("BETTER_AUTH_URL");
20
+ if (!baseURL) {
21
+ throw new Error(
22
+ "[auth-preset] missing baseURL \u2014 set AUTH_URL or pass `baseURL` to createAuth()"
23
+ );
24
+ }
25
+ const googleId = opts.google?.clientId ?? readEnv("GOOGLE_CLIENT_ID") ?? readEnv("AUTH_GOOGLE_ID") ?? "";
26
+ const googleSecret = opts.google?.clientSecret ?? readEnv("GOOGLE_CLIENT_SECRET") ?? readEnv("AUTH_GOOGLE_SECRET") ?? "";
27
+ const env = opts.env ?? readEnv("NODE_ENV") ?? "development";
28
+ const isProd = env === "production";
29
+ return {
30
+ secret,
31
+ baseURL,
32
+ socialProviders: {
33
+ google: { clientId: googleId, clientSecret: googleSecret }
34
+ },
35
+ trustedOrigins: opts.trustedOrigins ?? [baseURL],
36
+ advanced: {
37
+ cookies: {
38
+ session_token: {
39
+ name: opts.sessionCookieName ?? "foundry.session",
40
+ attributes: { secure: isProd, sameSite: "lax", httpOnly: true }
41
+ }
42
+ },
43
+ crossSubDomainCookies: { enabled: false },
44
+ useSecureCookies: isProd
45
+ }
46
+ };
47
+ }
48
+
49
+ // src/index.ts
50
+ function createAuth(opts) {
51
+ const cfg = resolveAuthConfig(opts);
52
+ const db = drizzle(opts.d1, { schema: opts.schema });
53
+ return betterAuth({
54
+ database: drizzleAdapter(db, { provider: "sqlite", schema: opts.schema }),
55
+ secret: cfg.secret,
56
+ baseURL: cfg.baseURL,
57
+ socialProviders: cfg.socialProviders,
58
+ trustedOrigins: cfg.trustedOrigins,
59
+ advanced: cfg.advanced
60
+ });
61
+ }
62
+ export {
63
+ createAuth,
64
+ resolveAuthConfig
65
+ };
66
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/config.ts"],"sourcesContent":["/**\n * Server entrypoint — wires better-auth with Foundry defaults + D1 adapter.\n */\n\nimport { betterAuth } from 'better-auth';\nimport { drizzleAdapter } from 'better-auth/adapters/drizzle';\nimport { drizzle } from 'drizzle-orm/d1';\nimport { resolveAuthConfig, type FoundryAuthOpts } from './config.js';\n\nexport type { FoundryAuthOpts, ResolvedAuthConfig } from './config.js';\nexport { resolveAuthConfig } from './config.js';\n\n/**\n * Create a Foundry-standard better-auth instance.\n *\n * @example\n * ```ts\n * import { createAuth } from '@saas-maker/auth-preset';\n * import * as schema from './auth-schema';\n *\n * const auth = createAuth({ d1: env.DB, schema });\n * ```\n */\nexport function createAuth(opts: FoundryAuthOpts) {\n const cfg = resolveAuthConfig(opts);\n const db = drizzle(opts.d1 as Parameters<typeof drizzle>[0], { schema: opts.schema });\n\n return betterAuth({\n database: drizzleAdapter(db, { provider: 'sqlite', schema: opts.schema }),\n secret: cfg.secret,\n baseURL: cfg.baseURL,\n socialProviders: cfg.socialProviders,\n trustedOrigins: cfg.trustedOrigins,\n advanced: cfg.advanced,\n });\n}\n\nexport type FoundryAuth = ReturnType<typeof createAuth>;\n","/**\n * Foundry auth defaults — applied by createAuth() before the user-supplied opts.\n *\n * The actual better-auth instance is constructed in `index.ts` (server) and\n * `client.ts` (browser). This file isolates the defaults so they can be\n * unit-tested without pulling in the full better-auth dependency tree.\n */\n\ndeclare const process: { env?: Record<string, string | undefined> } | undefined;\n\nexport interface FoundryAuthOpts {\n /** D1 binding from the Cloudflare context, e.g. env.DB. */\n d1: unknown;\n /** Drizzle schema for auth tables (user / session / account / verification). */\n schema: Record<string, unknown>;\n /** Optional secret. Reads BETTER_AUTH_SECRET / AUTH_SECRET if omitted. */\n secret?: string;\n /** Public base URL of your auth-bearing app. Reads AUTH_URL if omitted. */\n baseURL?: string;\n /** Google OAuth credentials. Reads GOOGLE_CLIENT_ID / SECRET if omitted. */\n google?: { clientId?: string; clientSecret?: string };\n /** Trusted redirect origins. */\n trustedOrigins?: string[];\n /** Override session cookie name. Defaults to 'foundry.session'. */\n sessionCookieName?: string;\n /** Set to 'production' to force secure cookies. Reads NODE_ENV otherwise. */\n env?: 'development' | 'production' | 'test';\n}\n\nexport interface ResolvedAuthConfig {\n secret: string;\n baseURL: string;\n socialProviders: {\n google: { clientId: string; clientSecret: string };\n };\n trustedOrigins: string[];\n advanced: {\n cookies: {\n session_token: { name: string; attributes: { secure: boolean; sameSite: 'lax'; httpOnly: true } };\n };\n crossSubDomainCookies: { enabled: false };\n useSecureCookies: boolean;\n };\n}\n\nfunction readEnv(key: string): string | undefined {\n if (typeof process === 'undefined' || !process.env) return undefined;\n return process.env[key];\n}\n\n/**\n * Resolves the Foundry auth defaults. Pure function — call this from createAuth()\n * to get the config object, then pass it to betterAuth() with your `database`.\n */\nexport function resolveAuthConfig(opts: FoundryAuthOpts): ResolvedAuthConfig {\n const secret = opts.secret ?? readEnv('BETTER_AUTH_SECRET') ?? readEnv('AUTH_SECRET');\n if (!secret) {\n throw new Error(\n '[auth-preset] missing secret — set BETTER_AUTH_SECRET or pass `secret` to createAuth()',\n );\n }\n\n const baseURL =\n opts.baseURL ??\n readEnv('AUTH_URL') ??\n readEnv('NEXTAUTH_URL') ??\n readEnv('BETTER_AUTH_URL');\n if (!baseURL) {\n throw new Error(\n '[auth-preset] missing baseURL — set AUTH_URL or pass `baseURL` to createAuth()',\n );\n }\n\n const googleId =\n opts.google?.clientId ?? readEnv('GOOGLE_CLIENT_ID') ?? readEnv('AUTH_GOOGLE_ID') ?? '';\n const googleSecret =\n opts.google?.clientSecret ??\n readEnv('GOOGLE_CLIENT_SECRET') ??\n readEnv('AUTH_GOOGLE_SECRET') ??\n '';\n\n const env = opts.env ?? (readEnv('NODE_ENV') as FoundryAuthOpts['env']) ?? 'development';\n const isProd = env === 'production';\n\n return {\n secret,\n baseURL,\n socialProviders: {\n google: { clientId: googleId, clientSecret: googleSecret },\n },\n trustedOrigins: opts.trustedOrigins ?? [baseURL],\n advanced: {\n cookies: {\n session_token: {\n name: opts.sessionCookieName ?? 'foundry.session',\n attributes: { secure: isProd, sameSite: 'lax', httpOnly: true },\n },\n },\n crossSubDomainCookies: { enabled: false },\n useSecureCookies: isProd,\n },\n };\n}\n"],"mappings":";AAIA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,eAAe;;;ACuCxB,SAAS,QAAQ,KAAiC;AAChD,MAAI,OAAO,YAAY,eAAe,CAAC,QAAQ;AAAK,WAAO;AAC3D,SAAO,QAAQ,IAAI,GAAG;AACxB;AAMO,SAAS,kBAAkB,MAA2C;AAC3E,QAAM,SAAS,KAAK,UAAU,QAAQ,oBAAoB,KAAK,QAAQ,aAAa;AACpF,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UACJ,KAAK,WACL,QAAQ,UAAU,KAClB,QAAQ,cAAc,KACtB,QAAQ,iBAAiB;AAC3B,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,WACJ,KAAK,QAAQ,YAAY,QAAQ,kBAAkB,KAAK,QAAQ,gBAAgB,KAAK;AACvF,QAAM,eACJ,KAAK,QAAQ,gBACb,QAAQ,sBAAsB,KAC9B,QAAQ,oBAAoB,KAC5B;AAEF,QAAM,MAAM,KAAK,OAAQ,QAAQ,UAAU,KAAgC;AAC3E,QAAM,SAAS,QAAQ;AAEvB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,MACf,QAAQ,EAAE,UAAU,UAAU,cAAc,aAAa;AAAA,IAC3D;AAAA,IACA,gBAAgB,KAAK,kBAAkB,CAAC,OAAO;AAAA,IAC/C,UAAU;AAAA,MACR,SAAS;AAAA,QACP,eAAe;AAAA,UACb,MAAM,KAAK,qBAAqB;AAAA,UAChC,YAAY,EAAE,QAAQ,QAAQ,UAAU,OAAO,UAAU,KAAK;AAAA,QAChE;AAAA,MACF;AAAA,MACA,uBAAuB,EAAE,SAAS,MAAM;AAAA,MACxC,kBAAkB;AAAA,IACpB;AAAA,EACF;AACF;;;AD/EO,SAAS,WAAW,MAAuB;AAChD,QAAM,MAAM,kBAAkB,IAAI;AAClC,QAAM,KAAK,QAAQ,KAAK,IAAqC,EAAE,QAAQ,KAAK,OAAO,CAAC;AAEpF,SAAO,WAAW;AAAA,IAChB,UAAU,eAAe,IAAI,EAAE,UAAU,UAAU,QAAQ,KAAK,OAAO,CAAC;AAAA,IACxE,QAAQ,IAAI;AAAA,IACZ,SAAS,IAAI;AAAA,IACb,iBAAiB,IAAI;AAAA,IACrB,gBAAgB,IAAI;AAAA,IACpB,UAAU,IAAI;AAAA,EAChB,CAAC;AACH;","names":[]}
@@ -0,0 +1,25 @@
1
+ import { FoundryAuth } from './index.mjs';
2
+ import 'better-auth';
3
+
4
+ /**
5
+ * Next.js App Router route handler glue.
6
+ *
7
+ * Usage:
8
+ * ```ts
9
+ * // app/api/auth/[...all]/route.ts
10
+ * import { createAuth } from '@saas-maker/auth-preset';
11
+ * import { toNextHandler } from '@saas-maker/auth-preset/next';
12
+ * import * as schema from '@/lib/auth-schema';
13
+ *
14
+ * const auth = createAuth({ d1: env.DB, schema });
15
+ * export const { GET, POST } = toNextHandler(auth);
16
+ * ```
17
+ */
18
+
19
+ type WebHandler = (req: Request) => Promise<Response> | Response;
20
+ declare function toNextHandler(auth: FoundryAuth): {
21
+ GET: WebHandler;
22
+ POST: WebHandler;
23
+ };
24
+
25
+ export { toNextHandler };
package/dist/next.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { FoundryAuth } from './index.js';
2
+ import 'better-auth';
3
+
4
+ /**
5
+ * Next.js App Router route handler glue.
6
+ *
7
+ * Usage:
8
+ * ```ts
9
+ * // app/api/auth/[...all]/route.ts
10
+ * import { createAuth } from '@saas-maker/auth-preset';
11
+ * import { toNextHandler } from '@saas-maker/auth-preset/next';
12
+ * import * as schema from '@/lib/auth-schema';
13
+ *
14
+ * const auth = createAuth({ d1: env.DB, schema });
15
+ * export const { GET, POST } = toNextHandler(auth);
16
+ * ```
17
+ */
18
+
19
+ type WebHandler = (req: Request) => Promise<Response> | Response;
20
+ declare function toNextHandler(auth: FoundryAuth): {
21
+ GET: WebHandler;
22
+ POST: WebHandler;
23
+ };
24
+
25
+ export { toNextHandler };
package/dist/next.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/next.ts
21
+ var next_exports = {};
22
+ __export(next_exports, {
23
+ toNextHandler: () => toNextHandler
24
+ });
25
+ module.exports = __toCommonJS(next_exports);
26
+ function toNextHandler(auth) {
27
+ const handler = (req) => auth.handler(req);
28
+ return { GET: handler, POST: handler };
29
+ }
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ toNextHandler
33
+ });
34
+ //# sourceMappingURL=next.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/next.ts"],"sourcesContent":["/**\n * Next.js App Router route handler glue.\n *\n * Usage:\n * ```ts\n * // app/api/auth/[...all]/route.ts\n * import { createAuth } from '@saas-maker/auth-preset';\n * import { toNextHandler } from '@saas-maker/auth-preset/next';\n * import * as schema from '@/lib/auth-schema';\n *\n * const auth = createAuth({ d1: env.DB, schema });\n * export const { GET, POST } = toNextHandler(auth);\n * ```\n */\n\nimport type { FoundryAuth } from './index.js';\n\ntype WebHandler = (req: Request) => Promise<Response> | Response;\n\nexport function toNextHandler(auth: FoundryAuth): { GET: WebHandler; POST: WebHandler } {\n // better-auth exposes a `handler` Web-fetch-style function.\n const handler: WebHandler = (req: Request) => auth.handler(req);\n return { GET: handler, POST: handler };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBO,SAAS,cAAc,MAA0D;AAEtF,QAAM,UAAsB,CAAC,QAAiB,KAAK,QAAQ,GAAG;AAC9D,SAAO,EAAE,KAAK,SAAS,MAAM,QAAQ;AACvC;","names":[]}
package/dist/next.mjs ADDED
@@ -0,0 +1,9 @@
1
+ // src/next.ts
2
+ function toNextHandler(auth) {
3
+ const handler = (req) => auth.handler(req);
4
+ return { GET: handler, POST: handler };
5
+ }
6
+ export {
7
+ toNextHandler
8
+ };
9
+ //# sourceMappingURL=next.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/next.ts"],"sourcesContent":["/**\n * Next.js App Router route handler glue.\n *\n * Usage:\n * ```ts\n * // app/api/auth/[...all]/route.ts\n * import { createAuth } from '@saas-maker/auth-preset';\n * import { toNextHandler } from '@saas-maker/auth-preset/next';\n * import * as schema from '@/lib/auth-schema';\n *\n * const auth = createAuth({ d1: env.DB, schema });\n * export const { GET, POST } = toNextHandler(auth);\n * ```\n */\n\nimport type { FoundryAuth } from './index.js';\n\ntype WebHandler = (req: Request) => Promise<Response> | Response;\n\nexport function toNextHandler(auth: FoundryAuth): { GET: WebHandler; POST: WebHandler } {\n // better-auth exposes a `handler` Web-fetch-style function.\n const handler: WebHandler = (req: Request) => auth.handler(req);\n return { GET: handler, POST: handler };\n}\n"],"mappings":";AAmBO,SAAS,cAAc,MAA0D;AAEtF,QAAM,UAAsB,CAAC,QAAiB,KAAK,QAAQ,GAAG;AAC9D,SAAO,EAAE,KAAK,SAAS,MAAM,QAAQ;AACvC;","names":[]}