@lalternative/auth 0.2.0 → 0.3.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 (2) hide show
  1. package/README.md +34 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -34,3 +34,37 @@ export const authClient = createPlatformAuthClient({ baseURL })
34
34
  // UI + hooks
35
35
  import { VerifyEmailForm, ForgotPasswordForm, ResetPasswordForm, AuthLayout, useSession, useLogout } from "@lalternative/auth"
36
36
  ```
37
+
38
+ ### Invitations
39
+
40
+ An invitation link lands on the app's own sign-up page
41
+ (`/register?invite=<token>`) and is redeemed once the account exists. Claim on
42
+ the auth callback, not in the page: a sign-up completes through password + OTP,
43
+ OAuth redirect or email verification, and only two of those return to the page
44
+ that held the token.
45
+
46
+ ```ts
47
+ // server — auth callback (e.g. routes/api/auth/$.ts)
48
+ import { claimInvitation, inviteTokenFrom } from "@lalternative/auth/server"
49
+
50
+ const token = inviteTokenFrom(request)
51
+ if (token && user) {
52
+ // Best-effort: a sign-in must never fail because a claim did not go through.
53
+ const outcome = await claimInvitation({
54
+ endpoint: `${process.env.LUNGOR_API_URL}/invitations/claim`,
55
+ apiKey: process.env.LUNGOR_APP_API_KEY,
56
+ token,
57
+ externalUserId: user.id,
58
+ })
59
+ }
60
+ ```
61
+
62
+ ```tsx
63
+ // UI — telling the invitee why a link did not work
64
+ import { InvitationNotice, isInvitationFailure } from "@lalternative/auth"
65
+
66
+ if (isInvitationFailure(outcome)) return <InvitationNotice reason={outcome} />
67
+ ```
68
+
69
+ `endpoint` is any backend that redeems a token, so an app already claiming
70
+ against its own API keeps doing so; `extra` adds fields to the request body.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lalternative/auth",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Shared Better Auth wrapper for L'Alternative apps (server + React client + auth UI)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",