@mastra/auth-better-auth 1.1.5-alpha.0 → 1.1.5-alpha.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/README.md +16 -74
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
# @mastra/auth-better-auth
|
|
2
2
|
|
|
3
|
-
Better Auth
|
|
3
|
+
`@mastra/auth-better-auth` connects a Better Auth instance to Mastra's server authentication layer. Use it when you want a self-hosted, TypeScript-first authentication system that you control instead of relying on a hosted identity provider.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @mastra/auth-better-auth
|
|
8
|
+
npm install @mastra/auth-better-auth
|
|
9
|
+
npm install better-auth
|
|
9
10
|
```
|
|
10
11
|
|
|
11
12
|
## Usage
|
|
12
13
|
|
|
14
|
+
Create a Better Auth instance with your database configuration, then register its Mastra adapter under `server.auth`.
|
|
15
|
+
|
|
13
16
|
```typescript
|
|
14
|
-
import { betterAuth } from 'better-auth';
|
|
15
17
|
import { MastraAuthBetterAuth } from '@mastra/auth-better-auth';
|
|
16
|
-
import { Mastra } from '@mastra/core';
|
|
18
|
+
import { Mastra } from '@mastra/core/mastra';
|
|
19
|
+
import { betterAuth } from 'better-auth';
|
|
17
20
|
|
|
18
|
-
// Create your Better Auth instance
|
|
19
21
|
const auth = betterAuth({
|
|
20
22
|
database: {
|
|
21
23
|
provider: 'postgresql',
|
|
@@ -26,82 +28,22 @@ const auth = betterAuth({
|
|
|
26
28
|
},
|
|
27
29
|
});
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
const mastraAuth = new MastraAuthBetterAuth({
|
|
31
|
-
auth,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Use with Mastra
|
|
35
|
-
const mastra = new Mastra({
|
|
31
|
+
export const mastra = new Mastra({
|
|
36
32
|
server: {
|
|
37
|
-
auth:
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Configuration Options
|
|
43
|
-
|
|
44
|
-
| Option | Type | Required | Description |
|
|
45
|
-
| --------------- | ------------------------------------- | -------- | ------------------------------------------------------------ |
|
|
46
|
-
| `auth` | `Auth` | Yes | Your Better Auth instance created via `betterAuth({ ... })` |
|
|
47
|
-
| `name` | `string` | No | Custom name for the auth provider (default: `'better-auth'`) |
|
|
48
|
-
| `authorizeUser` | `(user, request) => Promise<boolean>` | No | Custom authorization logic |
|
|
49
|
-
| `public` | `string[]` | No | Public routes that don't require authentication |
|
|
50
|
-
| `protected` | `string[]` | No | Protected routes that require authentication |
|
|
51
|
-
|
|
52
|
-
## Custom Authorization
|
|
53
|
-
|
|
54
|
-
You can provide custom authorization logic:
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
const mastraAuth = new MastraAuthBetterAuth({
|
|
58
|
-
auth,
|
|
59
|
-
async authorizeUser(user) {
|
|
60
|
-
// Only allow verified emails
|
|
61
|
-
return user?.user?.emailVerified === true;
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Role-Based Access Control
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
const mastraAuth = new MastraAuthBetterAuth({
|
|
70
|
-
auth,
|
|
71
|
-
async authorizeUser(user) {
|
|
72
|
-
// Check for admin role (assuming you have a role field)
|
|
73
|
-
const userWithRole = user?.user as any;
|
|
74
|
-
return userWithRole?.role === 'admin';
|
|
33
|
+
auth: new MastraAuthBetterAuth({ auth }),
|
|
75
34
|
},
|
|
76
35
|
});
|
|
77
36
|
```
|
|
78
37
|
|
|
79
|
-
##
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
const mastraAuth = new MastraAuthBetterAuth({
|
|
83
|
-
auth,
|
|
84
|
-
public: ['/health', '/api/status'],
|
|
85
|
-
protected: ['/api/*', '/admin/*'],
|
|
86
|
-
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## Why Better Auth?
|
|
90
|
-
|
|
91
|
-
Better Auth is a self-hosted, open-source authentication framework that gives you:
|
|
38
|
+
## Documentation
|
|
92
39
|
|
|
93
|
-
-
|
|
94
|
-
-
|
|
95
|
-
- **Flexible** - works with various databases and providers
|
|
96
|
-
- **TypeScript-first** - full type safety
|
|
97
|
-
- **Plugin system** - extend with OAuth, 2FA, organizations, etc.
|
|
40
|
+
- [Better Auth integration guide](https://mastra.ai/integrations/auth/better-auth)
|
|
41
|
+
- [Better Auth provider reference](https://mastra.ai/reference/auth/better-auth)
|
|
98
42
|
|
|
99
|
-
##
|
|
43
|
+
## Changelog
|
|
100
44
|
|
|
101
|
-
|
|
102
|
-
- [Mastra Documentation](https://mastra.ai/docs)
|
|
103
|
-
- [GitHub Repository](https://github.com/mastra-ai/mastra)
|
|
45
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/auth/better-auth/CHANGELOG.md) for version history and release notes.
|
|
104
46
|
|
|
105
|
-
##
|
|
47
|
+
## Support
|
|
106
48
|
|
|
107
|
-
|
|
49
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/auth-better-auth",
|
|
3
|
-
"version": "1.1.5-alpha.
|
|
3
|
+
"version": "1.1.5-alpha.1",
|
|
4
4
|
"description": "Mastra Better Auth integration - self-hosted authentication",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"tsdown": "0.22.9",
|
|
35
35
|
"typescript": "^7.0.2",
|
|
36
36
|
"vitest": "4.1.10",
|
|
37
|
-
"@internal/lint": "0.0.129",
|
|
38
37
|
"@internal/auth": "0.0.19",
|
|
39
|
-
"@internal/types-builder": "0.0.104"
|
|
38
|
+
"@internal/types-builder": "0.0.104",
|
|
39
|
+
"@internal/lint": "0.0.129"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
42
42
|
"dist"
|