@rdlabo/ionic-angular-kit 0.0.3 → 0.0.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 +25 -12
- package/fesm2022/rdlabo-ionic-angular-kit.mjs +849 -0
- package/fesm2022/rdlabo-ionic-angular-kit.mjs.map +1 -0
- package/package.json +15 -3
- package/types/rdlabo-ionic-angular-kit.d.ts +815 -0
- package/ng-package.json +0 -7
- package/src/lib/auth/auth-guards.spec.ts +0 -210
- package/src/lib/auth/auth-guards.ts +0 -227
- package/src/lib/directives/autofill.directive.ts +0 -68
- package/src/lib/http/kit-http.interceptor.spec.ts +0 -300
- package/src/lib/http/kit-http.interceptor.ts +0 -236
- package/src/lib/overlay/kit-overlay.controller.spec.ts +0 -233
- package/src/lib/overlay/kit-overlay.controller.ts +0 -206
- package/src/lib/overlay/kit-reload-alert.controller.spec.ts +0 -105
- package/src/lib/overlay/kit-reload-alert.controller.ts +0 -108
- package/src/lib/overlay/overlay-config.ts +0 -53
- package/src/lib/storage/kit-storage.service.spec.ts +0 -127
- package/src/lib/storage/kit-storage.service.ts +0 -91
- package/src/lib/utils/array.spec.ts +0 -33
- package/src/lib/utils/array.ts +0 -82
- package/src/lib/utils/haptics.ts +0 -32
- package/src/public-api.ts +0 -24
- package/tsconfig.lib.json +0 -14
- package/tsconfig.lib.prod.json +0 -11
- package/tsconfig.spec.json +0 -10
package/README.md
CHANGED
|
@@ -176,7 +176,7 @@ Functional `CanActivateFn` guards for a four-state auth model:
|
|
|
176
176
|
| `'required'` | Not authenticated |
|
|
177
177
|
| `'anonymous'` | Anonymous login active (can be prompted to register) |
|
|
178
178
|
|
|
179
|
-
**Convention:** every redirect path and
|
|
179
|
+
**Convention:** every redirect path is supplied via `provideKitAuth`; the kit does not hard-code any routes. `authState` and `redirects` are required. The app-specific hooks `onAuthorized` / `onUnauthenticated` are **optional** and default to `true` (allow the authenticated user through) / `false` (fall through to the `whenUnauthorized` redirect), so an app only supplies the ones with real logic.
|
|
180
180
|
|
|
181
181
|
**Setup**
|
|
182
182
|
|
|
@@ -190,29 +190,42 @@ export const appConfig: ApplicationConfig = {
|
|
|
190
190
|
const auth = inject(AuthService);
|
|
191
191
|
return {
|
|
192
192
|
authState: () => auth.state$, // Observable<KitAuthState>
|
|
193
|
-
onAuthorized: async (state) => {
|
|
194
|
-
// Called for 'user' — perform token refresh, permission check, etc.
|
|
195
|
-
// Return true to proceed, UrlTree to redirect, false to block.
|
|
196
|
-
await auth.refreshToken();
|
|
197
|
-
return true;
|
|
198
|
-
},
|
|
199
|
-
onUnauthenticated: async (state) => {
|
|
200
|
-
// Called for 'required'/'confirm' in kitRequireAuthorizedGuard.
|
|
201
|
-
// Return true to allow anonymous access, false to redirect.
|
|
202
|
-
return false;
|
|
203
|
-
},
|
|
204
193
|
redirects: {
|
|
205
194
|
whenAuthorized: '/home', // kitRequiredUnauthorizedGuard
|
|
206
195
|
whenConfirming: '/auth/confirm', // kitRequiredUnauthorizedGuard
|
|
207
196
|
whenNotConfirming: '/auth/signin',// kitRequireConfirmingGuard
|
|
208
197
|
whenUnauthorized: '/auth', // kitRequireAuthorizedGuard
|
|
209
198
|
},
|
|
199
|
+
// onAuthorized / onUnauthenticated omitted → defaults (allow / redirect).
|
|
200
|
+
// Supply onAuthorized only when 'user' needs extra work (token login, permissions):
|
|
201
|
+
// onAuthorized: async () => { await auth.refreshToken(); return true; },
|
|
202
|
+
// Supply onUnauthenticated only for a fallback such as anonymous sign-in:
|
|
203
|
+
// onUnauthenticated: async () => { await auth.signInAnonymously(); return true; },
|
|
210
204
|
};
|
|
211
205
|
}),
|
|
212
206
|
],
|
|
213
207
|
};
|
|
214
208
|
```
|
|
215
209
|
|
|
210
|
+
### kitPresentAuthFailedAlert
|
|
211
|
+
|
|
212
|
+
The fleet's canonical "sign-in / token exchange failed" alert: an informative alert (header + optional server error as sub-header + detail message) with a single close button that reloads the app so the user restarts cleanly. Text is passed in (no hardcoded i18n); the caller signs the user out around it. A standalone helper (takes `AlertController`) since `location.reload()` is navigation policy the overlay controller does not hold.
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import { kitPresentAuthFailedAlert } from '@rdlabo/ionic-angular-kit';
|
|
216
|
+
|
|
217
|
+
const logged = await auth.tokenLogin().catch(async (e) => {
|
|
218
|
+
await kitPresentAuthFailedAlert(alertCtrl, {
|
|
219
|
+
header: 'ログインできませんでした',
|
|
220
|
+
subHeader: e.error.error,
|
|
221
|
+
message: e.error.detail,
|
|
222
|
+
closeText: '閉じる',
|
|
223
|
+
});
|
|
224
|
+
await auth.signOut();
|
|
225
|
+
return undefined;
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
216
229
|
**Guards**
|
|
217
230
|
|
|
218
231
|
```typescript
|