limen-auth 0.0.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 (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -0
  3. package/dist/bearer-Cqmrmjjf.mjs +84 -0
  4. package/dist/bearer-Cqmrmjjf.mjs.map +1 -0
  5. package/dist/client-Er91De-z.mjs +705 -0
  6. package/dist/client-Er91De-z.mjs.map +1 -0
  7. package/dist/constants-CsR2pQ_9.mjs +15 -0
  8. package/dist/constants-CsR2pQ_9.mjs.map +1 -0
  9. package/dist/define-plugin-C7WOGU4b.mjs +24 -0
  10. package/dist/define-plugin-C7WOGU4b.mjs.map +1 -0
  11. package/dist/define-plugin-Dv0xXIaH.d.mts +450 -0
  12. package/dist/define-plugin-Dv0xXIaH.d.mts.map +1 -0
  13. package/dist/errors-4YJYt6f0.mjs +37 -0
  14. package/dist/errors-4YJYt6f0.mjs.map +1 -0
  15. package/dist/helpers-Cs3VtXdv.mjs +54 -0
  16. package/dist/helpers-Cs3VtXdv.mjs.map +1 -0
  17. package/dist/helpers-CvmKjWi2.d.mts +10 -0
  18. package/dist/helpers-CvmKjWi2.d.mts.map +1 -0
  19. package/dist/index-B8SpHkSd.d.mts +48 -0
  20. package/dist/index-B8SpHkSd.d.mts.map +1 -0
  21. package/dist/index-C6atwjEq.d.mts +65 -0
  22. package/dist/index-C6atwjEq.d.mts.map +1 -0
  23. package/dist/index-C9EuA9UZ.d.mts +32 -0
  24. package/dist/index-C9EuA9UZ.d.mts.map +1 -0
  25. package/dist/index-Cgr2wHmM.d.mts +87 -0
  26. package/dist/index-Cgr2wHmM.d.mts.map +1 -0
  27. package/dist/index-DV6YcNSu.d.mts +81 -0
  28. package/dist/index-DV6YcNSu.d.mts.map +1 -0
  29. package/dist/index-dEksIImj.d.mts +28 -0
  30. package/dist/index-dEksIImj.d.mts.map +1 -0
  31. package/dist/index.d.mts +30 -0
  32. package/dist/index.d.mts.map +1 -0
  33. package/dist/index.mjs +12 -0
  34. package/dist/index.mjs.map +1 -0
  35. package/dist/plugins/bearer/index.d.mts +2 -0
  36. package/dist/plugins/bearer/index.mjs +2 -0
  37. package/dist/plugins/credential/index.d.mts +2 -0
  38. package/dist/plugins/credential/index.mjs +50 -0
  39. package/dist/plugins/credential/index.mjs.map +1 -0
  40. package/dist/plugins/index.d.mts +7 -0
  41. package/dist/plugins/index.mjs +7 -0
  42. package/dist/plugins/magic-link/index.d.mts +2 -0
  43. package/dist/plugins/magic-link/index.mjs +21 -0
  44. package/dist/plugins/magic-link/index.mjs.map +1 -0
  45. package/dist/plugins/oauth/index.d.mts +2 -0
  46. package/dist/plugins/oauth/index.mjs +56 -0
  47. package/dist/plugins/oauth/index.mjs.map +1 -0
  48. package/dist/plugins/session-jwt/index.d.mts +2 -0
  49. package/dist/plugins/session-jwt/index.mjs +2 -0
  50. package/dist/plugins/two-factor/index.d.mts +2 -0
  51. package/dist/plugins/two-factor/index.mjs +52 -0
  52. package/dist/plugins/two-factor/index.mjs.map +1 -0
  53. package/dist/react/index.d.mts +24 -0
  54. package/dist/react/index.d.mts.map +1 -0
  55. package/dist/react/index.mjs +31 -0
  56. package/dist/react/index.mjs.map +1 -0
  57. package/dist/route-DGxvFqWl.mjs +19 -0
  58. package/dist/route-DGxvFqWl.mjs.map +1 -0
  59. package/dist/session-jwt-DgLdMQxP.mjs +129 -0
  60. package/dist/session-jwt-DgLdMQxP.mjs.map +1 -0
  61. package/dist/solid/index.d.mts +25 -0
  62. package/dist/solid/index.d.mts.map +1 -0
  63. package/dist/solid/index.mjs +28 -0
  64. package/dist/solid/index.mjs.map +1 -0
  65. package/dist/svelte/index.d.mts +25 -0
  66. package/dist/svelte/index.d.mts.map +1 -0
  67. package/dist/svelte/index.mjs +18 -0
  68. package/dist/svelte/index.mjs.map +1 -0
  69. package/dist/vue/index.d.mts +36 -0
  70. package/dist/vue/index.d.mts.map +1 -0
  71. package/dist/vue/index.mjs +36 -0
  72. package/dist/vue/index.mjs.map +1 -0
  73. package/package.json +123 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Brian Iyoha
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,72 @@
1
+ <p align="center">
2
+ <a href="https://limenauth.dev">
3
+ <img src="./banner.svg" alt="Limen" width="640" />
4
+ </a>
5
+ </p>
6
+
7
+ # limen-auth
8
+
9
+ Official TypeScript client SDK for **[Limen](https://github.com/thecodearcher/limen)** — a modern, composable authentication library for Go. Framework-agnostic core with first-class **React, Vue, Svelte, and Solid** adapters.
10
+
11
+ > 📖 Full guides and API reference: **[limenauth.dev](https://limenauth.dev)**
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install limen-auth
17
+ ```
18
+
19
+ Works with any framework — or none at all. If you're on React, Vue, Svelte, or Solid, just have that framework installed; there's nothing else to add.
20
+
21
+ ## Quick start
22
+
23
+ ```ts
24
+ import { createAuthClient } from "limen-auth";
25
+ import { credentialPasswordPlugin } from "limen-auth/plugins/credential";
26
+
27
+ export const auth = createAuthClient({
28
+ baseURL: "http://localhost:8080", // your Limen server origin
29
+ plugins: [credentialPasswordPlugin()],
30
+ });
31
+
32
+ await auth.signIn.credential({ credential: "ada@example.com", password: "secret" });
33
+ const session = await auth.getSession(); // Session | null
34
+ await auth.signout();
35
+ ```
36
+
37
+ `auth.$session` is a reactive store for the current user. It loads on its own, keeps your open tabs in sync, and updates as you sign in and out — so the UI always reflects the real session.
38
+
39
+ ## Framework adapters
40
+
41
+ Import `createAuthClient` from your framework's entry point and you get a `useSession()` wired to it:
42
+
43
+ ```tsx
44
+ import { createAuthClient } from "limen-auth/react";
45
+ import { credentialPasswordPlugin } from "limen-auth/plugins/credential";
46
+
47
+ export const auth = createAuthClient({ baseURL: "...", plugins: [credentialPasswordPlugin()] });
48
+
49
+ function Profile() {
50
+ const { data, isPending } = auth.useSession();
51
+ if (isPending) return <p>Loading…</p>;
52
+ return data ? <p>Hi {data.user.email}</p> : <p>Signed out</p>;
53
+ }
54
+ ```
55
+
56
+ Also available from `limen-auth/vue`, `limen-auth/svelte`, and `limen-auth/solid`.
57
+
58
+ ## Plugins
59
+
60
+ Add the sign-in flows you need as plugins (each lives under `limen-auth/plugins/<name>`):
61
+
62
+ - `credentialPasswordPlugin` — email/username + password
63
+ - `oauthClientPlugin` — social / OAuth providers
64
+ - `magicLinkPlugin` — passwordless email links
65
+ - `twoFactorPlugin` — TOTP, OTP, and backup codes
66
+ - `bearerPlugin` / `sessionJwtPlugin` — token-based sessions
67
+
68
+ See the plugin and full API reference at **[limenauth.dev](https://limenauth.dev)**.
69
+
70
+ ## License
71
+
72
+ MIT © Brian Iyoha
@@ -0,0 +1,84 @@
1
+ import { a as SET_REFRESH_TOKEN_HEADER, i as SET_AUTH_TOKEN_HEADER, r as DEFAULT_TOKEN_STORAGE_KEY } from "./constants-CsR2pQ_9.mjs";
2
+ import { n as defineRoutes, t as defineClientPlugin } from "./define-plugin-C7WOGU4b.mjs";
3
+ //#region src/plugins/bearer/storage.ts
4
+ function memoryBearerStorage() {
5
+ let tokens = null;
6
+ return {
7
+ get: () => tokens,
8
+ set: (next) => {
9
+ tokens = next;
10
+ },
11
+ clear: () => {
12
+ tokens = null;
13
+ }
14
+ };
15
+ }
16
+ function localStorageBearerStorage(key = DEFAULT_TOKEN_STORAGE_KEY) {
17
+ return {
18
+ get: () => {
19
+ try {
20
+ const raw = globalThis.localStorage.getItem(key);
21
+ if (!raw) return null;
22
+ const parsed = JSON.parse(raw);
23
+ if (typeof parsed?.accessToken !== "string") return null;
24
+ return parsed;
25
+ } catch {
26
+ return null;
27
+ }
28
+ },
29
+ set: (tokens) => {
30
+ globalThis.localStorage.setItem(key, JSON.stringify(tokens));
31
+ },
32
+ clear: () => {
33
+ globalThis.localStorage.removeItem(key);
34
+ }
35
+ };
36
+ }
37
+ function resolveDefaultStorage(key) {
38
+ if (typeof globalThis.localStorage !== "undefined") return localStorageBearerStorage(key);
39
+ return memoryBearerStorage();
40
+ }
41
+ //#endregion
42
+ //#region src/plugins/bearer/index.ts
43
+ function bearerPlugin(config = {}) {
44
+ const store = config.storage ?? resolveDefaultStorage(config.storageKey ?? "limen.tokens");
45
+ return defineClientPlugin({
46
+ id: "bearer",
47
+ routes: defineRoutes(),
48
+ actions: () => ({ bearer: {
49
+ getTokens: () => store.get(),
50
+ setTokens: (tokens) => store.set(tokens),
51
+ clear: () => store.clear()
52
+ } }),
53
+ hooks: {
54
+ beforeRequest: [{ run: (req) => {
55
+ const tokens = store.get();
56
+ if (tokens?.accessToken && !req.headers.has("Authorization")) req.headers.set("Authorization", `Bearer ${tokens.accessToken}`);
57
+ return req;
58
+ } }],
59
+ afterResponse: [{
60
+ allowOnFailure: true,
61
+ run: (res) => {
62
+ const accessToken = res.headers.get(SET_AUTH_TOKEN_HEADER);
63
+ if (accessToken) {
64
+ const tokens = { accessToken };
65
+ const refreshToken = res.headers.get(SET_REFRESH_TOKEN_HEADER);
66
+ if (refreshToken) tokens.refreshToken = refreshToken;
67
+ store.set(tokens);
68
+ }
69
+ return res;
70
+ }
71
+ }, {
72
+ match: ["/signout", "/revoke-sessions"],
73
+ run: (res) => {
74
+ store.clear();
75
+ return res;
76
+ }
77
+ }]
78
+ }
79
+ });
80
+ }
81
+ //#endregion
82
+ export { resolveDefaultStorage as i, localStorageBearerStorage as n, memoryBearerStorage as r, bearerPlugin as t };
83
+
84
+ //# sourceMappingURL=bearer-Cqmrmjjf.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bearer-Cqmrmjjf.mjs","names":[],"sources":["../src/plugins/bearer/storage.ts","../src/plugins/bearer/index.ts"],"sourcesContent":["import { DEFAULT_TOKEN_STORAGE_KEY } from \"../../constants\";\nimport type { BearerStorage, BearerTokens } from \"./types\";\n\nexport function memoryBearerStorage(): BearerStorage {\n let tokens: BearerTokens | null = null;\n return {\n get: () => tokens,\n set: (next) => {\n tokens = next;\n },\n clear: () => {\n tokens = null;\n },\n };\n}\n\nexport function localStorageBearerStorage(key: string = DEFAULT_TOKEN_STORAGE_KEY): BearerStorage {\n return {\n get: () => {\n try {\n const raw = globalThis.localStorage.getItem(key);\n if (!raw) {\n return null;\n }\n const parsed = JSON.parse(raw) as Partial<BearerTokens>;\n if (typeof parsed?.accessToken !== \"string\") {\n return null;\n }\n return parsed as BearerTokens;\n } catch {\n return null;\n }\n },\n set: (tokens) => {\n globalThis.localStorage.setItem(key, JSON.stringify(tokens));\n },\n clear: () => {\n globalThis.localStorage.removeItem(key);\n },\n };\n}\n\nexport function resolveDefaultStorage(key: string): BearerStorage {\n if (typeof globalThis.localStorage !== \"undefined\") {\n return localStorageBearerStorage(key);\n }\n return memoryBearerStorage();\n}\n","import { DEFAULT_TOKEN_STORAGE_KEY, SET_AUTH_TOKEN_HEADER, SET_REFRESH_TOKEN_HEADER } from \"../../constants\";\nimport { defineClientPlugin, defineRoutes } from \"../../define-plugin\";\nimport { resolveDefaultStorage } from \"./storage\";\nimport type { BearerPluginConfig, BearerTokens } from \"./types\";\n\nexport function bearerPlugin(config: BearerPluginConfig = {}) {\n const store = config.storage ?? resolveDefaultStorage(config.storageKey ?? DEFAULT_TOKEN_STORAGE_KEY);\n\n return defineClientPlugin({\n id: \"bearer\",\n routes: defineRoutes(),\n actions: () => ({\n bearer: {\n getTokens: () => store.get(),\n setTokens: (tokens: BearerTokens) => store.set(tokens),\n clear: () => store.clear(),\n },\n }),\n hooks: {\n beforeRequest: [\n {\n run: (req) => {\n const tokens = store.get();\n if (tokens?.accessToken && !req.headers.has(\"Authorization\")) {\n req.headers.set(\"Authorization\", `Bearer ${tokens.accessToken}`);\n }\n return req;\n },\n },\n ],\n afterResponse: [\n {\n allowOnFailure: true,\n run: (res) => {\n const accessToken = res.headers.get(SET_AUTH_TOKEN_HEADER);\n if (accessToken) {\n const tokens: BearerTokens = { accessToken };\n const refreshToken = res.headers.get(SET_REFRESH_TOKEN_HEADER);\n if (refreshToken) {\n tokens.refreshToken = refreshToken;\n }\n store.set(tokens);\n }\n return res;\n },\n },\n {\n match: [\"/signout\", \"/revoke-sessions\"],\n run: (res) => {\n store.clear();\n return res;\n },\n },\n ],\n },\n });\n}\n\nexport { localStorageBearerStorage, memoryBearerStorage, resolveDefaultStorage } from \"./storage\";\nexport type { BearerPluginConfig, BearerPlugin as BearerPublic, BearerStorage, BearerTokens } from \"./types\";\n"],"mappings":";;;AAGA,SAAgB,sBAAqC;CACnD,IAAI,SAA8B;CAClC,OAAO;EACL,WAAW;EACX,MAAM,SAAS;GACb,SAAS;EACX;EACA,aAAa;GACX,SAAS;EACX;CACF;AACF;AAEA,SAAgB,0BAA0B,MAAc,2BAA0C;CAChG,OAAO;EACL,WAAW;GACT,IAAI;IACF,MAAM,MAAM,WAAW,aAAa,QAAQ,GAAG;IAC/C,IAAI,CAAC,KACH,OAAO;IAET,MAAM,SAAS,KAAK,MAAM,GAAG;IAC7B,IAAI,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