@procedures/better-auth 0.13.0 → 0.13.2

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 CHANGED
@@ -38,6 +38,36 @@ app.all("/auth/*path", toNodeHandler(auth)); // the routes belong to the app
38
38
  | `PASSKEY_RP_ID` | The domain of the passkeys. The default is the host of the first trusted origin. |
39
39
  | `AUTH_TEST_ACCOUNTS=1` | Accounts with an email and a password, for the tests. Their email counts as verified. Production refuses it. |
40
40
 
41
+ ## The browser
42
+
43
+ `@procedures/better-auth/browser` gives the calls of a page to the auth routes of the server. It has no framework and no global state. Each function gives data, and the app decides what the page does next.
44
+
45
+ ```ts
46
+ import { createBrowserAuth } from "@procedures/better-auth/browser";
47
+
48
+ // The page and the server have one origin (or a proxy gives the server under the origin of the page)
49
+ const auth = createBrowserAuth({ baseURL: "" });
50
+ const user = await auth.session(); // undefined when signed out
51
+ const out = await auth.signInSocial("github", location.href);
52
+ if ("url" in out) location.assign(out.url);
53
+ ```
54
+
55
+ | Function | What it does |
56
+ | --- | --- |
57
+ | `session()` | The signed-in user of this browser: `id`, `name` and `email`. A server that does not answer in time gives `undefined`. |
58
+ | `signInSocial(provider, callbackURL)` | The page of the provider. The provider comes back to `callbackURL`. |
59
+ | `signOut()` | This function ends the session. |
60
+ | `addPasskey(name)` | This function makes a passkey of this device for the signed-in user. |
61
+ | `signInWithPasskey()` | This function signs in with a passkey of this device. |
62
+ | `signInWithPassword(input)` | A test server only (`AUTH_TEST_ACCOUNTS`): a sign-in, or a sign-up with `signUp: true`. |
63
+
64
+ - Each call sends the cookies. The session cookie is `httpOnly`, so a script of the page cannot read it.
65
+ - Give the page and the server one origin. A proxy under the origin of the page also works. This is the simplest form.
66
+ - A server on another origin needs CORS that names exactly one trusted origin, with `Access-Control-Allow-Credentials: true`. The server of this package does not send these headers. Without them, `session()` gives `undefined` and the other calls fail.
67
+ - A server on another site also needs the cookie attributes `SameSite=None` and `Secure`.
68
+ - A refused call gives `{ error }`. The functions do not throw for an answer of the server.
69
+ - The passkeys use `@simplewebauthn/browser`, which loads only when a passkey function operates.
70
+
41
71
  ## The principal of a request
42
72
 
43
73
  `SessionPrincipals` gives the user of a session cookie: the id, the verified email, the name and the groups. A short memo keeps the boot of a page to one session lookup.