@simple-auth-kit/auth-client 1.0.0 → 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Atik Shahriar Ratul
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,87 @@
1
+ # @simple-auth-kit/auth-client
2
+
3
+ Shared, framework-agnostic auth API client for [simple-auth-kit](https://github.com/shahriar-ratul/simple-auth-kit)
4
+ backends. Used by every client app in the repo (`admin-nextjs`, `admin-react`, `mobile-expo`,
5
+ `mobile-bare-rn`) — the auth flow and API contract are identical across them; only the
6
+ injected `TokenStorage` adapter differs per platform (`cookies-next` on web, `AsyncStorage`
7
+ on mobile).
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @simple-auth-kit/auth-client
13
+ ```
14
+
15
+ Package: https://www.npmjs.com/package/@simple-auth-kit/auth-client
16
+
17
+ ## Clone the source
18
+
19
+ This is a **standalone copy**, published from the monorepo. To pull just this package's
20
+ source without cloning the whole repo:
21
+
22
+ ```bash
23
+ npx degit shahriar-ratul/simple-auth-kit/packages/auth-client auth-client
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ `baseUrl` and `storage` are **required** — this package has no default backend URL and no
29
+ built-in storage. You provide both, from your own app's config:
30
+
31
+ - `baseUrl`: a plain string — this package doesn't read any env var itself, so how you produce
32
+ that string is entirely up to your own setup. The only real question is how *your* build tool
33
+ gets an env value into browser-run JS in the first place:
34
+
35
+ | Your setup | How to expose the value |
36
+ |---|---|
37
+ | Node.js backend (SSR, BFF, server-only code) | `process.env.AUTH_API_URL` directly — no build step needed |
38
+ | Next.js | prefix it `NEXT_PUBLIC_*` — only those are inlined into the browser bundle |
39
+ | Vite | prefix it `VITE_*`, read via `import.meta.env.VITE_AUTH_API_URL` |
40
+ | CRA / plain webpack | `REACT_APP_*` (CRA) or whatever your `DefinePlugin` rule exposes |
41
+ | Expo | prefix it `EXPO_PUBLIC_*` |
42
+ | Bare React Native | no built-in env support — use `react-native-config` (native build step) or `react-native-dotenv` (Babel plugin) |
43
+ | Plain `<script>`, no bundler | can't inline env vars at all — hardcode it, have your server inject it (e.g. `<script>window.__ENV__={API_URL:"..."}</script>`), or `fetch('/config.json')` at runtime |
44
+
45
+ Whichever string you end up with, that's the entire integration — pass it as `baseUrl` below.
46
+ `process.env.AUTH_API_URL` in the snippet is illustrative, not a name this package looks for.
47
+ - `storage`: a small object implementing `{ get, set, clear }` (see `TokenStorage` in
48
+ `types.ts`) — e.g. cookies on web, `AsyncStorage` on mobile. This package ships no
49
+ implementation; you write the one that fits your platform.
50
+
51
+ ```ts
52
+ import { AuthClient } from "@simple-auth-kit/auth-client";
53
+
54
+ const auth = new AuthClient({
55
+ baseUrl: process.env.AUTH_API_URL!, // wherever *your* backend is deployed — read via your own framework's env convention
56
+ storage: myTokenStorageAdapter, // your own TokenStorage implementation — platform-specific (cookies, AsyncStorage, ...)
57
+ });
58
+ ```
59
+
60
+ Pair it with any simple-auth-kit backend combo (`nestjs-prisma`, `nestjs-drizzle`,
61
+ `express-prisma`, `express-drizzle`) — the API contract is the same across all four.
62
+
63
+ `baseUrl` is read once, at construction, and kept on the instance — no method takes it as an
64
+ argument. Construct one `AuthClient` at app startup (a module-level singleton, as every app in
65
+ this repo does) and import that same instance everywhere else:
66
+
67
+ ```ts
68
+ // lib/auth-client.ts — built once, when this module first loads
69
+ export const authClient = new AuthClient({ baseUrl: AUTH_API_URL, storage: cookieTokenStorage });
70
+
71
+ // every other call site — just import and use; baseUrl is never mentioned again
72
+ await authClient.login({ identifier, password });
73
+ await authClient.me();
74
+ ```
75
+
76
+ ## Development
77
+
78
+ ```bash
79
+ npm install
80
+ npm run build # tsc -> dist/
81
+ npm run typecheck
82
+ npm run test # vitest
83
+ ```
84
+
85
+ ## Source
86
+
87
+ Full source and every consuming app: [simple-auth-kit](https://github.com/shahriar-ratul/simple-auth-kit).
@@ -5,7 +5,7 @@ export interface AuthClientOptions {
5
5
  /**
6
6
  * The workspace that workspace-scoped calls act in.
7
7
  *
8
- * Leave it out entirely against the plain backend variant (`easy-auth add <combo>`): nothing
8
+ * Leave it out entirely against the plain backend variant (`simple-auth-kit add <combo>`): nothing
9
9
  * then ever sends `X-Workspace-Id`, and no call site has to mention workspaces. Against the
10
10
  * workspaces variant (`--workspaces`) set it once — a string for a fixed workspace, or a
11
11
  * function resolved per request so the app's own store stays the owner of "which workspace am
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@simple-auth-kit/auth-client",
3
- "version": "1.0.0",
4
- "description": "Shared, framework-agnostic auth API client for the easy-auth backend. Used by all 4 client apps (admin-nextjs, admin-react, mobile-expo, mobile-bare-rn) — the auth flow and API contract are identical across them, only the injected TokenStorage adapter differs per platform (cookies-next on web, AsyncStorage on mobile).",
3
+ "version": "1.0.2",
4
+ "description": "Shared, framework-agnostic auth API client for the simple-auth-kit backend. Used by all 4 client apps (admin-nextjs, admin-react, mobile-expo, mobile-bare-rn) — the auth flow and API contract are identical across them, only the injected TokenStorage adapter differs per platform (cookies-next on web, AsyncStorage on mobile).",
5
+ "license": "MIT",
5
6
  "type": "module",
6
7
  "main": "./dist/index.js",
7
8
  "types": "./dist/index.d.ts",