@invect/user-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/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/backend/index.cjs +1166 -0
- package/dist/backend/index.cjs.map +1 -0
- package/dist/backend/index.d.ts +42 -0
- package/dist/backend/index.d.ts.map +1 -0
- package/dist/backend/index.mjs +1164 -0
- package/dist/backend/index.mjs.map +1 -0
- package/dist/backend/plugin.d.ts +62 -0
- package/dist/backend/plugin.d.ts.map +1 -0
- package/dist/backend/types.d.ts +299 -0
- package/dist/backend/types.d.ts.map +1 -0
- package/dist/frontend/components/AuthGate.d.ts +17 -0
- package/dist/frontend/components/AuthGate.d.ts.map +1 -0
- package/dist/frontend/components/AuthenticatedInvect.d.ts +129 -0
- package/dist/frontend/components/AuthenticatedInvect.d.ts.map +1 -0
- package/dist/frontend/components/ProfilePage.d.ts +10 -0
- package/dist/frontend/components/ProfilePage.d.ts.map +1 -0
- package/dist/frontend/components/SidebarUserMenu.d.ts +12 -0
- package/dist/frontend/components/SidebarUserMenu.d.ts.map +1 -0
- package/dist/frontend/components/SignInForm.d.ts +14 -0
- package/dist/frontend/components/SignInForm.d.ts.map +1 -0
- package/dist/frontend/components/SignInPage.d.ts +19 -0
- package/dist/frontend/components/SignInPage.d.ts.map +1 -0
- package/dist/frontend/components/UserButton.d.ts +15 -0
- package/dist/frontend/components/UserButton.d.ts.map +1 -0
- package/dist/frontend/components/UserManagement.d.ts +19 -0
- package/dist/frontend/components/UserManagement.d.ts.map +1 -0
- package/dist/frontend/components/UserManagementPage.d.ts +9 -0
- package/dist/frontend/components/UserManagementPage.d.ts.map +1 -0
- package/dist/frontend/index.cjs +1262 -0
- package/dist/frontend/index.cjs.map +1 -0
- package/dist/frontend/index.d.ts +29 -0
- package/dist/frontend/index.d.ts.map +1 -0
- package/dist/frontend/index.mjs +1250 -0
- package/dist/frontend/index.mjs.map +1 -0
- package/dist/frontend/plugins/authFrontendPlugin.d.ts +14 -0
- package/dist/frontend/plugins/authFrontendPlugin.d.ts.map +1 -0
- package/dist/frontend/providers/AuthProvider.d.ts +46 -0
- package/dist/frontend/providers/AuthProvider.d.ts.map +1 -0
- package/dist/roles-BOY5N82v.cjs +74 -0
- package/dist/roles-BOY5N82v.cjs.map +1 -0
- package/dist/roles-CZuKFEpJ.mjs +33 -0
- package/dist/roles-CZuKFEpJ.mjs.map +1 -0
- package/dist/shared/roles.d.ts +11 -0
- package/dist/shared/roles.d.ts.map +1 -0
- package/dist/shared/types.cjs +0 -0
- package/dist/shared/types.d.ts +46 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.mjs +1 -0
- package/package.json +116 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 @robase
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# @invect/user-auth
|
|
2
|
+
|
|
3
|
+
Better Auth integration for [Invect](https://github.com/invect/invect). Adds user authentication, session management, identity resolution, and auth UI components.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @invect/user-auth better-auth
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Backend
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { betterAuth } from 'better-auth';
|
|
17
|
+
import { betterAuthPlugin } from '@invect/user-auth';
|
|
18
|
+
import { createInvectRouter } from '@invect/express';
|
|
19
|
+
|
|
20
|
+
// 1. Configure better-auth
|
|
21
|
+
const auth = betterAuth({
|
|
22
|
+
database: { url: 'file:./auth.db', type: 'sqlite' },
|
|
23
|
+
emailAndPassword: { enabled: true },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// 2. Add the plugin
|
|
27
|
+
app.use('/invect', createInvectRouter({
|
|
28
|
+
databaseUrl: 'file:./dev.db',
|
|
29
|
+
plugins: [
|
|
30
|
+
betterAuthPlugin({
|
|
31
|
+
auth,
|
|
32
|
+
globalAdmins: [
|
|
33
|
+
{
|
|
34
|
+
email: process.env.INVECT_ADMIN_EMAIL,
|
|
35
|
+
pw: process.env.INVECT_ADMIN_PASSWORD,
|
|
36
|
+
name: 'Admin',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
}));
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`globalAdmins` is the explicit source of truth for seeded admin accounts. If you
|
|
45
|
+
want to use environment variables, wire them into that array yourself.
|
|
46
|
+
|
|
47
|
+
### Frontend
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { AuthProvider, useAuth, SignInForm, UserButton, AuthGate } from '@invect/user-auth/ui';
|
|
51
|
+
|
|
52
|
+
function App() {
|
|
53
|
+
return (
|
|
54
|
+
<AuthProvider baseUrl="http://localhost:3000/invect">
|
|
55
|
+
<AuthGate fallback={<SignInPage />}>
|
|
56
|
+
<Header />
|
|
57
|
+
<MainApp />
|
|
58
|
+
</AuthGate>
|
|
59
|
+
</AuthProvider>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function Header() {
|
|
64
|
+
return (
|
|
65
|
+
<header>
|
|
66
|
+
<UserButton />
|
|
67
|
+
</header>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function SignInPage() {
|
|
72
|
+
return <SignInForm onSuccess={() => window.location.reload()} />;
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Package Exports
|
|
77
|
+
|
|
78
|
+
| Entry Point | Import | Content |
|
|
79
|
+
|-------------|--------|---------|
|
|
80
|
+
| `@invect/user-auth` | `import { betterAuthPlugin } from '@invect/user-auth'` | Backend plugin (Node.js) |
|
|
81
|
+
| `@invect/user-auth/ui` | `import { AuthProvider, useAuth } from '@invect/user-auth/ui'` | Frontend components (Browser) |
|
|
82
|
+
| `@invect/user-auth/types` | `import type { AuthUser } from '@invect/user-auth/types'` | Shared types |
|
|
83
|
+
|
|
84
|
+
## What It Does
|
|
85
|
+
|
|
86
|
+
### Backend (`@invect/user-auth`)
|
|
87
|
+
- **Proxies auth routes** — Sign-in, sign-up, OAuth, session endpoints at `/plugins/auth/*`
|
|
88
|
+
- **Resolves sessions** — Every Invect API request calls `auth.api.getSession()` to populate `InvectIdentity`
|
|
89
|
+
- **Maps roles** — better-auth user roles align with Invect RBAC (`owner`, `editor`, `operator`, `viewer`), preserve `admin`, and fall back to `default` for no global access
|
|
90
|
+
- **Middleware helper** — `createSessionResolver()` for use as `auth.resolveUser` callback
|
|
91
|
+
|
|
92
|
+
### Frontend (`@invect/user-auth/ui`)
|
|
93
|
+
- **AuthProvider** — Context provider that fetches session state and provides sign-in/sign-up/sign-out actions
|
|
94
|
+
- **useAuth()** — Hook for accessing current user, auth state, and actions
|
|
95
|
+
- **SignInForm** — Email/password sign-in form
|
|
96
|
+
- **SignUpForm** — Email/password sign-up form
|
|
97
|
+
- **UserButton** — User avatar with dropdown (name, email, role, sign-out)
|
|
98
|
+
- **AuthGate** — Conditionally renders children based on auth state
|
|
99
|
+
|
|
100
|
+
## Docs
|
|
101
|
+
|
|
102
|
+
Full documentation: [invect.dev/docs/authentication](https://invect.dev/docs/authentication)
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT
|