@kuckit/auth 2.0.0 → 2.0.1
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/config-BViah4xX.d.ts +42 -0
- package/dist/config-BViah4xX.d.ts.map +1 -0
- package/dist/config-BZZEHPCg.js +24 -0
- package/dist/config-BZZEHPCg.js.map +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +3 -0
- package/dist/index.d.ts +43 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +37 -15
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/config.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Pure config exports for @kuckit/auth
|
|
4
|
+
*
|
|
5
|
+
* This entrypoint is GUARANTEED to be side-effect-free:
|
|
6
|
+
* - No better-auth instantiation
|
|
7
|
+
* - No database connections
|
|
8
|
+
* - No process.env reads at module scope
|
|
9
|
+
*
|
|
10
|
+
* Safe for CLI tools, build scripts, and config files.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Auth configuration options
|
|
14
|
+
*/
|
|
15
|
+
interface AuthConfig {
|
|
16
|
+
/** List of trusted origins for CORS */
|
|
17
|
+
trustedOrigins?: string[];
|
|
18
|
+
/** Base URL for auth endpoints (e.g., http://localhost:3000) */
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
/** Cookie name prefix (default: better-auth) */
|
|
21
|
+
cookiePrefix?: string;
|
|
22
|
+
/** Session max age in seconds (default: 7 days) */
|
|
23
|
+
sessionMaxAge?: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Define auth configuration with type safety
|
|
27
|
+
*/
|
|
28
|
+
declare function defineAuthConfig(config: AuthConfig): AuthConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Get cookie attributes for auth cookies
|
|
31
|
+
*
|
|
32
|
+
* @param secure - Whether to use secure cookies (true in production)
|
|
33
|
+
*/
|
|
34
|
+
declare function getCookieAttributes(secure: boolean): {
|
|
35
|
+
secure: boolean;
|
|
36
|
+
sameSite: "lax";
|
|
37
|
+
path: string;
|
|
38
|
+
httpOnly: boolean;
|
|
39
|
+
};
|
|
40
|
+
//#endregion
|
|
41
|
+
export { defineAuthConfig as n, getCookieAttributes as r, AuthConfig as t };
|
|
42
|
+
//# sourceMappingURL=config-BViah4xX.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-BViah4xX.d.ts","names":[],"sources":["../src/config.ts"],"sourcesContent":[],"mappings":";;AAcA;AAcA;AASA;;;;;;;;;;UAvBiB,UAAA;;;;;;;;;;;;;iBAcD,gBAAA,SAAyB,aAAa;;;;;;iBAStC,mBAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/config.ts
|
|
2
|
+
/**
|
|
3
|
+
* Define auth configuration with type safety
|
|
4
|
+
*/
|
|
5
|
+
function defineAuthConfig(config) {
|
|
6
|
+
return config;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Get cookie attributes for auth cookies
|
|
10
|
+
*
|
|
11
|
+
* @param secure - Whether to use secure cookies (true in production)
|
|
12
|
+
*/
|
|
13
|
+
function getCookieAttributes(secure) {
|
|
14
|
+
return {
|
|
15
|
+
secure,
|
|
16
|
+
sameSite: "lax",
|
|
17
|
+
path: "/",
|
|
18
|
+
httpOnly: true
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { getCookieAttributes as n, defineAuthConfig as t };
|
|
24
|
+
//# sourceMappingURL=config-BZZEHPCg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-BZZEHPCg.js","names":[],"sources":["../src/config.ts"],"sourcesContent":["/**\n * Pure config exports for @kuckit/auth\n *\n * This entrypoint is GUARANTEED to be side-effect-free:\n * - No better-auth instantiation\n * - No database connections\n * - No process.env reads at module scope\n *\n * Safe for CLI tools, build scripts, and config files.\n */\n\n/**\n * Auth configuration options\n */\nexport interface AuthConfig {\n\t/** List of trusted origins for CORS */\n\ttrustedOrigins?: string[]\n\t/** Base URL for auth endpoints (e.g., http://localhost:3000) */\n\tbaseUrl?: string\n\t/** Cookie name prefix (default: better-auth) */\n\tcookiePrefix?: string\n\t/** Session max age in seconds (default: 7 days) */\n\tsessionMaxAge?: number\n}\n\n/**\n * Define auth configuration with type safety\n */\nexport function defineAuthConfig(config: AuthConfig): AuthConfig {\n\treturn config\n}\n\n/**\n * Get cookie attributes for auth cookies\n *\n * @param secure - Whether to use secure cookies (true in production)\n */\nexport function getCookieAttributes(secure: boolean) {\n\treturn {\n\t\tsecure,\n\t\tsameSite: 'lax' as const,\n\t\tpath: '/',\n\t\thttpOnly: true,\n\t}\n}\n"],"mappings":";;;;AA4BA,SAAgB,iBAAiB,QAAgC;AAChE,QAAO;;;;;;;AAQR,SAAgB,oBAAoB,QAAiB;AACpD,QAAO;EACN;EACA,UAAU;EACV,MAAM;EACN,UAAU;EACV"}
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,47 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { n as defineAuthConfig, r as getCookieAttributes, t as AuthConfig } from "./config-BViah4xX.js";
|
|
2
|
+
import { betterAuth } from "better-auth";
|
|
3
|
+
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
3
4
|
|
|
4
5
|
//#region src/index.d.ts
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Auth instance type (inferred from betterAuth)
|
|
9
|
+
*/
|
|
10
|
+
type Auth = ReturnType<typeof betterAuth>;
|
|
11
|
+
/**
|
|
12
|
+
* Database type accepted by createAuth
|
|
13
|
+
* This matches the Drizzle database type from @kuckit/db
|
|
14
|
+
*/
|
|
15
|
+
type AuthDbClient = Parameters<typeof drizzleAdapter>[0];
|
|
16
|
+
interface CreateAuthOptions {
|
|
17
|
+
/** Drizzle database instance */
|
|
18
|
+
db: AuthDbClient;
|
|
19
|
+
/** Auth configuration */
|
|
20
|
+
config?: AuthConfig;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a Better-Auth instance
|
|
24
|
+
*
|
|
25
|
+
* This is a factory function that creates the auth instance at runtime,
|
|
26
|
+
* avoiding module-level side effects.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Database and configuration options
|
|
29
|
+
* @returns Better-Auth instance
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const auth = createAuth({
|
|
34
|
+
* db,
|
|
35
|
+
* config: {
|
|
36
|
+
* trustedOrigins: ['http://localhost:5173'],
|
|
37
|
+
* },
|
|
38
|
+
* })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function createAuth({
|
|
42
|
+
db,
|
|
43
|
+
config
|
|
44
|
+
}: CreateAuthOptions): Auth;
|
|
6
45
|
//#endregion
|
|
7
|
-
export {
|
|
46
|
+
export { Auth, type AuthConfig, AuthDbClient, CreateAuthOptions, createAuth, defineAuthConfig, getCookieAttributes };
|
|
8
47
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAQA;AAMY,KANA,IAAA,GAAO,UAMK,CAAqB,OANR,UAMV,CAAA;AAE3B;AA0BA;;;AAAgD,KA5BpC,YAAA,GAAe,UA4BqB,CAAA,OA5BH,cA4BG,CAAA,CAAA,CAAA,CAAA;AAAoB,UA1BnD,iBAAA,CA0BmD;EAAI;MAxBnE;;WAEK;;;;;;;;;;;;;;;;;;;;;iBAsBM,UAAA;;;GAAgC,oBAAoB"}
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,45 @@
|
|
|
1
|
+
import { n as getCookieAttributes, t as defineAuthConfig } from "./config-BZZEHPCg.js";
|
|
1
2
|
import { betterAuth } from "better-auth";
|
|
2
3
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
3
|
-
import { db } from "@kuckit/db";
|
|
4
4
|
import * as schema from "@kuckit/db/schema/auth";
|
|
5
5
|
|
|
6
6
|
//#region src/index.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Create a Better-Auth instance
|
|
9
|
+
*
|
|
10
|
+
* This is a factory function that creates the auth instance at runtime,
|
|
11
|
+
* avoiding module-level side effects.
|
|
12
|
+
*
|
|
13
|
+
* @param options - Database and configuration options
|
|
14
|
+
* @returns Better-Auth instance
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const auth = createAuth({
|
|
19
|
+
* db,
|
|
20
|
+
* config: {
|
|
21
|
+
* trustedOrigins: ['http://localhost:5173'],
|
|
22
|
+
* },
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function createAuth({ db, config = {} }) {
|
|
27
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
28
|
+
return betterAuth({
|
|
29
|
+
database: drizzleAdapter(db, {
|
|
30
|
+
provider: "pg",
|
|
31
|
+
schema
|
|
32
|
+
}),
|
|
33
|
+
trustedOrigins: config.trustedOrigins ?? [process.env.CORS_ORIGIN || ""],
|
|
34
|
+
emailAndPassword: { enabled: true },
|
|
35
|
+
advanced: { defaultCookieAttributes: {
|
|
36
|
+
sameSite: isProduction ? "none" : "lax",
|
|
37
|
+
secure: isProduction,
|
|
38
|
+
httpOnly: true
|
|
39
|
+
} }
|
|
40
|
+
});
|
|
41
|
+
}
|
|
20
42
|
|
|
21
43
|
//#endregion
|
|
22
|
-
export {
|
|
44
|
+
export { createAuth, defineAuthConfig, getCookieAttributes };
|
|
23
45
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { betterAuth, type BetterAuthOptions } from 'better-auth'\nimport { drizzleAdapter } from 'better-auth/adapters/drizzle'\nimport
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { betterAuth, type BetterAuthOptions } from 'better-auth'\nimport { drizzleAdapter } from 'better-auth/adapters/drizzle'\nimport * as schema from '@kuckit/db/schema/auth'\nimport type { AuthConfig } from './config'\n\n/**\n * Auth instance type (inferred from betterAuth)\n */\nexport type Auth = ReturnType<typeof betterAuth>\n\n/**\n * Database type accepted by createAuth\n * This matches the Drizzle database type from @kuckit/db\n */\nexport type AuthDbClient = Parameters<typeof drizzleAdapter>[0]\n\nexport interface CreateAuthOptions {\n\t/** Drizzle database instance */\n\tdb: AuthDbClient\n\t/** Auth configuration */\n\tconfig?: AuthConfig\n}\n\n/**\n * Create a Better-Auth instance\n *\n * This is a factory function that creates the auth instance at runtime,\n * avoiding module-level side effects.\n *\n * @param options - Database and configuration options\n * @returns Better-Auth instance\n *\n * @example\n * ```ts\n * const auth = createAuth({\n * db,\n * config: {\n * trustedOrigins: ['http://localhost:5173'],\n * },\n * })\n * ```\n */\nexport function createAuth({ db, config = {} }: CreateAuthOptions): Auth {\n\tconst isProduction = process.env.NODE_ENV === 'production'\n\n\treturn betterAuth<BetterAuthOptions>({\n\t\tdatabase: drizzleAdapter(db, {\n\t\t\tprovider: 'pg',\n\t\t\tschema: schema,\n\t\t}),\n\t\ttrustedOrigins: config.trustedOrigins ?? [process.env.CORS_ORIGIN || ''],\n\t\temailAndPassword: {\n\t\t\tenabled: true,\n\t\t},\n\t\tadvanced: {\n\t\t\tdefaultCookieAttributes: {\n\t\t\t\tsameSite: isProduction ? 'none' : 'lax',\n\t\t\t\tsecure: isProduction,\n\t\t\t\thttpOnly: true,\n\t\t\t},\n\t\t},\n\t})\n}\n\n// Re-export config types\nexport type { AuthConfig } from './config'\nexport { defineAuthConfig, getCookieAttributes } from './config'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,SAAgB,WAAW,EAAE,IAAI,SAAS,EAAE,IAA6B;CACxE,MAAM,eAAe,QAAQ,IAAI,aAAa;AAE9C,QAAO,WAA8B;EACpC,UAAU,eAAe,IAAI;GAC5B,UAAU;GACF;GACR,CAAC;EACF,gBAAgB,OAAO,kBAAkB,CAAC,QAAQ,IAAI,eAAe,GAAG;EACxE,kBAAkB,EACjB,SAAS,MACT;EACD,UAAU,EACT,yBAAyB;GACxB,UAAU,eAAe,SAAS;GAClC,QAAQ;GACR,UAAU;GACV,EACD;EACD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kuckit/auth",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"default": "./dist/index.js"
|
|
14
14
|
},
|
|
15
|
+
"./config": {
|
|
16
|
+
"types": "./dist/config.d.ts",
|
|
17
|
+
"default": "./dist/config.js"
|
|
18
|
+
},
|
|
15
19
|
"./*": {
|
|
16
20
|
"types": "./dist/*.d.ts",
|
|
17
21
|
"default": "./dist/*.js"
|
|
@@ -31,6 +35,6 @@
|
|
|
31
35
|
"better-auth": "^1.3.28",
|
|
32
36
|
"dotenv": "^17.2.2",
|
|
33
37
|
"zod": "^4.1.11",
|
|
34
|
-
"@kuckit/db": "^2.0.
|
|
38
|
+
"@kuckit/db": "^2.0.1"
|
|
35
39
|
}
|
|
36
40
|
}
|