create-chaaskit 0.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/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +25 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/add-infra.d.ts +6 -0
- package/dist/commands/add-infra.d.ts.map +1 -0
- package/dist/commands/add-infra.js +160 -0
- package/dist/commands/add-infra.js.map +1 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +63 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/db-sync.d.ts +13 -0
- package/dist/commands/db-sync.d.ts.map +1 -0
- package/dist/commands/db-sync.js +108 -0
- package/dist/commands/db-sync.js.map +1 -0
- package/dist/commands/dev.d.ts +7 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +61 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/init.d.ts +9 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +214 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/.env.example +24 -0
- package/dist/templates/README.md +81 -0
- package/dist/templates/app/components/AcceptInviteClient.tsx +10 -0
- package/dist/templates/app/components/AdminDashboardClient.tsx +10 -0
- package/dist/templates/app/components/AdminTeamClient.tsx +10 -0
- package/dist/templates/app/components/AdminTeamsClient.tsx +10 -0
- package/dist/templates/app/components/AdminUsersClient.tsx +10 -0
- package/dist/templates/app/components/ApiKeysClient.tsx +10 -0
- package/dist/templates/app/components/AutomationsClient.tsx +10 -0
- package/dist/templates/app/components/ChatClient.tsx +13 -0
- package/dist/templates/app/components/ClientOnly.tsx +6 -0
- package/dist/templates/app/components/DocumentsClient.tsx +10 -0
- package/dist/templates/app/components/OAuthConsentClient.tsx +10 -0
- package/dist/templates/app/components/PricingClient.tsx +10 -0
- package/dist/templates/app/components/TeamSettingsClient.tsx +10 -0
- package/dist/templates/app/components/VerifyEmailClient.tsx +10 -0
- package/dist/templates/app/entry.client.tsx +12 -0
- package/dist/templates/app/entry.server.tsx +67 -0
- package/dist/templates/app/root.tsx +91 -0
- package/dist/templates/app/routes/_index.tsx +82 -0
- package/dist/templates/app/routes/admin._index.tsx +57 -0
- package/dist/templates/app/routes/admin.teams.$teamId.tsx +57 -0
- package/dist/templates/app/routes/admin.teams._index.tsx +57 -0
- package/dist/templates/app/routes/admin.users.tsx +57 -0
- package/dist/templates/app/routes/api-keys.tsx +57 -0
- package/dist/templates/app/routes/automations.tsx +57 -0
- package/dist/templates/app/routes/chat._index.tsx +11 -0
- package/dist/templates/app/routes/chat.admin._index.tsx +10 -0
- package/dist/templates/app/routes/chat.admin.teams.$teamId.tsx +10 -0
- package/dist/templates/app/routes/chat.admin.teams._index.tsx +10 -0
- package/dist/templates/app/routes/chat.admin.users.tsx +10 -0
- package/dist/templates/app/routes/chat.api-keys.tsx +10 -0
- package/dist/templates/app/routes/chat.automations.tsx +10 -0
- package/dist/templates/app/routes/chat.documents.tsx +10 -0
- package/dist/templates/app/routes/chat.team.$teamId.settings.tsx +10 -0
- package/dist/templates/app/routes/chat.thread.$threadId.tsx +11 -0
- package/dist/templates/app/routes/chat.tsx +39 -0
- package/dist/templates/app/routes/documents.tsx +57 -0
- package/dist/templates/app/routes/invite.$token.tsx +10 -0
- package/dist/templates/app/routes/login.tsx +334 -0
- package/dist/templates/app/routes/oauth.consent.tsx +10 -0
- package/dist/templates/app/routes/pricing.tsx +10 -0
- package/dist/templates/app/routes/privacy.tsx +197 -0
- package/dist/templates/app/routes/register.tsx +398 -0
- package/dist/templates/app/routes/shared.$shareId.tsx +226 -0
- package/dist/templates/app/routes/team.$teamId.settings.tsx +57 -0
- package/dist/templates/app/routes/terms.tsx +173 -0
- package/dist/templates/app/routes/thread.$threadId.tsx +102 -0
- package/dist/templates/app/routes/verify-email.tsx +10 -0
- package/dist/templates/app/routes.ts +47 -0
- package/dist/templates/config/app.config.ts +216 -0
- package/dist/templates/docs/admin.md +257 -0
- package/dist/templates/docs/api-keys.md +403 -0
- package/dist/templates/docs/authentication.md +247 -0
- package/dist/templates/docs/configuration.md +1212 -0
- package/dist/templates/docs/custom-pages.md +466 -0
- package/dist/templates/docs/deployment.md +362 -0
- package/dist/templates/docs/development.md +411 -0
- package/dist/templates/docs/documents.md +293 -0
- package/dist/templates/docs/extensions.md +639 -0
- package/dist/templates/docs/index.md +139 -0
- package/dist/templates/docs/installation.md +286 -0
- package/dist/templates/docs/mcp.md +952 -0
- package/dist/templates/docs/native-tools.md +688 -0
- package/dist/templates/docs/queue.md +514 -0
- package/dist/templates/docs/scheduled-prompts.md +279 -0
- package/dist/templates/docs/settings.md +415 -0
- package/dist/templates/docs/slack.md +318 -0
- package/dist/templates/docs/styling.md +288 -0
- package/dist/templates/extensions/agents/.gitkeep +0 -0
- package/dist/templates/extensions/pages/.gitkeep +0 -0
- package/dist/templates/extensions/payment-plans/.gitkeep +0 -0
- package/dist/templates/index.html +16 -0
- package/dist/templates/infra-aws/.github/workflows/deploy.yml +95 -0
- package/dist/templates/infra-aws/README.md +207 -0
- package/dist/templates/infra-aws/bin/cdk.ts +18 -0
- package/dist/templates/infra-aws/cdk.json +43 -0
- package/dist/templates/infra-aws/config/deployment.ts +156 -0
- package/dist/templates/infra-aws/lib/chaaskit-stack.ts +419 -0
- package/dist/templates/infra-aws/package.json +27 -0
- package/dist/templates/infra-aws/scripts/build-app.sh +63 -0
- package/dist/templates/infra-aws/tsconfig.json +25 -0
- package/dist/templates/package.json +46 -0
- package/dist/templates/prisma/schema/base.prisma +584 -0
- package/dist/templates/prisma/schema/custom.prisma +24 -0
- package/dist/templates/prisma/schema.prisma +271 -0
- package/dist/templates/public/favicon.svg +4 -0
- package/dist/templates/public/logo.svg +4 -0
- package/dist/templates/react-router.config.ts +11 -0
- package/dist/templates/server.js +52 -0
- package/dist/templates/src/main.tsx +8 -0
- package/dist/templates/tsconfig.json +26 -0
- package/dist/templates/vite.config.ts +26 -0
- package/package.json +46 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Authentication
|
|
2
|
+
|
|
3
|
+
The ChaasKit Template supports multiple authentication methods including email/password, OAuth providers, and magic links.
|
|
4
|
+
|
|
5
|
+
## Configuration
|
|
6
|
+
|
|
7
|
+
Configure authentication in `config/app.config.ts`:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
auth: {
|
|
11
|
+
methods: ['email-password', 'google', 'github', 'magic-link'],
|
|
12
|
+
allowUnauthenticated: false,
|
|
13
|
+
magicLink: {
|
|
14
|
+
enabled: true,
|
|
15
|
+
expiresInMinutes: 15,
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Available Methods
|
|
21
|
+
|
|
22
|
+
### Email/Password
|
|
23
|
+
|
|
24
|
+
Built-in email and password authentication with bcrypt hashing.
|
|
25
|
+
|
|
26
|
+
**Configuration:**
|
|
27
|
+
```typescript
|
|
28
|
+
auth: {
|
|
29
|
+
methods: ['email-password'],
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Endpoints:**
|
|
34
|
+
- `POST /api/auth/register` - Create account
|
|
35
|
+
- `POST /api/auth/login` - Log in
|
|
36
|
+
- `POST /api/auth/logout` - Log out
|
|
37
|
+
|
|
38
|
+
### Google OAuth
|
|
39
|
+
|
|
40
|
+
**Setup:**
|
|
41
|
+
|
|
42
|
+
1. Create a project at [console.cloud.google.com](https://console.cloud.google.com)
|
|
43
|
+
2. Enable the Google+ API
|
|
44
|
+
3. Create OAuth 2.0 credentials
|
|
45
|
+
4. Add authorized redirect URI: `{API_URL}/api/auth/google/callback`
|
|
46
|
+
|
|
47
|
+
**Environment:**
|
|
48
|
+
```bash
|
|
49
|
+
GOOGLE_CLIENT_ID="your-client-id"
|
|
50
|
+
GOOGLE_CLIENT_SECRET="your-client-secret"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Configuration:**
|
|
54
|
+
```typescript
|
|
55
|
+
auth: {
|
|
56
|
+
methods: ['google'],
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### GitHub OAuth
|
|
61
|
+
|
|
62
|
+
**Setup:**
|
|
63
|
+
|
|
64
|
+
1. Go to GitHub Settings > Developer settings > OAuth Apps
|
|
65
|
+
2. Create a new OAuth App
|
|
66
|
+
3. Set Authorization callback URL: `{API_URL}/api/auth/github/callback`
|
|
67
|
+
|
|
68
|
+
**Environment:**
|
|
69
|
+
```bash
|
|
70
|
+
GITHUB_CLIENT_ID="your-client-id"
|
|
71
|
+
GITHUB_CLIENT_SECRET="your-client-secret"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Configuration:**
|
|
75
|
+
```typescript
|
|
76
|
+
auth: {
|
|
77
|
+
methods: ['github'],
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Magic Links
|
|
82
|
+
|
|
83
|
+
Passwordless authentication via email links.
|
|
84
|
+
|
|
85
|
+
**Configuration:**
|
|
86
|
+
```typescript
|
|
87
|
+
auth: {
|
|
88
|
+
methods: ['magic-link'],
|
|
89
|
+
magicLink: {
|
|
90
|
+
enabled: true,
|
|
91
|
+
expiresInMinutes: 15,
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Note:** Requires email service configuration (not included by default).
|
|
97
|
+
|
|
98
|
+
## Anonymous Users
|
|
99
|
+
|
|
100
|
+
Allow users to chat without authentication:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
auth: {
|
|
104
|
+
allowUnauthenticated: true,
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Anonymous users:
|
|
109
|
+
- Can create threads and send messages
|
|
110
|
+
- Cannot access saved threads after session ends
|
|
111
|
+
- No access to premium features
|
|
112
|
+
|
|
113
|
+
## JWT Tokens
|
|
114
|
+
|
|
115
|
+
Authentication uses JWT tokens stored in HTTP-only cookies.
|
|
116
|
+
|
|
117
|
+
**Token Structure:**
|
|
118
|
+
```typescript
|
|
119
|
+
{
|
|
120
|
+
sub: userId,
|
|
121
|
+
email: userEmail,
|
|
122
|
+
iat: issuedAt,
|
|
123
|
+
exp: expiresAt,
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Cookie Settings:**
|
|
128
|
+
- `httpOnly: true` - Not accessible via JavaScript
|
|
129
|
+
- `secure: true` - HTTPS only in production
|
|
130
|
+
- `sameSite: 'lax'` - CSRF protection
|
|
131
|
+
|
|
132
|
+
## Protected Routes
|
|
133
|
+
|
|
134
|
+
### Backend
|
|
135
|
+
|
|
136
|
+
Use middleware to protect routes:
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
import { requireAuth, optionalAuth } from '../middleware/auth.js';
|
|
140
|
+
|
|
141
|
+
// Requires authentication
|
|
142
|
+
router.get('/private', requireAuth, async (req, res) => {
|
|
143
|
+
// req.user is guaranteed to exist
|
|
144
|
+
res.json({ userId: req.user.id });
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Optional authentication
|
|
148
|
+
router.get('/public', optionalAuth, async (req, res) => {
|
|
149
|
+
// req.user may or may not exist
|
|
150
|
+
if (req.user) {
|
|
151
|
+
res.json({ message: 'Hello, ' + req.user.email });
|
|
152
|
+
} else {
|
|
153
|
+
res.json({ message: 'Hello, anonymous' });
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Frontend
|
|
159
|
+
|
|
160
|
+
Use the AuthContext:
|
|
161
|
+
|
|
162
|
+
```tsx
|
|
163
|
+
import { useAuth } from '../contexts/AuthContext';
|
|
164
|
+
|
|
165
|
+
function MyComponent() {
|
|
166
|
+
const { user, isAuthenticated, login, logout } = useAuth();
|
|
167
|
+
|
|
168
|
+
if (!isAuthenticated) {
|
|
169
|
+
return <Navigate to="/login" />;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return <div>Hello, {user.email}</div>;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## User Model
|
|
177
|
+
|
|
178
|
+
```prisma
|
|
179
|
+
model User {
|
|
180
|
+
id String @id @default(cuid())
|
|
181
|
+
email String @unique
|
|
182
|
+
passwordHash String?
|
|
183
|
+
name String?
|
|
184
|
+
avatarUrl String?
|
|
185
|
+
|
|
186
|
+
// OAuth
|
|
187
|
+
oauthProvider String?
|
|
188
|
+
oauthId String?
|
|
189
|
+
|
|
190
|
+
// Subscription
|
|
191
|
+
plan String @default("free")
|
|
192
|
+
|
|
193
|
+
// Settings
|
|
194
|
+
settings Json @default("{}")
|
|
195
|
+
|
|
196
|
+
createdAt DateTime @default(now())
|
|
197
|
+
updatedAt DateTime @updatedAt
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Security Considerations
|
|
202
|
+
|
|
203
|
+
1. **Password Hashing**: bcrypt with automatic salt
|
|
204
|
+
2. **JWT Secrets**: Use 32+ character random strings
|
|
205
|
+
3. **HTTPS**: Required in production
|
|
206
|
+
4. **CSRF Protection**: SameSite cookies
|
|
207
|
+
5. **Rate Limiting**: Built-in via express-rate-limit
|
|
208
|
+
|
|
209
|
+
## Customization
|
|
210
|
+
|
|
211
|
+
### Add a New OAuth Provider
|
|
212
|
+
|
|
213
|
+
1. Install Passport strategy:
|
|
214
|
+
```bash
|
|
215
|
+
pnpm add passport-twitter -F @chaaskit/server
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
2. Add route in `packages/server/src/api/auth.ts`
|
|
219
|
+
|
|
220
|
+
3. Configure strategy in passport setup
|
|
221
|
+
|
|
222
|
+
4. Add to config:
|
|
223
|
+
```typescript
|
|
224
|
+
auth: {
|
|
225
|
+
methods: ['twitter'],
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Custom Auth Provider
|
|
230
|
+
|
|
231
|
+
Implement using the registry pattern:
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
// extensions/auth-providers/my-provider.ts
|
|
235
|
+
import { BaseAuthProvider } from '@chaaskit/server';
|
|
236
|
+
|
|
237
|
+
export class MyAuthProvider extends BaseAuthProvider {
|
|
238
|
+
async authenticate(credentials) {
|
|
239
|
+
// Custom auth logic
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Register:
|
|
245
|
+
```typescript
|
|
246
|
+
registry.register('auth-provider', 'my-provider', MyAuthProvider);
|
|
247
|
+
```
|