@objectstack/plugin-auth 4.0.4 → 4.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/README.md +4 -1
- package/dist/index.d.mts +441 -19940
- package/dist/index.d.ts +441 -19940
- package/dist/index.js +704 -900
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +699 -880
- package/dist/index.mjs.map +1 -1
- package/package.json +35 -12
- package/.turbo/turbo-build.log +0 -78
- package/ARCHITECTURE.md +0 -176
- package/CHANGELOG.md +0 -333
- package/IMPLEMENTATION_SUMMARY.md +0 -192
- package/examples/basic-usage.ts +0 -107
- package/objectstack.config.ts +0 -24
- package/src/auth-manager.test.ts +0 -883
- package/src/auth-manager.ts +0 -419
- package/src/auth-plugin.test.ts +0 -446
- package/src/auth-plugin.ts +0 -314
- package/src/auth-schema-config.ts +0 -339
- package/src/index.ts +0 -16
- package/src/objectql-adapter.test.ts +0 -281
- package/src/objectql-adapter.ts +0 -279
- package/src/objects/auth-account.object.ts +0 -7
- package/src/objects/auth-session.object.ts +0 -7
- package/src/objects/auth-user.object.ts +0 -7
- package/src/objects/auth-verification.object.ts +0 -7
- package/src/objects/index.ts +0 -40
- package/src/objects/sys-account.object.ts +0 -111
- package/src/objects/sys-api-key.object.ts +0 -104
- package/src/objects/sys-invitation.object.ts +0 -93
- package/src/objects/sys-member.object.ts +0 -68
- package/src/objects/sys-organization.object.ts +0 -82
- package/src/objects/sys-session.object.ts +0 -84
- package/src/objects/sys-team-member.object.ts +0 -61
- package/src/objects/sys-team.object.ts +0 -69
- package/src/objects/sys-two-factor.object.ts +0 -73
- package/src/objects/sys-user-preference.object.ts +0 -82
- package/src/objects/sys-user.object.ts +0 -91
- package/src/objects/sys-verification.object.ts +0 -75
- package/tsconfig.json +0 -18
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
# Auth Plugin Implementation Summary
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Successfully integrated the Better-Auth library (v1.4.18) into `@objectstack/plugin-auth` - an authentication and identity plugin for the ObjectStack ecosystem. The plugin now has the better-auth library integrated with a working AuthManager class and lazy initialization pattern.
|
|
6
|
-
|
|
7
|
-
## Latest Updates (Phase 1 & 2 Complete)
|
|
8
|
-
|
|
9
|
-
### Better-Auth Integration
|
|
10
|
-
- ✅ Added better-auth v1.4.18 as runtime dependency
|
|
11
|
-
- ✅ Created AuthManager class wrapping better-auth
|
|
12
|
-
- ✅ Implemented lazy initialization to avoid database errors
|
|
13
|
-
- ✅ Added TypeScript types for all authentication methods
|
|
14
|
-
- ✅ Updated plugin to use real AuthManager (not stub)
|
|
15
|
-
- ✅ All 11 tests passing with no errors
|
|
16
|
-
|
|
17
|
-
### Technical Improvements
|
|
18
|
-
- Better-auth instance created only when needed (lazy initialization)
|
|
19
|
-
- Proper TypeScript typing for HTTP request/response handlers
|
|
20
|
-
- Support for configuration-based initialization
|
|
21
|
-
- Extensible design for future features (OAuth, 2FA, etc.)
|
|
22
|
-
|
|
23
|
-
## What Was Implemented
|
|
24
|
-
|
|
25
|
-
### 1. Package Structure
|
|
26
|
-
- Created new workspace package at `packages/plugins/plugin-auth/`
|
|
27
|
-
- Configured package.json with proper dependencies
|
|
28
|
-
- Set up TypeScript configuration
|
|
29
|
-
- Created comprehensive README and CHANGELOG
|
|
30
|
-
|
|
31
|
-
### 2. Core Plugin Implementation
|
|
32
|
-
- **AuthPlugin class** - Full plugin lifecycle (init, start, destroy)
|
|
33
|
-
- **AuthManager class** - Real implementation with better-auth integration
|
|
34
|
-
- **Lazy initialization** - Better-auth instance created only when needed
|
|
35
|
-
- **Route registration** - HTTP endpoints for login, register, logout, session
|
|
36
|
-
- **Service registration** - Registers 'auth' service in ObjectKernel
|
|
37
|
-
- **Configuration support** - Uses AuthConfig schema from @objectstack/spec/system
|
|
38
|
-
- **TypeScript types** - Proper typing for IHttpRequest and IHttpResponse
|
|
39
|
-
|
|
40
|
-
### 3. Testing
|
|
41
|
-
- 11 comprehensive unit tests
|
|
42
|
-
- 100% test coverage of implemented functionality
|
|
43
|
-
- All tests passing (11/11)
|
|
44
|
-
- Proper mocking of dependencies
|
|
45
|
-
|
|
46
|
-
### 4. Documentation
|
|
47
|
-
- Detailed README with usage examples
|
|
48
|
-
- Implementation status clearly documented
|
|
49
|
-
- Configuration options explained
|
|
50
|
-
- Example usage file (examples/basic-usage.ts)
|
|
51
|
-
- Updated main README to list the new package
|
|
52
|
-
|
|
53
|
-
### 5. Build & Integration
|
|
54
|
-
- Package builds successfully with tsup
|
|
55
|
-
- Integrated into monorepo build system
|
|
56
|
-
- All dependencies resolved correctly
|
|
57
|
-
- No build or lint errors
|
|
58
|
-
|
|
59
|
-
## File Structure
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
packages/plugins/plugin-auth/
|
|
63
|
-
├── CHANGELOG.md
|
|
64
|
-
├── README.md
|
|
65
|
-
├── IMPLEMENTATION_SUMMARY.md
|
|
66
|
-
├── package.json
|
|
67
|
-
├── tsconfig.json
|
|
68
|
-
├── examples/
|
|
69
|
-
│ └── basic-usage.ts
|
|
70
|
-
├── src/
|
|
71
|
-
│ ├── index.ts
|
|
72
|
-
│ ├── auth-plugin.ts # Main plugin implementation
|
|
73
|
-
│ ├── auth-manager.ts # NEW: Better-auth wrapper class
|
|
74
|
-
│ └── auth-plugin.test.ts
|
|
75
|
-
└── dist/
|
|
76
|
-
└── [build outputs]
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Key Design Decisions
|
|
80
|
-
|
|
81
|
-
1. **Better-Auth Integration**: Integrated better-auth v1.4.18 as the core authentication library
|
|
82
|
-
2. **Lazy Initialization**: AuthManager creates better-auth instance only when needed to avoid database initialization errors
|
|
83
|
-
3. **Flexible Configuration**: Supports custom better-auth instances or automatic creation from config
|
|
84
|
-
4. **IHttpServer Integration**: Routes registered through ObjectStack's IHttpServer interface
|
|
85
|
-
5. **Configuration Protocol**: Uses existing AuthConfig schema from spec package
|
|
86
|
-
6. **Plugin Pattern**: Follows established ObjectStack plugin conventions
|
|
87
|
-
7. **TypeScript-First**: Full type safety with proper interface definitions
|
|
88
|
-
|
|
89
|
-
## API Routes Registered
|
|
90
|
-
|
|
91
|
-
- `POST /api/v1/auth/login` - User login (stub)
|
|
92
|
-
- `POST /api/v1/auth/register` - User registration (stub)
|
|
93
|
-
- `POST /api/v1/auth/logout` - User logout (stub)
|
|
94
|
-
- `GET /api/v1/auth/session` - Get current session (stub)
|
|
95
|
-
|
|
96
|
-
## Dependencies
|
|
97
|
-
|
|
98
|
-
### Runtime Dependencies
|
|
99
|
-
- `@objectstack/core` - Plugin system
|
|
100
|
-
- `@objectstack/spec` - Protocol schemas
|
|
101
|
-
- `better-auth` ^1.4.18 - Authentication library
|
|
102
|
-
|
|
103
|
-
### Peer Dependencies (Optional)
|
|
104
|
-
- `drizzle-orm` >=0.41.0 - For database persistence (optional)
|
|
105
|
-
|
|
106
|
-
### Dev Dependencies
|
|
107
|
-
- `@types/node` ^25.2.2
|
|
108
|
-
- `typescript` ^5.0.0
|
|
109
|
-
- `vitest` ^4.0.18
|
|
110
|
-
|
|
111
|
-
## Testing Results
|
|
112
|
-
|
|
113
|
-
```
|
|
114
|
-
✓ src/auth-plugin.test.ts (11 tests) 13ms
|
|
115
|
-
✓ Plugin Metadata (1)
|
|
116
|
-
✓ Initialization (4)
|
|
117
|
-
✓ Start Phase (3)
|
|
118
|
-
✓ Destroy Phase (1)
|
|
119
|
-
✓ Configuration Options (2)
|
|
120
|
-
|
|
121
|
-
Test Files 1 passed (1)
|
|
122
|
-
Tests 11 passed (11)
|
|
123
|
-
|
|
124
|
-
✅ All tests passing with no errors
|
|
125
|
-
✅ Better-auth integration working with lazy initialization
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
## Next Steps (Future Development)
|
|
129
|
-
|
|
130
|
-
1. **Phase 3: Complete API Integration**
|
|
131
|
-
- Wire up better-auth API methods to login/register/logout routes
|
|
132
|
-
- Implement proper session management
|
|
133
|
-
- Add request/response transformations
|
|
134
|
-
|
|
135
|
-
2. **Phase 4: Database Adapter**
|
|
136
|
-
- Implement drizzle-orm adapter
|
|
137
|
-
- Add database schema migrations
|
|
138
|
-
- Support multiple database providers (PostgreSQL, MySQL, SQLite)
|
|
139
|
-
|
|
140
|
-
3. **Phase 5: OAuth Providers**
|
|
141
|
-
- Google OAuth integration
|
|
142
|
-
- GitHub OAuth integration
|
|
143
|
-
- Generic OAuth provider support
|
|
144
|
-
- Provider configuration
|
|
145
|
-
|
|
146
|
-
4. **Phase 6: Advanced Features**
|
|
147
|
-
- Two-factor authentication (2FA)
|
|
148
|
-
- Passkey support
|
|
149
|
-
- Magic link authentication
|
|
150
|
-
- Organization/team management
|
|
151
|
-
|
|
152
|
-
5. **Phase 7: Security**
|
|
153
|
-
- Rate limiting
|
|
154
|
-
- CSRF protection
|
|
155
|
-
- Session security
|
|
156
|
-
- Audit logging
|
|
157
|
-
|
|
158
|
-
## Current Implementation Status
|
|
159
|
-
|
|
160
|
-
✅ **Phase 1 & 2: COMPLETE**
|
|
161
|
-
- Better-auth library successfully integrated
|
|
162
|
-
- AuthManager class implemented with lazy initialization
|
|
163
|
-
- All tests passing
|
|
164
|
-
- Build successful
|
|
165
|
-
- Ready for Phase 3 (API Integration)
|
|
166
|
-
|
|
167
|
-
🔄 **Phase 3: IN PROGRESS**
|
|
168
|
-
- Authentication method structures in place
|
|
169
|
-
- Placeholder responses implemented
|
|
170
|
-
- Need to connect actual better-auth API calls
|
|
171
|
-
## References
|
|
172
|
-
|
|
173
|
-
- Plugin implementation: `packages/plugins/plugin-auth/src/auth-plugin.ts`
|
|
174
|
-
- AuthManager implementation: `packages/plugins/plugin-auth/src/auth-manager.ts`
|
|
175
|
-
- Tests: `packages/plugins/plugin-auth/src/auth-plugin.test.ts`
|
|
176
|
-
- Schema: `packages/spec/src/system/auth-config.zod.ts`
|
|
177
|
-
- Example: `packages/plugins/plugin-auth/examples/basic-usage.ts`
|
|
178
|
-
- Better-auth docs: https://www.better-auth.com/
|
|
179
|
-
|
|
180
|
-
## Recent Commits
|
|
181
|
-
|
|
182
|
-
1. `135a5c6` - feat: add better-auth library integration to auth plugin
|
|
183
|
-
2. `c11398a` - Initial plan
|
|
184
|
-
3. `81dbb51` - docs: update implementation summary with planned features
|
|
185
|
-
|
|
186
|
-
---
|
|
187
|
-
|
|
188
|
-
**Status**: ✅ Better-Auth Integration Complete (Phase 1 & 2)
|
|
189
|
-
**Version**: 2.0.2
|
|
190
|
-
**Test Coverage**: 11/11 tests passing (100%)
|
|
191
|
-
**Build Status**: ✅ Passing
|
|
192
|
-
**Dependencies**: better-auth v1.4.18 integrated
|
package/examples/basic-usage.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Auth Plugin Usage Example
|
|
5
|
-
*
|
|
6
|
-
* This example demonstrates how to use the AuthPlugin with better-auth
|
|
7
|
-
* in an ObjectStack application. All requests are forwarded directly
|
|
8
|
-
* to better-auth's universal handler.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { ObjectKernel } from '@objectstack/core';
|
|
12
|
-
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
|
|
13
|
-
import { AuthPlugin } from '@objectstack/plugin-auth';
|
|
14
|
-
|
|
15
|
-
// Create kernel
|
|
16
|
-
const kernel = new ObjectKernel();
|
|
17
|
-
|
|
18
|
-
// Initialize the kernel
|
|
19
|
-
async function main() {
|
|
20
|
-
try {
|
|
21
|
-
// Register HTTP server plugin
|
|
22
|
-
await kernel.use(new HonoServerPlugin({
|
|
23
|
-
port: 3000,
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
// Register auth plugin
|
|
27
|
-
await kernel.use(new AuthPlugin({
|
|
28
|
-
secret: process.env.AUTH_SECRET || 'your-secret-key-at-least-32-chars',
|
|
29
|
-
baseUrl: process.env.BASE_URL || 'http://localhost:3000',
|
|
30
|
-
databaseUrl: process.env.DATABASE_URL,
|
|
31
|
-
|
|
32
|
-
// OAuth providers (optional)
|
|
33
|
-
providers: [
|
|
34
|
-
{
|
|
35
|
-
id: 'google',
|
|
36
|
-
clientId: process.env.GOOGLE_CLIENT_ID || '',
|
|
37
|
-
clientSecret: process.env.GOOGLE_CLIENT_SECRET || '',
|
|
38
|
-
scope: ['email', 'profile'],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
id: 'github',
|
|
42
|
-
clientId: process.env.GITHUB_CLIENT_ID || '',
|
|
43
|
-
clientSecret: process.env.GITHUB_CLIENT_SECRET || '',
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
|
|
47
|
-
// Additional auth features (optional)
|
|
48
|
-
plugins: {
|
|
49
|
-
organization: true, // Multi-tenant support
|
|
50
|
-
twoFactor: true, // 2FA support
|
|
51
|
-
passkeys: false, // Passkey support
|
|
52
|
-
magicLink: true, // Magic link login
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
// Session configuration (optional)
|
|
56
|
-
session: {
|
|
57
|
-
expiresIn: 60 * 60 * 24 * 7, // 7 days
|
|
58
|
-
updateAge: 60 * 60 * 24, // Update every 24 hours
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
// Route configuration
|
|
62
|
-
registerRoutes: true,
|
|
63
|
-
basePath: '/api/v1/auth',
|
|
64
|
-
}));
|
|
65
|
-
|
|
66
|
-
// Bootstrap the kernel
|
|
67
|
-
await kernel.bootstrap();
|
|
68
|
-
|
|
69
|
-
console.log('🚀 Server started with auth plugin');
|
|
70
|
-
console.log('📍 Better-auth endpoints available at:');
|
|
71
|
-
console.log('');
|
|
72
|
-
console.log(' Email/Password:');
|
|
73
|
-
console.log(' - POST http://localhost:3000/api/v1/auth/sign-up/email');
|
|
74
|
-
console.log(' - POST http://localhost:3000/api/v1/auth/sign-in/email');
|
|
75
|
-
console.log(' - POST http://localhost:3000/api/v1/auth/sign-out');
|
|
76
|
-
console.log(' - GET http://localhost:3000/api/v1/auth/get-session');
|
|
77
|
-
console.log('');
|
|
78
|
-
console.log(' Password Management:');
|
|
79
|
-
console.log(' - POST http://localhost:3000/api/v1/auth/forget-password');
|
|
80
|
-
console.log(' - POST http://localhost:3000/api/v1/auth/reset-password');
|
|
81
|
-
console.log('');
|
|
82
|
-
console.log(' OAuth (if configured):');
|
|
83
|
-
console.log(' - GET http://localhost:3000/api/v1/auth/authorize/google');
|
|
84
|
-
console.log(' - GET http://localhost:3000/api/v1/auth/authorize/github');
|
|
85
|
-
console.log('');
|
|
86
|
-
console.log(' See https://www.better-auth.com/docs for complete API reference');
|
|
87
|
-
console.log('');
|
|
88
|
-
|
|
89
|
-
// Access the auth service from the kernel
|
|
90
|
-
const authService = kernel.getService('auth');
|
|
91
|
-
console.log('✅ Auth service registered:', !!authService);
|
|
92
|
-
|
|
93
|
-
} catch (error) {
|
|
94
|
-
console.error('❌ Failed to start server:', error);
|
|
95
|
-
process.exit(1);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Handle graceful shutdown
|
|
100
|
-
process.on('SIGINT', async () => {
|
|
101
|
-
console.log('\n🛑 Shutting down...');
|
|
102
|
-
await kernel.shutdown();
|
|
103
|
-
process.exit(0);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
// Start the application
|
|
107
|
-
main();
|
package/objectstack.config.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
|
|
2
|
-
|
|
3
|
-
import { defineStack } from '@objectstack/spec';
|
|
4
|
-
import * as objects from './src/objects';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* ObjectStack Configuration for plugin-auth
|
|
8
|
-
*
|
|
9
|
-
* This configuration defines the authentication and identity kernel objects
|
|
10
|
-
* for the ObjectStack platform.
|
|
11
|
-
*/
|
|
12
|
-
export default defineStack({
|
|
13
|
-
manifest: {
|
|
14
|
-
id: 'com.objectstack.plugin-auth',
|
|
15
|
-
namespace: 'auth',
|
|
16
|
-
version: '3.0.1',
|
|
17
|
-
type: 'plugin',
|
|
18
|
-
name: 'Authentication & Identity Plugin',
|
|
19
|
-
description: 'Core authentication objects for ObjectStack (User, Session, Account, Verification)',
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
// Export all authentication kernel objects
|
|
23
|
-
objects: Object.values(objects),
|
|
24
|
-
});
|