@momentumcms/auth 0.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/CHANGELOG.md +30 -0
- package/CLAUDE.md +130 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/index.cjs +1227 -0
- package/package.json +37 -0
- package/src/index.d.ts +10 -0
- package/src/lib/auth-collections.d.ts +27 -0
- package/src/lib/auth-plugin.d.ts +79 -0
- package/src/lib/auth.d.ts +144 -0
- package/src/lib/email-templates.d.ts +48 -0
- package/src/lib/email.d.ts +72 -0
- package/src/lib/plugins/admin.d.ts +19 -0
- package/src/lib/plugins/index.d.ts +4 -0
- package/src/lib/plugins/organization.d.ts +19 -0
- package/src/lib/plugins/sub-plugin.types.d.ts +29 -0
- package/src/lib/plugins/two-factor.d.ts +12 -0
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@momentumcms/auth",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Better Auth integration for Momentum CMS",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Momentum CMS Contributors",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/momentum-cms/momentum-cms.git",
|
|
10
|
+
"directory": "libs/auth"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/momentum-cms/momentum-cms#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/momentum-cms/momentum-cms/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"cms",
|
|
18
|
+
"momentum-cms",
|
|
19
|
+
"authentication",
|
|
20
|
+
"better-auth",
|
|
21
|
+
"auth"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"type": "commonjs",
|
|
27
|
+
"main": "./index.cjs",
|
|
28
|
+
"types": "./src/index.d.ts",
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@momentumcms/core": ">=0.0.1",
|
|
31
|
+
"@momentumcms/logger": ">=0.0.1",
|
|
32
|
+
"better-auth": "^1.4.0",
|
|
33
|
+
"better-sqlite3": "^12.0.0",
|
|
34
|
+
"nodemailer": "^8.0.0",
|
|
35
|
+
"pg": "^8.0.0"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './lib/auth';
|
|
2
|
+
export * from './lib/email';
|
|
3
|
+
export * from './lib/email-templates';
|
|
4
|
+
export { momentumAuth } from './lib/auth-plugin';
|
|
5
|
+
export type { MomentumAuthPluginConfig, MomentumAuthPlugin, MomentumAuthPluginRuntimeConfig, } from './lib/auth-plugin';
|
|
6
|
+
export { AuthUserCollection, AuthSessionCollection, AuthAccountCollection, AuthVerificationCollection, AuthApiKeysCollection, BASE_AUTH_COLLECTIONS, } from './lib/auth-collections';
|
|
7
|
+
export { authTwoFactor } from './lib/plugins/two-factor';
|
|
8
|
+
export { authAdmin } from './lib/plugins/admin';
|
|
9
|
+
export { authOrganization } from './lib/plugins/organization';
|
|
10
|
+
export type { MomentumAuthSubPlugin } from './lib/plugins/sub-plugin.types';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Auth Collections for Momentum CMS
|
|
3
|
+
*
|
|
4
|
+
* Defines Better Auth tables as Momentum collections.
|
|
5
|
+
* Visible collections (auth-user, auth-api-keys) are fully interactive in the
|
|
6
|
+
* admin UI with access restricted to admin role. Internal collections (session,
|
|
7
|
+
* account, verification) are managed and hidden — Better Auth owns those data
|
|
8
|
+
* operations.
|
|
9
|
+
*
|
|
10
|
+
* Column types are chosen to match Better Auth's expected schema exactly.
|
|
11
|
+
*/
|
|
12
|
+
import type { CollectionConfig, SelectOption } from '@momentumcms/core';
|
|
13
|
+
/**
|
|
14
|
+
* Canonical list of auth roles, ordered by privilege (highest first).
|
|
15
|
+
* Used by both server middleware and admin UI for role validation and display.
|
|
16
|
+
*/
|
|
17
|
+
export declare const AUTH_ROLES: SelectOption[];
|
|
18
|
+
export declare const AuthUserCollection: CollectionConfig;
|
|
19
|
+
export declare const AuthSessionCollection: CollectionConfig;
|
|
20
|
+
export declare const AuthAccountCollection: CollectionConfig;
|
|
21
|
+
export declare const AuthVerificationCollection: CollectionConfig;
|
|
22
|
+
export declare const AuthApiKeysCollection: CollectionConfig;
|
|
23
|
+
/**
|
|
24
|
+
* All base auth collections.
|
|
25
|
+
* These are injected into the Momentum config by the auth plugin's onInit.
|
|
26
|
+
*/
|
|
27
|
+
export declare const BASE_AUTH_COLLECTIONS: CollectionConfig[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Momentum Auth Plugin Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates a first-class Momentum plugin that manages all Better Auth integration:
|
|
5
|
+
* - Injects auth collections into the Momentum config (schema generation)
|
|
6
|
+
* - Creates the Better Auth instance with dynamic plugins/fields
|
|
7
|
+
* - Exposes getAuth()/tryGetAuth() for server framework middleware creation
|
|
8
|
+
*
|
|
9
|
+
* Framework-agnostic: no Express dependency. Middleware creation is handled by
|
|
10
|
+
* @momentumcms/server-express (initializeMomentum + createDeferredSessionResolver).
|
|
11
|
+
*/
|
|
12
|
+
import type { MomentumPlugin, Field } from '@momentumcms/core';
|
|
13
|
+
import { type MomentumAuth, type DatabaseConfig, type MomentumEmailOptions, type OAuthProvidersConfig } from './auth';
|
|
14
|
+
import type { MomentumAuthSubPlugin } from './plugins/sub-plugin.types';
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for the Momentum Auth plugin.
|
|
17
|
+
*/
|
|
18
|
+
export interface MomentumAuthPluginConfig {
|
|
19
|
+
/** Database configuration (same as createMomentumAuth) */
|
|
20
|
+
db: DatabaseConfig;
|
|
21
|
+
/** Base URL of the application (e.g., 'http://localhost:4000') */
|
|
22
|
+
baseURL?: string;
|
|
23
|
+
/** Secret key for signing tokens */
|
|
24
|
+
secret?: string;
|
|
25
|
+
/** Trusted origins for CORS */
|
|
26
|
+
trustedOrigins?: string[];
|
|
27
|
+
/** Email configuration */
|
|
28
|
+
email?: MomentumEmailOptions;
|
|
29
|
+
/** OAuth social login providers */
|
|
30
|
+
socialProviders?: OAuthProvidersConfig;
|
|
31
|
+
/** Auth sub-plugins (2FA, admin, organization, etc.) */
|
|
32
|
+
plugins?: MomentumAuthSubPlugin[];
|
|
33
|
+
/** Admin UI configuration */
|
|
34
|
+
admin?: {
|
|
35
|
+
/** Show auth collections in admin UI. Default: true */
|
|
36
|
+
showCollections?: boolean;
|
|
37
|
+
};
|
|
38
|
+
/** Extra fields to add to the auth-user collection */
|
|
39
|
+
userFields?: Field[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Config exposed by the auth plugin for the server framework to create middleware.
|
|
43
|
+
* This avoids the auth library needing to import server-express (circular dep).
|
|
44
|
+
*/
|
|
45
|
+
export interface MomentumAuthPluginRuntimeConfig {
|
|
46
|
+
db: DatabaseConfig;
|
|
47
|
+
socialProviders?: OAuthProvidersConfig;
|
|
48
|
+
}
|
|
49
|
+
export interface MomentumAuthPlugin extends MomentumPlugin {
|
|
50
|
+
/** Get the Better Auth instance (available after onInit). Throws if not yet initialized. */
|
|
51
|
+
getAuth(): MomentumAuth;
|
|
52
|
+
/** Get the Better Auth instance if initialized, or null if not yet ready. */
|
|
53
|
+
tryGetAuth(): MomentumAuth | null;
|
|
54
|
+
/** Get the plugin's runtime config (db, socialProviders) for server-framework middleware creation. */
|
|
55
|
+
getPluginConfig(): MomentumAuthPluginRuntimeConfig;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates the Momentum Auth plugin.
|
|
59
|
+
*
|
|
60
|
+
* This is the recommended way to integrate Better Auth with Momentum CMS.
|
|
61
|
+
* Add the returned plugin to your `momentum.config.ts` plugins array.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { momentumAuth, authTwoFactor } from '@momentumcms/auth';
|
|
66
|
+
*
|
|
67
|
+
* export default defineMomentumConfig({
|
|
68
|
+
* plugins: [
|
|
69
|
+
* momentumAuth({
|
|
70
|
+
* db: { type: 'postgres', pool },
|
|
71
|
+
* baseURL: 'http://localhost:4000',
|
|
72
|
+
* plugins: [authTwoFactor()],
|
|
73
|
+
* }),
|
|
74
|
+
* ],
|
|
75
|
+
* collections: [Posts],
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function momentumAuth(config: MomentumAuthPluginConfig): MomentumAuthPlugin;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { betterAuth } from 'better-auth';
|
|
2
|
+
import type { Pool } from 'pg';
|
|
3
|
+
import type { Database } from 'better-sqlite3';
|
|
4
|
+
import { type EmailConfig } from './email';
|
|
5
|
+
import type { Field } from '@momentumcms/core';
|
|
6
|
+
/**
|
|
7
|
+
* Database configuration for Better Auth.
|
|
8
|
+
* Supports both SQLite (better-sqlite3) and PostgreSQL (pg).
|
|
9
|
+
*/
|
|
10
|
+
export type DatabaseConfig = {
|
|
11
|
+
type: 'sqlite';
|
|
12
|
+
database: Database;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'postgres';
|
|
15
|
+
pool: Pool;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Email configuration options for Momentum Auth.
|
|
19
|
+
*/
|
|
20
|
+
export interface MomentumEmailOptions extends EmailConfig {
|
|
21
|
+
/** Enable email features (password reset, verification). Default: auto-detect from SMTP_HOST env var */
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
/** Application name shown in emails. Default: 'Momentum CMS' */
|
|
24
|
+
appName?: string;
|
|
25
|
+
/** Require email verification on signup. Default: false */
|
|
26
|
+
requireEmailVerification?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* OAuth provider configuration.
|
|
30
|
+
*/
|
|
31
|
+
export interface OAuthProviderConfig {
|
|
32
|
+
clientId: string;
|
|
33
|
+
clientSecret: string;
|
|
34
|
+
redirectURI?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Supported OAuth providers.
|
|
38
|
+
*/
|
|
39
|
+
export interface OAuthProvidersConfig {
|
|
40
|
+
google?: OAuthProviderConfig;
|
|
41
|
+
github?: OAuthProviderConfig;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Configuration options for Momentum Auth.
|
|
45
|
+
*/
|
|
46
|
+
export interface MomentumAuthConfig {
|
|
47
|
+
/** Database configuration - supports SQLite or PostgreSQL */
|
|
48
|
+
db: DatabaseConfig;
|
|
49
|
+
/** Base URL of the application (e.g., 'http://localhost:4000') */
|
|
50
|
+
baseURL?: string;
|
|
51
|
+
/** Secret key for signing tokens. Use env var AUTH_SECRET in production. */
|
|
52
|
+
secret?: string;
|
|
53
|
+
/** Trusted origins for CORS */
|
|
54
|
+
trustedOrigins?: string[];
|
|
55
|
+
/** Email configuration for password reset and verification */
|
|
56
|
+
email?: MomentumEmailOptions;
|
|
57
|
+
/** OAuth social login providers */
|
|
58
|
+
socialProviders?: OAuthProvidersConfig;
|
|
59
|
+
/** Enable two-factor authentication (TOTP). Default: false */
|
|
60
|
+
twoFactorAuth?: boolean;
|
|
61
|
+
/** Additional Better Auth plugins (from sub-plugins). */
|
|
62
|
+
plugins?: unknown[];
|
|
63
|
+
/** Extra user fields to register with Better Auth's user.additionalFields. */
|
|
64
|
+
userFields?: Field[];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Legacy configuration for SQLite (backwards compatibility).
|
|
68
|
+
*/
|
|
69
|
+
export interface MomentumAuthConfigLegacy {
|
|
70
|
+
/** The better-sqlite3 database instance (deprecated, use db instead) */
|
|
71
|
+
database: Database;
|
|
72
|
+
/** Base URL of the application (e.g., 'http://localhost:4000') */
|
|
73
|
+
baseURL?: string;
|
|
74
|
+
/** Secret key for signing tokens. Use env var AUTH_SECRET in production. */
|
|
75
|
+
secret?: string;
|
|
76
|
+
/** Trusted origins for CORS */
|
|
77
|
+
trustedOrigins?: string[];
|
|
78
|
+
/** Email configuration for password reset and verification */
|
|
79
|
+
email?: MomentumEmailOptions;
|
|
80
|
+
/** OAuth social login providers */
|
|
81
|
+
socialProviders?: OAuthProvidersConfig;
|
|
82
|
+
/** Enable two-factor authentication (TOTP). Default: false */
|
|
83
|
+
twoFactorAuth?: boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* User type from Better Auth with additional role field.
|
|
87
|
+
*/
|
|
88
|
+
export interface MomentumUser {
|
|
89
|
+
id: string;
|
|
90
|
+
email: string;
|
|
91
|
+
name: string;
|
|
92
|
+
role: string;
|
|
93
|
+
emailVerified: boolean;
|
|
94
|
+
twoFactorEnabled?: boolean;
|
|
95
|
+
image?: string | null;
|
|
96
|
+
createdAt: Date;
|
|
97
|
+
updatedAt: Date;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Session type from Better Auth.
|
|
101
|
+
*/
|
|
102
|
+
export interface MomentumSession {
|
|
103
|
+
id: string;
|
|
104
|
+
userId: string;
|
|
105
|
+
token: string;
|
|
106
|
+
expiresAt: Date;
|
|
107
|
+
ipAddress?: string | null;
|
|
108
|
+
userAgent?: string | null;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the list of enabled OAuth provider names from config/env vars.
|
|
112
|
+
* Useful for exposing available providers to the client.
|
|
113
|
+
*/
|
|
114
|
+
export declare function getEnabledOAuthProviders(config?: OAuthProvidersConfig): string[];
|
|
115
|
+
/**
|
|
116
|
+
* Creates a Momentum Auth instance using Better Auth.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* import { createMomentumAuth } from '@momentumcms/auth';
|
|
121
|
+
*
|
|
122
|
+
* // With PostgreSQL
|
|
123
|
+
* const auth = createMomentumAuth({
|
|
124
|
+
* db: { type: 'postgres', pool: pgPool },
|
|
125
|
+
* baseURL: 'http://localhost:4000',
|
|
126
|
+
* secret: process.env.AUTH_SECRET,
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* // With SQLite (legacy)
|
|
130
|
+
* const auth = createMomentumAuth({
|
|
131
|
+
* database: sqliteDb,
|
|
132
|
+
* baseURL: 'http://localhost:4000',
|
|
133
|
+
* secret: process.env.AUTH_SECRET,
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* // Use in Express
|
|
137
|
+
* app.all('/api/auth/*', toNodeHandler(auth));
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function createMomentumAuth(config: MomentumAuthConfig | MomentumAuthConfigLegacy): ReturnType<typeof betterAuth>;
|
|
141
|
+
/**
|
|
142
|
+
* Type for the Momentum Auth instance.
|
|
143
|
+
*/
|
|
144
|
+
export type MomentumAuth = ReturnType<typeof createMomentumAuth>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email template options.
|
|
3
|
+
*/
|
|
4
|
+
interface EmailTemplateOptions {
|
|
5
|
+
/** Recipient's name */
|
|
6
|
+
name?: string;
|
|
7
|
+
/** Action URL (reset link, verification link, etc.) */
|
|
8
|
+
url: string;
|
|
9
|
+
/** Application name (default: 'Momentum CMS') */
|
|
10
|
+
appName?: string;
|
|
11
|
+
/** Expiration time for the link (e.g., '1 hour') */
|
|
12
|
+
expiresIn?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Generate password reset email content.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const { subject, text, html } = getPasswordResetEmail({
|
|
20
|
+
* name: 'John',
|
|
21
|
+
* url: 'https://example.com/admin/reset-password?token=abc123',
|
|
22
|
+
* expiresIn: '1 hour',
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function getPasswordResetEmail(options: EmailTemplateOptions): {
|
|
27
|
+
subject: string;
|
|
28
|
+
text: string;
|
|
29
|
+
html: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Generate email verification email content.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const { subject, text, html } = getVerificationEmail({
|
|
37
|
+
* name: 'John',
|
|
38
|
+
* url: 'https://example.com/admin/verify-email?token=abc123',
|
|
39
|
+
* expiresIn: '24 hours',
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function getVerificationEmail(options: EmailTemplateOptions): {
|
|
44
|
+
subject: string;
|
|
45
|
+
text: string;
|
|
46
|
+
html: string;
|
|
47
|
+
};
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email configuration options.
|
|
3
|
+
*/
|
|
4
|
+
export interface EmailConfig {
|
|
5
|
+
/** SMTP server hostname (default: localhost) */
|
|
6
|
+
host?: string;
|
|
7
|
+
/** SMTP server port (default: 1025 for Mailpit) */
|
|
8
|
+
port?: number;
|
|
9
|
+
/** Sender email address */
|
|
10
|
+
from?: string;
|
|
11
|
+
/** Use TLS/SSL (default: false for local dev) */
|
|
12
|
+
secure?: boolean;
|
|
13
|
+
/** SMTP authentication credentials */
|
|
14
|
+
auth?: {
|
|
15
|
+
user: string;
|
|
16
|
+
pass: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options for sending an email.
|
|
21
|
+
*/
|
|
22
|
+
export interface SendEmailOptions {
|
|
23
|
+
/** Recipient email address */
|
|
24
|
+
to: string;
|
|
25
|
+
/** Email subject line */
|
|
26
|
+
subject: string;
|
|
27
|
+
/** Plain text body */
|
|
28
|
+
text: string;
|
|
29
|
+
/** HTML body (optional) */
|
|
30
|
+
html?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Email service for sending transactional emails.
|
|
34
|
+
*/
|
|
35
|
+
export interface EmailService {
|
|
36
|
+
/**
|
|
37
|
+
* Send an email.
|
|
38
|
+
* @param options Email options (to, subject, text, html)
|
|
39
|
+
*/
|
|
40
|
+
sendEmail(options: SendEmailOptions): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create an email service with SMTP transport.
|
|
44
|
+
*
|
|
45
|
+
* Configuration is merged in order of priority:
|
|
46
|
+
* 1. Explicit config passed to this function
|
|
47
|
+
* 2. Environment variables (SMTP_HOST, SMTP_PORT, etc.)
|
|
48
|
+
* 3. Default values (Mailpit on localhost:1025)
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Use environment variables or defaults
|
|
53
|
+
* const emailService = createEmailService();
|
|
54
|
+
*
|
|
55
|
+
* // Or provide explicit config
|
|
56
|
+
* const emailService = createEmailService({
|
|
57
|
+
* host: 'smtp.example.com',
|
|
58
|
+
* port: 587,
|
|
59
|
+
* secure: true,
|
|
60
|
+
* auth: { user: 'apikey', pass: 'your-api-key' },
|
|
61
|
+
* from: 'noreply@example.com',
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* await emailService.sendEmail({
|
|
65
|
+
* to: 'user@example.com',
|
|
66
|
+
* subject: 'Password Reset',
|
|
67
|
+
* text: 'Click here to reset your password...',
|
|
68
|
+
* html: '<p>Click <a href="...">here</a> to reset your password.</p>',
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function createEmailService(config?: EmailConfig): EmailService;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin Sub-Plugin (Stub)
|
|
3
|
+
*
|
|
4
|
+
* Wraps Better Auth's admin plugin for user management capabilities:
|
|
5
|
+
* - Ban/unban users
|
|
6
|
+
* - Impersonate users
|
|
7
|
+
* - Admin-level session fields
|
|
8
|
+
*
|
|
9
|
+
* This is a stub — the Better Auth admin plugin import will be added
|
|
10
|
+
* when the full admin integration is implemented.
|
|
11
|
+
*/
|
|
12
|
+
import type { MomentumAuthSubPlugin } from './sub-plugin.types';
|
|
13
|
+
/**
|
|
14
|
+
* Creates the admin sub-plugin.
|
|
15
|
+
*
|
|
16
|
+
* Adds ban/impersonation fields to the user and session collections.
|
|
17
|
+
* The actual Better Auth admin plugin will be wired in a future iteration.
|
|
18
|
+
*/
|
|
19
|
+
export declare function authAdmin(): MomentumAuthSubPlugin;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Organization Sub-Plugin (Stub)
|
|
3
|
+
*
|
|
4
|
+
* Wraps Better Auth's organization plugin for multi-tenant capabilities:
|
|
5
|
+
* - Organizations
|
|
6
|
+
* - Members with roles
|
|
7
|
+
* - Invitations
|
|
8
|
+
*
|
|
9
|
+
* This is a stub — the Better Auth organization plugin import will be added
|
|
10
|
+
* when the full organization integration is implemented.
|
|
11
|
+
*/
|
|
12
|
+
import type { MomentumAuthSubPlugin } from './sub-plugin.types';
|
|
13
|
+
/**
|
|
14
|
+
* Creates the organization sub-plugin.
|
|
15
|
+
*
|
|
16
|
+
* Adds organization, member, and invitation collections.
|
|
17
|
+
* The actual Better Auth organization plugin will be wired in a future iteration.
|
|
18
|
+
*/
|
|
19
|
+
export declare function authOrganization(): MomentumAuthSubPlugin;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sub-Plugin Types for Momentum Auth
|
|
3
|
+
*
|
|
4
|
+
* Each sub-plugin wraps a Better Auth plugin and brings its own
|
|
5
|
+
* collections, user/session fields, and admin routes.
|
|
6
|
+
*/
|
|
7
|
+
import type { CollectionConfig, Field } from '@momentumcms/core';
|
|
8
|
+
import type { PluginAdminRouteDescriptor } from '@momentumcms/core';
|
|
9
|
+
/**
|
|
10
|
+
* A Momentum Auth sub-plugin wraps a Better Auth plugin.
|
|
11
|
+
*
|
|
12
|
+
* It declares what schema changes and admin UI additions the
|
|
13
|
+
* Better Auth plugin requires, allowing the auth plugin factory
|
|
14
|
+
* to merge everything together.
|
|
15
|
+
*/
|
|
16
|
+
export interface MomentumAuthSubPlugin {
|
|
17
|
+
/** Human-readable name (for logging / admin UI). */
|
|
18
|
+
name: string;
|
|
19
|
+
/** The Better Auth plugin instance to be spread into betterAuth({ plugins: [...] }). */
|
|
20
|
+
betterAuthPlugin: unknown;
|
|
21
|
+
/** Additional managed collections this plugin needs. */
|
|
22
|
+
collections?: CollectionConfig[];
|
|
23
|
+
/** Extra fields to add to the auth-user collection. */
|
|
24
|
+
userFields?: Field[];
|
|
25
|
+
/** Extra fields to add to the auth-session collection. */
|
|
26
|
+
sessionFields?: Field[];
|
|
27
|
+
/** Admin routes contributed by this plugin. */
|
|
28
|
+
adminRoutes?: PluginAdminRouteDescriptor[];
|
|
29
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two-Factor Authentication Sub-Plugin
|
|
3
|
+
*
|
|
4
|
+
* Wraps Better Auth's twoFactor plugin and provides:
|
|
5
|
+
* - A `twoFactor` managed collection (stores TOTP secrets and backup codes)
|
|
6
|
+
* - A `twoFactorEnabled` field on the auth-user collection
|
|
7
|
+
*/
|
|
8
|
+
import type { MomentumAuthSubPlugin } from './sub-plugin.types';
|
|
9
|
+
/**
|
|
10
|
+
* Creates the two-factor authentication sub-plugin.
|
|
11
|
+
*/
|
|
12
|
+
export declare function authTwoFactor(): MomentumAuthSubPlugin;
|