@nauth-toolkit/client 0.1.3 → 0.1.5
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 +2 -85
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,92 +1,9 @@
|
|
|
1
1
|
# @nauth-toolkit/client
|
|
2
2
|
|
|
3
|
-
Framework-agnostic frontend SDK for nauth-toolkit
|
|
3
|
+
Framework-agnostic frontend SDK for nauth-toolkit
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Preview Release Notice
|
|
6
6
|
|
|
7
7
|
**This is a preview release for internal testing. Do not use in production yet.**
|
|
8
8
|
|
|
9
9
|
This package is part of nauth-toolkit and is currently in early access/preview. Features and APIs may change between releases. For production use, please wait for the stable v1.0 release.
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
npm install @nauth-toolkit/client@preview
|
|
15
|
-
# or
|
|
16
|
-
yarn add @nauth-toolkit/client@preview
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Angular apps (optional peers):
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
yarn add @angular/core @angular/common rxjs
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Quick Start (Vanilla)
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { NAuthClient } from '@nauth-toolkit/client';
|
|
29
|
-
|
|
30
|
-
const auth = new NAuthClient({
|
|
31
|
-
baseUrl: 'https://api.example.com/auth',
|
|
32
|
-
tokenDelivery: 'hybrid',
|
|
33
|
-
onSessionExpired: () => window.location.replace('/login')
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const result = await auth.login('user@example.com', 'password');
|
|
37
|
-
if (result.challengeName) {
|
|
38
|
-
// Prompt user to complete challenge then call respondToChallenge()
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Quick Start (Angular)
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
// app.config.ts (standalone)
|
|
46
|
-
import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
|
47
|
-
import { authInterceptor, NAUTH_CLIENT_CONFIG } from '@nauth-toolkit/client/angular';
|
|
48
|
-
|
|
49
|
-
providers: [
|
|
50
|
-
{ provide: NAUTH_CLIENT_CONFIG, useValue: {
|
|
51
|
-
baseUrl: 'https://api.example.com/auth',
|
|
52
|
-
tokenDelivery: 'cookies',
|
|
53
|
-
onSessionExpired: () => router.navigate(['/login'])
|
|
54
|
-
}},
|
|
55
|
-
provideHttpClient(withInterceptors([authInterceptor]))
|
|
56
|
-
]
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Configuration
|
|
60
|
-
|
|
61
|
-
- `baseUrl` (required): Auth API base (e.g., `https://api.example.com/auth`)
|
|
62
|
-
- `tokenDelivery`: `json` | `cookies` | `hybrid`
|
|
63
|
-
- `onSessionExpired` (required): Callback when refresh fails
|
|
64
|
-
- `storage`: Custom storage adapter for JSON/hybrid mobile (defaults to localStorage or in-memory)
|
|
65
|
-
- `csrf`: `{ cookieName, headerName }` (defaults: `nauth_csrf_token`, `x-csrf-token`)
|
|
66
|
-
- `deviceTrust`: `{ headerName, storageKey }` (defaults: `X-Device-Token`, `nauth_device_token`)
|
|
67
|
-
- `endpoints`: Override backend paths if different from defaults
|
|
68
|
-
|
|
69
|
-
## Token Delivery
|
|
70
|
-
|
|
71
|
-
- **json**: Stores tokens via storage adapter, sends Bearer header.
|
|
72
|
-
- **cookies**: Sends credentials; SDK never sends Bearer; CSRF header added automatically.
|
|
73
|
-
- **hybrid**: Browser path behaves like cookies; non-browser behaves like json.
|
|
74
|
-
|
|
75
|
-
## Storage Adapters
|
|
76
|
-
|
|
77
|
-
- `BrowserStorage` (localStorage/sessionStorage)
|
|
78
|
-
- `InMemoryStorage` (SSR/tests)
|
|
79
|
-
- Provide your own (e.g., Capacitor Preferences or React Native AsyncStorage).
|
|
80
|
-
|
|
81
|
-
## Error Handling
|
|
82
|
-
|
|
83
|
-
All errors are `NAuthClientError` with `code` from `NAuthErrorCode` enum and optional `details`.
|
|
84
|
-
|
|
85
|
-
## Scripts
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
yarn workspace @nauth-toolkit/client build
|
|
89
|
-
yarn workspace @nauth-toolkit/client lint
|
|
90
|
-
yarn workspace @nauth-toolkit/client test
|
|
91
|
-
```
|
|
92
|
-
|