cauthy-auth 0.5.1 → 0.8.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 +68 -3
- package/dist/{cauthy-BCTCqubt.d.ts → cauthy-Bn3iv50y.d.ts} +1 -1
- package/dist/{cauthy-hswMoS7B.d.mts → cauthy-C29HCvag.d.mts} +1 -1
- package/dist/cli.js +492 -25
- package/dist/client.d.mts +236 -0
- package/dist/client.d.ts +236 -0
- package/dist/client.js +331 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +297 -0
- package/dist/client.mjs.map +1 -0
- package/dist/express.d.mts +24 -0
- package/dist/express.d.ts +24 -0
- package/dist/express.js +102 -0
- package/dist/express.js.map +1 -0
- package/dist/express.mjs +76 -0
- package/dist/express.mjs.map +1 -0
- package/dist/fastify.d.mts +2 -2
- package/dist/fastify.d.ts +2 -2
- package/dist/fastify.js +3 -1
- package/dist/fastify.js.map +1 -1
- package/dist/fastify.mjs +3 -1
- package/dist/fastify.mjs.map +1 -1
- package/dist/hono.d.mts +23 -0
- package/dist/hono.d.ts +23 -0
- package/dist/hono.js +50 -0
- package/dist/hono.js.map +1 -0
- package/dist/hono.mjs +24 -0
- package/dist/hono.mjs.map +1 -0
- package/dist/index.d.mts +44 -6
- package/dist/index.d.ts +44 -6
- package/dist/index.js +672 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +660 -37
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +24 -0
- package/dist/next.d.ts +24 -0
- package/dist/next.js +77 -0
- package/dist/next.js.map +1 -0
- package/dist/next.mjs +52 -0
- package/dist/next.mjs.map +1 -0
- package/dist/react.d.mts +546 -7
- package/dist/react.d.ts +546 -7
- package/dist/react.js +925 -14
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +913 -10
- package/dist/react.mjs.map +1 -1
- package/dist/styles.css +271 -0
- package/dist/svelte.d.mts +26 -0
- package/dist/svelte.d.ts +26 -0
- package/dist/svelte.js +402 -0
- package/dist/svelte.js.map +1 -0
- package/dist/svelte.mjs +373 -0
- package/dist/svelte.mjs.map +1 -0
- package/dist/{system-DvcQjORr.d.ts → system-DhRr_WxR.d.ts} +139 -1
- package/dist/{system-CR8p4BjB.d.mts → system-ZD_Wa8Bm.d.mts} +139 -1
- package/dist/theme.d.mts +59 -1
- package/dist/theme.d.ts +59 -1
- package/dist/theme.js +185 -5
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +180 -4
- package/dist/theme.mjs.map +1 -1
- package/dist/validate-B_iC-4y8.d.mts +19 -0
- package/dist/validate-B_iC-4y8.d.ts +19 -0
- package/dist/vue.d.mts +28 -0
- package/dist/vue.d.ts +28 -0
- package/dist/vue.js +420 -0
- package/dist/vue.js.map +1 -0
- package/dist/vue.mjs +391 -0
- package/dist/vue.mjs.map +1 -0
- package/package.json +68 -7
- package/dist/permissions-B-a3eN0h.d.mts +0 -52
- package/dist/permissions-B-a3eN0h.d.ts +0 -52
package/README.md
CHANGED
|
@@ -36,14 +36,71 @@ import { CauthyProvider, useSession } from 'cauthy-auth/react'
|
|
|
36
36
|
const { session, signIn, signOut } = useSession()
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
Prefer your own sign-in page to Cauthy's? Set `CAUTHY_TENANT` and draw it, with the ready-made forms or the functions under them. The browser still holds no token:
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
```tsx
|
|
42
|
+
import { SignIn, useAuth } from 'cauthy-auth/react'
|
|
43
|
+
|
|
44
|
+
<SignIn locale="es" links={{ signUp: '/registro', forgotPassword: '/olvide' }} />
|
|
45
|
+
|
|
46
|
+
const { signIn } = useAuth()
|
|
47
|
+
const r = await signIn.email({ email, password }) // r.ok, r.status, r.error.field
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
What Cauthy mails opens your pages too: a new password, a confirmed address, a sign-in link.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
export const auth = createCauthy({ pages: { signIn: '/sign-in', resetPassword: '/new-password', verifyEmail: '/confirm' } })
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { ResetPassword, VerifyEmail } from 'cauthy-auth/react'
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
And the person's account, in your application: name, password, second step, sessions.
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { Account } from 'cauthy-auth/react'
|
|
64
|
+
<Account /> // or: const { account } = useAuth()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Roles and permissions with their names, from the catalog Cauthy has:
|
|
42
68
|
|
|
43
69
|
```bash
|
|
44
|
-
npx cauthy-auth
|
|
70
|
+
npx cauthy-auth policy --pull --out src/policy.ts
|
|
45
71
|
```
|
|
46
72
|
|
|
73
|
+
```ts
|
|
74
|
+
import { can, hasRole } from './policy'
|
|
75
|
+
can(organization, 'ledger:write') // only what the catalog names compiles
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Each framework has its own few lines:
|
|
79
|
+
|
|
80
|
+
| | |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| Next.js | `cauthyNext(auth)` from `cauthy-auth/next`: `{ GET, POST }`, `session()`, `middleware()` |
|
|
83
|
+
| Express | `app.use(cauthyExpress(auth))` from `cauthy-auth/express`: `req.cauthy()`, `requireSession` |
|
|
84
|
+
| Hono | `app.use(cauthyHono(auth))` from `cauthy-auth/hono`: `c.get('session')`, `requireSession` |
|
|
85
|
+
| Fastify | `app.register(cauthyFastify, { auth })` from `cauthy-auth/fastify`: `req.cauthy()`, `app.requireSession` |
|
|
86
|
+
| Anything else | `auth.handler(request)` takes a `Request` and answers a `Response` |
|
|
87
|
+
|
|
88
|
+
In the browser, beside React:
|
|
89
|
+
|
|
90
|
+
| | |
|
|
91
|
+
| --- | --- |
|
|
92
|
+
| Vue | `app.use(createCauthyVue())`, then `useSession()` and `useAuth()` from `cauthy-auth/vue` |
|
|
93
|
+
| Svelte | `createCauthySession()` from `cauthy-auth/svelte`: `$session`, `$status`, `auth` |
|
|
94
|
+
| Anything else | `createSessionStore()` from `cauthy-auth/client` |
|
|
95
|
+
|
|
96
|
+
The ready-made forms wear the look set for your application in Cauthy's dashboard (colours, corners, typeface), the same as Cauthy's own sign-in page, with one import:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import 'cauthy-auth/styles.css'
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Or draw them with your own `components` and `classNames`, and pass `unstyled`. The dashboard can start the look from your stylesheet (shadcn/ui and Tailwind, Stackmyth, or variables of your own); `npx cauthy-auth theme --css src/app/globals.css` reads it the same way from a terminal.
|
|
103
|
+
|
|
47
104
|
Connect your application to Cauthy in one step, from Cauthy's dashboard ("Connect a System") or from a terminal. It makes the client, registers `https://<your app>/api/auth/callback`, and prints every variable to set, `CAUTHY_SECRET` included:
|
|
48
105
|
|
|
49
106
|
```bash
|
|
@@ -57,6 +114,14 @@ const org = await auth.system.organizations.create({ name: 'Acme' })
|
|
|
57
114
|
await auth.system.members.add(org.id, { role: 'owner', email: 'ana@acme.com' })
|
|
58
115
|
```
|
|
59
116
|
|
|
117
|
+
A backend that is handed a Cauthy access token checks it with Cauthy's published keys: no secret, no call per request.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { verifyToken } from 'cauthy-auth'
|
|
121
|
+
const who = await verifyToken(request) // throws CauthyTokenError: answer 401
|
|
122
|
+
who.userId, who.tenantId, who.roles
|
|
123
|
+
```
|
|
124
|
+
|
|
60
125
|
The full guide is in Cauthy's documentation, under "Auth SDK".
|
|
61
126
|
|
|
62
127
|
## License
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { J as JsonValue, S as Session,
|
|
1
|
+
import { J as JsonValue, S as Session, l as SessionStatus, k as SessionOrganization, c as CauthySystem, i as PublicSession, b as CauthyOptions } from './system-DhRr_WxR.js';
|
|
2
2
|
import { JWTVerifyGetKey } from 'jose';
|
|
3
3
|
|
|
4
4
|
/** Something that happened in Cauthy, as a subscriber is told. Moments are UTC. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { J as JsonValue, S as Session,
|
|
1
|
+
import { J as JsonValue, S as Session, l as SessionStatus, k as SessionOrganization, c as CauthySystem, i as PublicSession, b as CauthyOptions } from './system-ZD_Wa8Bm.mjs';
|
|
2
2
|
import { JWTVerifyGetKey } from 'jose';
|
|
3
3
|
|
|
4
4
|
/** Something that happened in Cauthy, as a subscriber is told. Moments are UTC. */
|