@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 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 every app-specific hook (`onAuthorized`, `onUnauthenticated`) is supplied via `provideKitAuth`. The kit does not hard-code any routes.
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