@clivly/auth-better-auth 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/LICENSE +21 -0
- package/README.md +20 -0
- package/dist/index.cjs +28 -0
- package/dist/index.d.cts +33 -0
- package/dist/index.d.mts +33 -0
- package/dist/index.mjs +26 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Clivly
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @clivly/auth-better-auth
|
|
2
|
+
|
|
3
|
+
[better-auth](https://better-auth.com) implementation of Clivly's `ClivlyAuthAdapter`. Resolves a CRM end-user's identity from the host app's better-auth session via `auth.api.getSession`.
|
|
4
|
+
|
|
5
|
+
Zero runtime dependencies — you pass your own `betterAuth({...})` instance, so there's no `better-auth` version to keep in lockstep.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createBetterAuthAdapter } from "@clivly/auth-better-auth";
|
|
9
|
+
import { auth } from "./auth"; // your betterAuth({ ... }) instance
|
|
10
|
+
|
|
11
|
+
const authAdapter = createBetterAuthAdapter({ auth });
|
|
12
|
+
|
|
13
|
+
const user = await authAdapter.getUser(request); // { id, email, name } | null
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Returns `null` when there's no session or the session user has no email (Clivly requires one). The adapter answers "who is this person?" only — CRM authorization lives in Clivly's separate `crm_members` layer.
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/map.ts
|
|
3
|
+
function betterAuthUserToClivlyUser(user) {
|
|
4
|
+
if (!user.email) return null;
|
|
5
|
+
return {
|
|
6
|
+
id: user.id,
|
|
7
|
+
email: user.email,
|
|
8
|
+
name: user.name ?? void 0
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/index.ts
|
|
13
|
+
/**
|
|
14
|
+
* better-auth → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the
|
|
15
|
+
* host app's better-auth session on each request, via `auth.api.getSession`.
|
|
16
|
+
* Answers "who is this person?" only — CRM authorization lives in the separate
|
|
17
|
+
* `crm_members` layer.
|
|
18
|
+
*/
|
|
19
|
+
function createBetterAuthAdapter(options) {
|
|
20
|
+
return { async getUser(req) {
|
|
21
|
+
const session = await options.auth.api.getSession({ headers: req.headers });
|
|
22
|
+
if (!session?.user) return null;
|
|
23
|
+
return betterAuthUserToClivlyUser(session.user);
|
|
24
|
+
} };
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
exports.betterAuthUserToClivlyUser = betterAuthUserToClivlyUser;
|
|
28
|
+
exports.createBetterAuthAdapter = createBetterAuthAdapter;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ClivlyAuthAdapter, ClivlyUser } from "@clivly/core";
|
|
2
|
+
|
|
3
|
+
//#region src/map.d.ts
|
|
4
|
+
interface BetterAuthLikeUser {
|
|
5
|
+
email?: string | null;
|
|
6
|
+
id: string;
|
|
7
|
+
name?: string | null;
|
|
8
|
+
}
|
|
9
|
+
declare function betterAuthUserToClivlyUser(user: BetterAuthLikeUser): ClivlyUser | null;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/index.d.ts
|
|
12
|
+
interface BetterAuthLike {
|
|
13
|
+
api: {
|
|
14
|
+
getSession(args: {
|
|
15
|
+
headers: Headers;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
user: BetterAuthLikeUser;
|
|
18
|
+
} | null>;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface BetterAuthAdapterOptions {
|
|
22
|
+
/** Your better-auth instance (the object returned by `betterAuth({...})`). */
|
|
23
|
+
auth: BetterAuthLike;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* better-auth → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the
|
|
27
|
+
* host app's better-auth session on each request, via `auth.api.getSession`.
|
|
28
|
+
* Answers "who is this person?" only — CRM authorization lives in the separate
|
|
29
|
+
* `crm_members` layer.
|
|
30
|
+
*/
|
|
31
|
+
declare function createBetterAuthAdapter(options: BetterAuthAdapterOptions): ClivlyAuthAdapter;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { BetterAuthAdapterOptions, BetterAuthLike, type BetterAuthLikeUser, betterAuthUserToClivlyUser, createBetterAuthAdapter };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ClivlyAuthAdapter, ClivlyUser } from "@clivly/core";
|
|
2
|
+
|
|
3
|
+
//#region src/map.d.ts
|
|
4
|
+
interface BetterAuthLikeUser {
|
|
5
|
+
email?: string | null;
|
|
6
|
+
id: string;
|
|
7
|
+
name?: string | null;
|
|
8
|
+
}
|
|
9
|
+
declare function betterAuthUserToClivlyUser(user: BetterAuthLikeUser): ClivlyUser | null;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/index.d.ts
|
|
12
|
+
interface BetterAuthLike {
|
|
13
|
+
api: {
|
|
14
|
+
getSession(args: {
|
|
15
|
+
headers: Headers;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
user: BetterAuthLikeUser;
|
|
18
|
+
} | null>;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface BetterAuthAdapterOptions {
|
|
22
|
+
/** Your better-auth instance (the object returned by `betterAuth({...})`). */
|
|
23
|
+
auth: BetterAuthLike;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* better-auth → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the
|
|
27
|
+
* host app's better-auth session on each request, via `auth.api.getSession`.
|
|
28
|
+
* Answers "who is this person?" only — CRM authorization lives in the separate
|
|
29
|
+
* `crm_members` layer.
|
|
30
|
+
*/
|
|
31
|
+
declare function createBetterAuthAdapter(options: BetterAuthAdapterOptions): ClivlyAuthAdapter;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { BetterAuthAdapterOptions, BetterAuthLike, type BetterAuthLikeUser, betterAuthUserToClivlyUser, createBetterAuthAdapter };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/map.ts
|
|
2
|
+
function betterAuthUserToClivlyUser(user) {
|
|
3
|
+
if (!user.email) return null;
|
|
4
|
+
return {
|
|
5
|
+
id: user.id,
|
|
6
|
+
email: user.email,
|
|
7
|
+
name: user.name ?? void 0
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/index.ts
|
|
12
|
+
/**
|
|
13
|
+
* better-auth → ClivlyAuthAdapter. Resolves the CRM end-user's identity from the
|
|
14
|
+
* host app's better-auth session on each request, via `auth.api.getSession`.
|
|
15
|
+
* Answers "who is this person?" only — CRM authorization lives in the separate
|
|
16
|
+
* `crm_members` layer.
|
|
17
|
+
*/
|
|
18
|
+
function createBetterAuthAdapter(options) {
|
|
19
|
+
return { async getUser(req) {
|
|
20
|
+
const session = await options.auth.api.getSession({ headers: req.headers });
|
|
21
|
+
if (!session?.user) return null;
|
|
22
|
+
return betterAuthUserToClivlyUser(session.user);
|
|
23
|
+
} };
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { betterAuthUserToClivlyUser, createBetterAuthAdapter };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clivly/auth-better-auth",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "better-auth implementation of Clivly's ClivlyAuthAdapter.",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@clivly/core": "0.1.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"tsdown": "^0.21.9",
|
|
32
|
+
"typescript": "^6",
|
|
33
|
+
"vitest": "^3.2.4"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"check-types": "tsc --noEmit",
|
|
38
|
+
"test": "vitest run"
|
|
39
|
+
},
|
|
40
|
+
"main": "./dist/index.cjs",
|
|
41
|
+
"types": "./dist/index.d.cts",
|
|
42
|
+
"module": "./dist/index.mjs"
|
|
43
|
+
}
|