Skip to content

Commit 4da00e6

Browse files
authored
Merge pull request #3 from objectstack-ai/copilot/develop-better-auth-plugin
2 parents 32edb2a + 4a39392 commit 4da00e6

File tree

16 files changed

+1560
-1
lines changed

16 files changed

+1560
-1
lines changed

.env.example

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Better-Auth Configuration
2+
# Required: Secret key for signing tokens (minimum 32 characters)
3+
BETTER_AUTH_SECRET=your-super-secret-key-change-this-in-production-min-32-chars
4+
5+
# Required: Base URL where your application is hosted
6+
BETTER_AUTH_URL=http://localhost:3000
7+
8+
# Optional: Node environment
9+
NODE_ENV=development
10+
11+
# Optional: Google OAuth (if using social auth)
12+
GOOGLE_CLIENT_ID=your-google-client-id
13+
GOOGLE_CLIENT_SECRET=your-google-client-secret
14+
15+
# Optional: GitHub OAuth (if using social auth)
16+
GITHUB_CLIENT_ID=your-github-client-id
17+
GITHUB_CLIENT_SECRET=your-github-client-secret
18+
19+
# Optional: Database connection (for ObjectQL)
20+
DATABASE_URL=postgresql://user:password@localhost:5432/dbname

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
dist
3+
*.log
4+
.DS_Store
5+
.env
6+
.env.local
7+
*.tsbuildinfo

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.0] - 2026-01-25
9+
10+
### Added
11+
- Initial release of @objectstack/plugin-auth
12+
- ObjectQL adapter for Better-Auth enabling storage-agnostic authentication
13+
- GraphQL schema definitions for User, Session, Account, and VerificationToken entities
14+
- Server-side Better-Auth initialization with RBAC integration
15+
- React hooks for client-side authentication (`useSession`, `usePermissions`, `useHasPermission`)
16+
- Plugin lifecycle hooks (onEnable, onDisable, onHealthCheck)
17+
- Type-safe session management with permission injection
18+
- Support for email/password authentication
19+
- Support for social authentication providers (Google, GitHub, etc.)
20+
- Comprehensive documentation and examples
21+
- TypeScript strict mode support
22+
- ESM module support
23+
24+
### Features
25+
- **Storage Agnostic**: Works with any ObjectQL-supported database (Postgres, Redis, Excel, etc.)
26+
- **Type Safe**: Full TypeScript support with type inference
27+
- **RBAC Ready**: Automatic permission injection from ObjectOS
28+
- **React Hooks**: Pre-built hooks for easy client integration
29+
- **Framework Agnostic**: Core plugin works with any JavaScript framework
30+
31+
[0.1.0]: https://github.com/objectstack-ai/plugin-auth/releases/tag/v0.1.0

CONTRIBUTING.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Contributing to @objectstack/plugin-auth
2+
3+
Thank you for your interest in contributing to the ObjectStack Auth Plugin! This document provides guidelines and instructions for contributing.
4+
5+
## Development Setup
6+
7+
1. **Clone the repository**
8+
```bash
9+
git clone https://github.com/objectstack-ai/plugin-auth.git
10+
cd plugin-auth
11+
```
12+
13+
2. **Install dependencies**
14+
```bash
15+
npm install
16+
```
17+
18+
3. **Build the project**
19+
```bash
20+
npm run build
21+
```
22+
23+
4. **Watch mode for development**
24+
```bash
25+
npm run dev
26+
```
27+
28+
## Project Structure
29+
30+
```
31+
src/
32+
├── adapter/ # ObjectQL adapter for Better-Auth
33+
├── schema/ # GraphQL schema definitions
34+
├── client/ # React hooks and client utilities
35+
├── server/ # Server-side initialization
36+
├── types.ts # TypeScript type definitions
37+
└── index.ts # Main plugin entry point
38+
```
39+
40+
## Architecture Principles
41+
42+
### 1. Storage Agnostic
43+
- **Never** use direct database calls (SQL, Prisma, Drizzle)
44+
- **Always** use ObjectQL for data operations
45+
- Pattern: `ql.entity('EntityName').operation()`
46+
47+
Example:
48+
```typescript
49+
// ❌ Bad
50+
await prisma.user.create({ ... });
51+
52+
// ✅ Good
53+
await ql.entity('User').create({ ... });
54+
```
55+
56+
### 2. Type Safety
57+
- Use TypeScript strict mode
58+
- Export all public types
59+
- Leverage Better-Auth's type inference
60+
61+
### 3. Framework Agnostic
62+
- Core plugin should work with any framework
63+
- Framework-specific code goes in separate exports
64+
- Example: React hooks in `client/hooks.ts`
65+
66+
### 4. RBAC Integration
67+
- Authentication (who you are) via Better-Auth
68+
- Authorization (what you can do) via ObjectOS
69+
- Inject permissions into session objects
70+
71+
## Coding Standards
72+
73+
### TypeScript
74+
- Use strict mode
75+
- Prefer interfaces over types for objects
76+
- Use explicit return types for public APIs
77+
- Document complex logic with comments
78+
79+
### Naming Conventions
80+
- PascalCase for types, interfaces, classes
81+
- camelCase for functions, variables
82+
- UPPER_CASE for constants
83+
- Prefix private methods with `_`
84+
85+
### File Organization
86+
- One export per file (with exceptions for related utilities)
87+
- Group related functionality
88+
- Keep files focused and under 300 lines
89+
90+
## Testing Guidelines
91+
92+
When adding tests (future work):
93+
- Test with multiple ObjectQL drivers (Postgres, Redis, etc.)
94+
- Test RBAC permission injection
95+
- Test session lifecycle
96+
- Test error handling
97+
98+
## Pull Request Process
99+
100+
1. **Create a feature branch**
101+
```bash
102+
git checkout -b feature/your-feature-name
103+
```
104+
105+
2. **Make your changes**
106+
- Follow coding standards
107+
- Add tests if applicable
108+
- Update documentation
109+
110+
3. **Verify your changes**
111+
```bash
112+
npm run typecheck
113+
npm run build
114+
```
115+
116+
4. **Commit with clear messages**
117+
```bash
118+
git commit -m "feat: add new feature"
119+
```
120+
121+
Follow [Conventional Commits](https://www.conventionalcommits.org/):
122+
- `feat:` New feature
123+
- `fix:` Bug fix
124+
- `docs:` Documentation changes
125+
- `refactor:` Code refactoring
126+
- `test:` Test additions/changes
127+
- `chore:` Maintenance tasks
128+
129+
5. **Push and create PR**
130+
```bash
131+
git push origin feature/your-feature-name
132+
```
133+
134+
## Common Tasks
135+
136+
### Adding a New Auth Provider
137+
138+
1. Update `AuthPluginConfig` in `src/index.ts`
139+
2. Add provider configuration to server setup
140+
3. Update documentation
141+
4. Add example to `example.config.ts`
142+
143+
### Extending the Schema
144+
145+
1. Update GraphQL schema in `src/schema/auth.gql`
146+
2. Update TypeScript types in `src/types.ts`
147+
3. Update adapter operations in `src/adapter/index.ts`
148+
4. Update documentation
149+
150+
### Adding Client Hooks
151+
152+
1. Add hook to `src/client/hooks.ts`
153+
2. Export from `src/index.ts`
154+
3. Add TypeScript types
155+
4. Document with JSDoc comments
156+
5. Add usage example to README
157+
158+
## Questions?
159+
160+
- Open an issue for bugs or feature requests
161+
- Start a discussion for questions or ideas
162+
- Tag maintainers for urgent issues
163+
164+
## License
165+
166+
By contributing, you agree that your contributions will be licensed under the MIT License.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 ObjectStack
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.

0 commit comments

Comments
 (0)