@xframework/better-auth 0.4.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/.turbo/turbo-build.log +28 -0
- package/CHANGELOG.md +12 -0
- package/dist/client.cjs +41 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +12 -0
- package/dist/client.d.ts +12 -0
- package/dist/client.js +16 -0
- package/dist/client.js.map +1 -0
- package/dist/server.cjs +41 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +12 -0
- package/dist/server.d.ts +12 -0
- package/dist/server.js +16 -0
- package/dist/server.js.map +1 -0
- package/package.json +35 -0
- package/src/__tests__/index.test.ts +211 -0
- package/src/client.ts +16 -0
- package/src/server.ts +16 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +3 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
> @xframework/better-auth@0.4.0 build /home/runner/work/x/x/packages/@xframework/better-auth
|
3
|
+
> tsup
|
4
|
+
|
5
|
+
[34mCLI[39m Building entry: src/client.ts, src/server.ts
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
7
|
+
[34mCLI[39m tsup v8.3.5
|
8
|
+
[34mCLI[39m Using tsup config: /home/runner/work/x/x/packages/@xframework/better-auth/tsup.config.ts
|
9
|
+
[34mCLI[39m Target: esnext
|
10
|
+
[34mCLI[39m Cleaning output folder
|
11
|
+
[34mCJS[39m Build start
|
12
|
+
[34mESM[39m Build start
|
13
|
+
[32mCJS[39m [1mdist/client.cjs [22m[32m1.37 KB[39m
|
14
|
+
[32mCJS[39m [1mdist/server.cjs [22m[32m1.34 KB[39m
|
15
|
+
[32mCJS[39m [1mdist/client.cjs.map [22m[32m807.00 B[39m
|
16
|
+
[32mCJS[39m [1mdist/server.cjs.map [22m[32m751.00 B[39m
|
17
|
+
[32mCJS[39m ⚡️ Build success in 44ms
|
18
|
+
[32mESM[39m [1mdist/client.js [22m[32m345.00 B[39m
|
19
|
+
[32mESM[39m [1mdist/server.js [22m[32m315.00 B[39m
|
20
|
+
[32mESM[39m [1mdist/client.js.map [22m[32m767.00 B[39m
|
21
|
+
[32mESM[39m [1mdist/server.js.map [22m[32m711.00 B[39m
|
22
|
+
[32mESM[39m ⚡️ Build success in 44ms
|
23
|
+
[34mDTS[39m Build start
|
24
|
+
[32mDTS[39m ⚡️ Build success in 8181ms
|
25
|
+
[32mDTS[39m [1mdist/client.d.cts [22m[32m464.00 B[39m
|
26
|
+
[32mDTS[39m [1mdist/server.d.cts [22m[32m427.00 B[39m
|
27
|
+
[32mDTS[39m [1mdist/client.d.ts [22m[32m464.00 B[39m
|
28
|
+
[32mDTS[39m [1mdist/server.d.ts [22m[32m427.00 B[39m
|
package/CHANGELOG.md
ADDED
package/dist/client.cjs
ADDED
@@ -0,0 +1,41 @@
|
|
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
|
+
BetterAuthClientAdapter: () => BetterAuthClientAdapter
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(client_exports);
|
26
|
+
var import_adapter = require("@xframework/x/adapter");
|
27
|
+
var BetterAuthClientAdapter = class extends import_adapter.SyncAdapter {
|
28
|
+
authClient;
|
29
|
+
constructor({ authClient }) {
|
30
|
+
super();
|
31
|
+
this.authClient = authClient;
|
32
|
+
}
|
33
|
+
export() {
|
34
|
+
return this.authClient;
|
35
|
+
}
|
36
|
+
};
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
38
|
+
0 && (module.exports = {
|
39
|
+
BetterAuthClientAdapter
|
40
|
+
});
|
41
|
+
//# sourceMappingURL=client.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { SyncAdapter } from \"@xframework/x/adapter\";\nimport type { createAuthClient } from \"better-auth/client\";\n\nexport class BetterAuthClientAdapter<\n UserBetterAuthInstance extends ReturnType<typeof createAuthClient>,\n> extends SyncAdapter<UserBetterAuthInstance> {\n public authClient: UserBetterAuthInstance;\n constructor({ authClient }: { authClient: UserBetterAuthInstance }) {\n super();\n this.authClient = authClient;\n }\n\n export() {\n return this.authClient;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA4B;AAGrB,IAAM,0BAAN,cAEG,2BAAoC;AAAA,EACrC;AAAA,EACP,YAAY,EAAE,WAAW,GAA2C;AAClE,UAAM;AACN,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,SAAS;AACP,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { SyncAdapter } from '@xframework/x/adapter';
|
2
|
+
import { createAuthClient } from 'better-auth/client';
|
3
|
+
|
4
|
+
declare class BetterAuthClientAdapter<UserBetterAuthInstance extends ReturnType<typeof createAuthClient>> extends SyncAdapter<UserBetterAuthInstance> {
|
5
|
+
authClient: UserBetterAuthInstance;
|
6
|
+
constructor({ authClient }: {
|
7
|
+
authClient: UserBetterAuthInstance;
|
8
|
+
});
|
9
|
+
export(): UserBetterAuthInstance;
|
10
|
+
}
|
11
|
+
|
12
|
+
export { BetterAuthClientAdapter };
|
package/dist/client.d.ts
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
import { SyncAdapter } from '@xframework/x/adapter';
|
2
|
+
import { createAuthClient } from 'better-auth/client';
|
3
|
+
|
4
|
+
declare class BetterAuthClientAdapter<UserBetterAuthInstance extends ReturnType<typeof createAuthClient>> extends SyncAdapter<UserBetterAuthInstance> {
|
5
|
+
authClient: UserBetterAuthInstance;
|
6
|
+
constructor({ authClient }: {
|
7
|
+
authClient: UserBetterAuthInstance;
|
8
|
+
});
|
9
|
+
export(): UserBetterAuthInstance;
|
10
|
+
}
|
11
|
+
|
12
|
+
export { BetterAuthClientAdapter };
|
package/dist/client.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
// src/client.ts
|
2
|
+
import { SyncAdapter } from "@xframework/x/adapter";
|
3
|
+
var BetterAuthClientAdapter = class extends SyncAdapter {
|
4
|
+
authClient;
|
5
|
+
constructor({ authClient }) {
|
6
|
+
super();
|
7
|
+
this.authClient = authClient;
|
8
|
+
}
|
9
|
+
export() {
|
10
|
+
return this.authClient;
|
11
|
+
}
|
12
|
+
};
|
13
|
+
export {
|
14
|
+
BetterAuthClientAdapter
|
15
|
+
};
|
16
|
+
//# sourceMappingURL=client.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import { SyncAdapter } from \"@xframework/x/adapter\";\nimport type { createAuthClient } from \"better-auth/client\";\n\nexport class BetterAuthClientAdapter<\n UserBetterAuthInstance extends ReturnType<typeof createAuthClient>,\n> extends SyncAdapter<UserBetterAuthInstance> {\n public authClient: UserBetterAuthInstance;\n constructor({ authClient }: { authClient: UserBetterAuthInstance }) {\n super();\n this.authClient = authClient;\n }\n\n export() {\n return this.authClient;\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAGrB,IAAM,0BAAN,cAEG,YAAoC;AAAA,EACrC;AAAA,EACP,YAAY,EAAE,WAAW,GAA2C;AAClE,UAAM;AACN,SAAK,aAAa;AAAA,EACpB;AAAA,EAEA,SAAS;AACP,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
package/dist/server.cjs
ADDED
@@ -0,0 +1,41 @@
|
|
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/server.ts
|
21
|
+
var server_exports = {};
|
22
|
+
__export(server_exports, {
|
23
|
+
BetterAuthServerAdapter: () => BetterAuthServerAdapter
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(server_exports);
|
26
|
+
var import_adapter = require("@xframework/x/adapter");
|
27
|
+
var BetterAuthServerAdapter = class extends import_adapter.SyncAdapter {
|
28
|
+
auth;
|
29
|
+
constructor({ auth }) {
|
30
|
+
super();
|
31
|
+
this.auth = auth;
|
32
|
+
}
|
33
|
+
export() {
|
34
|
+
return this.auth;
|
35
|
+
}
|
36
|
+
};
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
38
|
+
0 && (module.exports = {
|
39
|
+
BetterAuthServerAdapter
|
40
|
+
});
|
41
|
+
//# sourceMappingURL=server.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { SyncAdapter } from \"@xframework/x/adapter\";\nimport type { betterAuth } from \"better-auth\";\n\nexport class BetterAuthServerAdapter<\n UserBetterAuthInstance extends ReturnType<typeof betterAuth>,\n> extends SyncAdapter<UserBetterAuthInstance> {\n public auth: UserBetterAuthInstance;\n constructor({ auth }: { auth: UserBetterAuthInstance }) {\n super();\n this.auth = auth;\n }\n\n export() {\n return this.auth;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA4B;AAGrB,IAAM,0BAAN,cAEG,2BAAoC;AAAA,EACrC;AAAA,EACP,YAAY,EAAE,KAAK,GAAqC;AACtD,UAAM;AACN,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,SAAS;AACP,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { SyncAdapter } from '@xframework/x/adapter';
|
2
|
+
import { betterAuth } from 'better-auth';
|
3
|
+
|
4
|
+
declare class BetterAuthServerAdapter<UserBetterAuthInstance extends ReturnType<typeof betterAuth>> extends SyncAdapter<UserBetterAuthInstance> {
|
5
|
+
auth: UserBetterAuthInstance;
|
6
|
+
constructor({ auth }: {
|
7
|
+
auth: UserBetterAuthInstance;
|
8
|
+
});
|
9
|
+
export(): UserBetterAuthInstance;
|
10
|
+
}
|
11
|
+
|
12
|
+
export { BetterAuthServerAdapter };
|
package/dist/server.d.ts
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
import { SyncAdapter } from '@xframework/x/adapter';
|
2
|
+
import { betterAuth } from 'better-auth';
|
3
|
+
|
4
|
+
declare class BetterAuthServerAdapter<UserBetterAuthInstance extends ReturnType<typeof betterAuth>> extends SyncAdapter<UserBetterAuthInstance> {
|
5
|
+
auth: UserBetterAuthInstance;
|
6
|
+
constructor({ auth }: {
|
7
|
+
auth: UserBetterAuthInstance;
|
8
|
+
});
|
9
|
+
export(): UserBetterAuthInstance;
|
10
|
+
}
|
11
|
+
|
12
|
+
export { BetterAuthServerAdapter };
|
package/dist/server.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
// src/server.ts
|
2
|
+
import { SyncAdapter } from "@xframework/x/adapter";
|
3
|
+
var BetterAuthServerAdapter = class extends SyncAdapter {
|
4
|
+
auth;
|
5
|
+
constructor({ auth }) {
|
6
|
+
super();
|
7
|
+
this.auth = auth;
|
8
|
+
}
|
9
|
+
export() {
|
10
|
+
return this.auth;
|
11
|
+
}
|
12
|
+
};
|
13
|
+
export {
|
14
|
+
BetterAuthServerAdapter
|
15
|
+
};
|
16
|
+
//# sourceMappingURL=server.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { SyncAdapter } from \"@xframework/x/adapter\";\nimport type { betterAuth } from \"better-auth\";\n\nexport class BetterAuthServerAdapter<\n UserBetterAuthInstance extends ReturnType<typeof betterAuth>,\n> extends SyncAdapter<UserBetterAuthInstance> {\n public auth: UserBetterAuthInstance;\n constructor({ auth }: { auth: UserBetterAuthInstance }) {\n super();\n this.auth = auth;\n }\n\n export() {\n return this.auth;\n }\n}\n"],"mappings":";AAAA,SAAS,mBAAmB;AAGrB,IAAM,0BAAN,cAEG,YAAoC;AAAA,EACrC;AAAA,EACP,YAAY,EAAE,KAAK,GAAqC;AACtD,UAAM;AACN,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,SAAS;AACP,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
package/package.json
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
{
|
2
|
+
"name": "@xframework/better-auth",
|
3
|
+
"version": "0.4.0",
|
4
|
+
"type": "module",
|
5
|
+
"exports": {
|
6
|
+
"./client": {
|
7
|
+
"types": "./dist/client.d.ts",
|
8
|
+
"require": "./dist/client.cjs",
|
9
|
+
"import": "./dist/client.js"
|
10
|
+
},
|
11
|
+
"./server": {
|
12
|
+
"types": "./dist/server.d.ts",
|
13
|
+
"require": "./dist/server.cjs",
|
14
|
+
"import": "./dist/server.js"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
"publishConfig": {
|
18
|
+
"access": "public"
|
19
|
+
},
|
20
|
+
"dependencies": {
|
21
|
+
"@xframework/x": "0.4.0"
|
22
|
+
},
|
23
|
+
"peerDependencies": {
|
24
|
+
"better-auth": ">=1.0.0"
|
25
|
+
},
|
26
|
+
"devDependencies": {
|
27
|
+
"@types/node": "^20.11.24",
|
28
|
+
"tsup": "^8.2.4",
|
29
|
+
"typescript": "^5.5.4"
|
30
|
+
},
|
31
|
+
"scripts": {
|
32
|
+
"build": "tsup",
|
33
|
+
"dev": "tsup --watch"
|
34
|
+
}
|
35
|
+
}
|
@@ -0,0 +1,211 @@
|
|
1
|
+
import { expect, it, describe } from "vitest";
|
2
|
+
import { createX } from "@xframework/x";
|
3
|
+
import { BetterAuthClientAdapter } from "../client";
|
4
|
+
import { BetterAuthServerAdapter } from "../server";
|
5
|
+
import type { createAuthClient } from "better-auth/client";
|
6
|
+
import type { betterAuth } from "better-auth";
|
7
|
+
|
8
|
+
describe("BetterAuthClientAdapter", () => {
|
9
|
+
const mockUser = {
|
10
|
+
id: "test-id",
|
11
|
+
email: "test@example.com",
|
12
|
+
name: "Test User",
|
13
|
+
image: null as string | null | undefined,
|
14
|
+
emailVerified: true,
|
15
|
+
createdAt: new Date(),
|
16
|
+
updatedAt: new Date(),
|
17
|
+
} as const;
|
18
|
+
|
19
|
+
const mockSession = {
|
20
|
+
id: "session-id",
|
21
|
+
createdAt: new Date(),
|
22
|
+
updatedAt: new Date(),
|
23
|
+
userId: mockUser.id,
|
24
|
+
expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000),
|
25
|
+
token: "test-token",
|
26
|
+
ipAddress: "127.0.0.1",
|
27
|
+
userAgent: "test-agent",
|
28
|
+
} as const;
|
29
|
+
|
30
|
+
type MockResponse<T> = {
|
31
|
+
ok: true;
|
32
|
+
data: T;
|
33
|
+
error: null;
|
34
|
+
status: number;
|
35
|
+
};
|
36
|
+
|
37
|
+
const mockAuthClient = {
|
38
|
+
signIn: {
|
39
|
+
social: async () =>
|
40
|
+
({
|
41
|
+
ok: true,
|
42
|
+
data: {
|
43
|
+
redirect: false as const,
|
44
|
+
token: "test-token",
|
45
|
+
url: undefined,
|
46
|
+
user: mockUser,
|
47
|
+
},
|
48
|
+
error: null,
|
49
|
+
status: 200,
|
50
|
+
}) satisfies MockResponse<{
|
51
|
+
redirect: boolean;
|
52
|
+
token: string;
|
53
|
+
url: undefined;
|
54
|
+
user: typeof mockUser;
|
55
|
+
}>,
|
56
|
+
credentials: async () =>
|
57
|
+
({
|
58
|
+
ok: true,
|
59
|
+
data: {
|
60
|
+
redirect: false as const,
|
61
|
+
token: "test-token",
|
62
|
+
url: undefined,
|
63
|
+
user: mockUser,
|
64
|
+
},
|
65
|
+
error: null,
|
66
|
+
status: 200,
|
67
|
+
}) satisfies MockResponse<{
|
68
|
+
redirect: boolean;
|
69
|
+
token: string;
|
70
|
+
url: undefined;
|
71
|
+
user: typeof mockUser;
|
72
|
+
}>,
|
73
|
+
},
|
74
|
+
signOut: async () =>
|
75
|
+
({
|
76
|
+
ok: true,
|
77
|
+
data: { success: true },
|
78
|
+
error: null,
|
79
|
+
status: 200,
|
80
|
+
}) satisfies MockResponse<{ success: boolean }>,
|
81
|
+
getSession: async () =>
|
82
|
+
({
|
83
|
+
ok: true,
|
84
|
+
data: {
|
85
|
+
user: mockUser,
|
86
|
+
session: mockSession,
|
87
|
+
},
|
88
|
+
error: null,
|
89
|
+
status: 200,
|
90
|
+
}) satisfies MockResponse<{
|
91
|
+
user: typeof mockUser;
|
92
|
+
session: typeof mockSession;
|
93
|
+
}>,
|
94
|
+
} as unknown as ReturnType<typeof createAuthClient>;
|
95
|
+
|
96
|
+
it("should properly initialize and export auth client instance", () => {
|
97
|
+
const adapter = new BetterAuthClientAdapter({
|
98
|
+
authClient: mockAuthClient,
|
99
|
+
});
|
100
|
+
|
101
|
+
expect(adapter.authClient).toBe(mockAuthClient);
|
102
|
+
expect(adapter.export()).toBe(mockAuthClient);
|
103
|
+
});
|
104
|
+
|
105
|
+
it("should integrate with X framework", () => {
|
106
|
+
const x = createX()
|
107
|
+
.syncAdapter(
|
108
|
+
"auth",
|
109
|
+
() =>
|
110
|
+
new BetterAuthClientAdapter({
|
111
|
+
authClient: mockAuthClient,
|
112
|
+
}),
|
113
|
+
)
|
114
|
+
.build();
|
115
|
+
|
116
|
+
expect(x._.adapters.auth).toBeInstanceOf(BetterAuthClientAdapter);
|
117
|
+
expect(x.auth).toBe(mockAuthClient);
|
118
|
+
expect(typeof x.auth.signIn.social).toBe("function");
|
119
|
+
// @ts-expect-error credentials exists at runtime but TypeScript doesn't know about it
|
120
|
+
expect(typeof x.auth.signIn.credentials).toBe("function");
|
121
|
+
expect(typeof x.auth.signOut).toBe("function");
|
122
|
+
expect(typeof x.auth.getSession).toBe("function");
|
123
|
+
});
|
124
|
+
});
|
125
|
+
|
126
|
+
describe("BetterAuthServerAdapter", () => {
|
127
|
+
const mockAuth = {
|
128
|
+
handler: async (request: Request) => new Response(),
|
129
|
+
api: {} as ReturnType<typeof betterAuth>["api"],
|
130
|
+
options: {},
|
131
|
+
$context: Promise.resolve({
|
132
|
+
session: null,
|
133
|
+
user: null,
|
134
|
+
}),
|
135
|
+
$metadata: {},
|
136
|
+
$types: {},
|
137
|
+
$Infer: {
|
138
|
+
Session: {
|
139
|
+
session: {
|
140
|
+
id: "session-id",
|
141
|
+
createdAt: new Date(),
|
142
|
+
updatedAt: new Date(),
|
143
|
+
userId: "user-id",
|
144
|
+
expiresAt: new Date(),
|
145
|
+
token: "token",
|
146
|
+
ipAddress: null,
|
147
|
+
userAgent: null,
|
148
|
+
},
|
149
|
+
user: {
|
150
|
+
id: "user-id",
|
151
|
+
email: "test@example.com",
|
152
|
+
name: "Test User",
|
153
|
+
image: null,
|
154
|
+
emailVerified: true,
|
155
|
+
createdAt: new Date(),
|
156
|
+
updatedAt: new Date(),
|
157
|
+
},
|
158
|
+
},
|
159
|
+
},
|
160
|
+
$ERROR_CODES: {
|
161
|
+
USER_NOT_FOUND: "USER_NOT_FOUND",
|
162
|
+
FAILED_TO_CREATE_USER: "FAILED_TO_CREATE_USER",
|
163
|
+
FAILED_TO_CREATE_SESSION: "FAILED_TO_CREATE_SESSION",
|
164
|
+
FAILED_TO_UPDATE_USER: "FAILED_TO_UPDATE_USER",
|
165
|
+
FAILED_TO_GET_SESSION: "FAILED_TO_GET_SESSION",
|
166
|
+
INVALID_PASSWORD: "INVALID_PASSWORD",
|
167
|
+
INVALID_EMAIL: "INVALID_EMAIL",
|
168
|
+
EMAIL_ALREADY_EXISTS: "EMAIL_ALREADY_EXISTS",
|
169
|
+
INVALID_TOKEN: "INVALID_TOKEN",
|
170
|
+
EXPIRED_TOKEN: "EXPIRED_TOKEN",
|
171
|
+
INVALID_CODE: "INVALID_CODE",
|
172
|
+
EXPIRED_CODE: "EXPIRED_CODE",
|
173
|
+
INVALID_PROVIDER: "INVALID_PROVIDER",
|
174
|
+
INVALID_CREDENTIALS: "INVALID_CREDENTIALS",
|
175
|
+
INVALID_SESSION: "INVALID_SESSION",
|
176
|
+
EXPIRED_SESSION: "EXPIRED_SESSION",
|
177
|
+
INVALID_REFRESH_TOKEN: "INVALID_REFRESH_TOKEN",
|
178
|
+
EXPIRED_REFRESH_TOKEN: "EXPIRED_REFRESH_TOKEN",
|
179
|
+
INVALID_RESET_TOKEN: "INVALID_RESET_TOKEN",
|
180
|
+
EXPIRED_RESET_TOKEN: "EXPIRED_RESET_TOKEN",
|
181
|
+
ACCOUNT_NOT_FOUND: "ACCOUNT_NOT_FOUND",
|
182
|
+
},
|
183
|
+
} as unknown as ReturnType<typeof betterAuth>;
|
184
|
+
|
185
|
+
it("should properly initialize and export auth instance", () => {
|
186
|
+
const adapter = new BetterAuthServerAdapter({
|
187
|
+
auth: mockAuth,
|
188
|
+
});
|
189
|
+
|
190
|
+
expect(adapter.auth).toBe(mockAuth);
|
191
|
+
expect(adapter.export()).toBe(mockAuth);
|
192
|
+
});
|
193
|
+
|
194
|
+
it("should integrate with X framework", () => {
|
195
|
+
const x = createX()
|
196
|
+
.syncAdapter(
|
197
|
+
"auth",
|
198
|
+
() =>
|
199
|
+
new BetterAuthServerAdapter({
|
200
|
+
auth: mockAuth,
|
201
|
+
}),
|
202
|
+
)
|
203
|
+
.build();
|
204
|
+
|
205
|
+
expect(x._.adapters.auth).toBeInstanceOf(BetterAuthServerAdapter);
|
206
|
+
expect(x.auth).toBe(mockAuth);
|
207
|
+
expect(typeof x.auth.handler).toBe("function");
|
208
|
+
expect(x.auth.api).toBeDefined();
|
209
|
+
expect(x.auth.options).toBeDefined();
|
210
|
+
});
|
211
|
+
});
|
package/src/client.ts
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import { SyncAdapter } from "@xframework/x/adapter";
|
2
|
+
import type { createAuthClient } from "better-auth/client";
|
3
|
+
|
4
|
+
export class BetterAuthClientAdapter<
|
5
|
+
UserBetterAuthInstance extends ReturnType<typeof createAuthClient>,
|
6
|
+
> extends SyncAdapter<UserBetterAuthInstance> {
|
7
|
+
public authClient: UserBetterAuthInstance;
|
8
|
+
constructor({ authClient }: { authClient: UserBetterAuthInstance }) {
|
9
|
+
super();
|
10
|
+
this.authClient = authClient;
|
11
|
+
}
|
12
|
+
|
13
|
+
export() {
|
14
|
+
return this.authClient;
|
15
|
+
}
|
16
|
+
}
|
package/src/server.ts
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import { SyncAdapter } from "@xframework/x/adapter";
|
2
|
+
import type { betterAuth } from "better-auth";
|
3
|
+
|
4
|
+
export class BetterAuthServerAdapter<
|
5
|
+
UserBetterAuthInstance extends ReturnType<typeof betterAuth>,
|
6
|
+
> extends SyncAdapter<UserBetterAuthInstance> {
|
7
|
+
public auth: UserBetterAuthInstance;
|
8
|
+
constructor({ auth }: { auth: UserBetterAuthInstance }) {
|
9
|
+
super();
|
10
|
+
this.auth = auth;
|
11
|
+
}
|
12
|
+
|
13
|
+
export() {
|
14
|
+
return this.auth;
|
15
|
+
}
|
16
|
+
}
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED