--- oldAuthClass.ts 2025-05-07 18:11:43
+++ authClass.ts 2025-05-07 18:12:53
@@ -1,5 +1,5 @@
-import { betterAuth, BetterAuthOptions } from "better-auth";
-import { jwt } from "better-auth/plugins";
+import { betterAuth, BetterAuthOptions, UnionToIntersection } from "better-auth";
+import { anonymous, jwt } from "better-auth/plugins";
const authInstance = betterAuth({
@@ -12,19 +12,28 @@
},
plugins: [jwt()],
});
+const plugins = [anonymous, jwt];
+type Plugins = typeof plugins;
+type PlugInReturnTypes = ReturnType<Plugins[number]>;
+type PluginEndpoints = UnionToIntersection<PlugInReturnTypes['endpoints']>;
+type PluginApis = {
+ api: PluginEndpoints;
+};
+
export class AuthService {
- authInstance: ReturnType<typeof betterAuth>;
+ authInstance: ReturnType<typeof betterAuth> & PluginApis;
constructor(o: BetterAuthOptions) {
this.authInstance = betterAuth({
...o,
emailAndPassword: {
enabled: true,
},
advanced: {
cookiePrefix: "pva_",
},
- plugins: [jwt()],
+ plugins: plugins.map((plugin) => plugin())
});
}
--- oldAuthClass.ts 2025-05-07 18:11:43
+++ authClass.ts 2025-05-07 18:12:53
@@ -1,5 +1,5 @@
-import { betterAuth, BetterAuthOptions } from "better-auth";
-import { jwt } from "better-auth/plugins";
+import { betterAuth, BetterAuthOptions, UnionToIntersection } from "better-auth";
+import { anonymous, jwt } from "better-auth/plugins";
const authInstance = betterAuth({
@@ -12,19 +12,28 @@
},
plugins: [jwt()],
});
+const plugins = [anonymous, jwt];
+type Plugins = typeof plugins;
+type PlugInReturnTypes = ReturnType<Plugins[number]>;
+type PluginEndpoints = UnionToIntersection<PlugInReturnTypes['endpoints']>;
+type PluginApis = {
+ api: PluginEndpoints;
+};
+
export class AuthService {
- authInstance: ReturnType<typeof betterAuth>;
+ authInstance: ReturnType<typeof betterAuth> & PluginApis;
constructor(o: BetterAuthOptions) {
this.authInstance = betterAuth({
...o,
emailAndPassword: {
enabled: true,
},
advanced: {
cookiePrefix: "pva_",
},
- plugins: [jwt()],
+ plugins: plugins.map((plugin) => plugin())
});
}