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.
Files changed (72) hide show
  1. package/README.md +68 -3
  2. package/dist/{cauthy-BCTCqubt.d.ts → cauthy-Bn3iv50y.d.ts} +1 -1
  3. package/dist/{cauthy-hswMoS7B.d.mts → cauthy-C29HCvag.d.mts} +1 -1
  4. package/dist/cli.js +492 -25
  5. package/dist/client.d.mts +236 -0
  6. package/dist/client.d.ts +236 -0
  7. package/dist/client.js +331 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/client.mjs +297 -0
  10. package/dist/client.mjs.map +1 -0
  11. package/dist/express.d.mts +24 -0
  12. package/dist/express.d.ts +24 -0
  13. package/dist/express.js +102 -0
  14. package/dist/express.js.map +1 -0
  15. package/dist/express.mjs +76 -0
  16. package/dist/express.mjs.map +1 -0
  17. package/dist/fastify.d.mts +2 -2
  18. package/dist/fastify.d.ts +2 -2
  19. package/dist/fastify.js +3 -1
  20. package/dist/fastify.js.map +1 -1
  21. package/dist/fastify.mjs +3 -1
  22. package/dist/fastify.mjs.map +1 -1
  23. package/dist/hono.d.mts +23 -0
  24. package/dist/hono.d.ts +23 -0
  25. package/dist/hono.js +50 -0
  26. package/dist/hono.js.map +1 -0
  27. package/dist/hono.mjs +24 -0
  28. package/dist/hono.mjs.map +1 -0
  29. package/dist/index.d.mts +44 -6
  30. package/dist/index.d.ts +44 -6
  31. package/dist/index.js +672 -37
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.mjs +660 -37
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/next.d.mts +24 -0
  36. package/dist/next.d.ts +24 -0
  37. package/dist/next.js +77 -0
  38. package/dist/next.js.map +1 -0
  39. package/dist/next.mjs +52 -0
  40. package/dist/next.mjs.map +1 -0
  41. package/dist/react.d.mts +546 -7
  42. package/dist/react.d.ts +546 -7
  43. package/dist/react.js +925 -14
  44. package/dist/react.js.map +1 -1
  45. package/dist/react.mjs +913 -10
  46. package/dist/react.mjs.map +1 -1
  47. package/dist/styles.css +271 -0
  48. package/dist/svelte.d.mts +26 -0
  49. package/dist/svelte.d.ts +26 -0
  50. package/dist/svelte.js +402 -0
  51. package/dist/svelte.js.map +1 -0
  52. package/dist/svelte.mjs +373 -0
  53. package/dist/svelte.mjs.map +1 -0
  54. package/dist/{system-DvcQjORr.d.ts → system-DhRr_WxR.d.ts} +139 -1
  55. package/dist/{system-CR8p4BjB.d.mts → system-ZD_Wa8Bm.d.mts} +139 -1
  56. package/dist/theme.d.mts +59 -1
  57. package/dist/theme.d.ts +59 -1
  58. package/dist/theme.js +185 -5
  59. package/dist/theme.js.map +1 -1
  60. package/dist/theme.mjs +180 -4
  61. package/dist/theme.mjs.map +1 -1
  62. package/dist/validate-B_iC-4y8.d.mts +19 -0
  63. package/dist/validate-B_iC-4y8.d.ts +19 -0
  64. package/dist/vue.d.mts +28 -0
  65. package/dist/vue.d.ts +28 -0
  66. package/dist/vue.js +420 -0
  67. package/dist/vue.js.map +1 -0
  68. package/dist/vue.mjs +391 -0
  69. package/dist/vue.mjs.map +1 -0
  70. package/package.json +68 -7
  71. package/dist/permissions-B-a3eN0h.d.mts +0 -52
  72. 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
- Fastify has a plugin: `import { cauthyFastify } from 'cauthy-auth/fastify'`, which adds `req.cauthy()` and `app.requireSession`.
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
- Built with Stackmyth? Give Cauthy's pages your application's look from its own tokens:
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 theme --css node_modules/@stackmyth/core/core.vars.css --css src/styles/brand-theme.css --push
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, f as SessionStatus, e as SessionOrganization, c as CauthySystem, P as PublicSession, b as CauthyOptions } from './system-DvcQjORr.js';
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, f as SessionStatus, e as SessionOrganization, c as CauthySystem, P as PublicSession, b as CauthyOptions } from './system-CR8p4BjB.mjs';
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. */