@rdlabo/ionic-angular-kit 22.0.1-beta.pr105.sha55308d6acf67 → 22.0.2-beta.pr107.shabca274cf9d55
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 +20 -14
- package/docs/eslint.md +2 -2
- package/docs/forms.md +1 -1
- package/docs/optional-features.md +13 -1
- package/fesm2022/rdlabo-ionic-angular-kit-auth-firebase-apple.mjs +82 -0
- package/fesm2022/rdlabo-ionic-angular-kit-auth-firebase-apple.mjs.map +1 -0
- package/fesm2022/rdlabo-ionic-angular-kit-auth-firebase-facebook.mjs +69 -0
- package/fesm2022/rdlabo-ionic-angular-kit-auth-firebase-facebook.mjs.map +1 -0
- package/fesm2022/rdlabo-ionic-angular-kit-auth-firebase-google.mjs +15 -34
- package/fesm2022/rdlabo-ionic-angular-kit-auth-firebase-google.mjs.map +1 -1
- package/fesm2022/rdlabo-ionic-angular-kit-auth-firebase-internal.mjs +75 -0
- package/fesm2022/rdlabo-ionic-angular-kit-auth-firebase-internal.mjs.map +1 -0
- package/fesm2022/rdlabo-ionic-angular-kit-auth-firebase-social.mjs +9 -220
- package/fesm2022/rdlabo-ionic-angular-kit-auth-firebase-social.mjs.map +1 -1
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs +175 -98
- package/fesm2022/rdlabo-ionic-angular-kit-offline.mjs.map +1 -1
- package/package.json +18 -6
- package/types/rdlabo-ionic-angular-kit-auth-firebase-apple.d.ts +33 -0
- package/types/rdlabo-ionic-angular-kit-auth-firebase-facebook.d.ts +29 -0
- package/types/rdlabo-ionic-angular-kit-auth-firebase-google.d.ts +10 -1
- package/types/rdlabo-ionic-angular-kit-auth-firebase-internal.d.ts +45 -0
- package/types/rdlabo-ionic-angular-kit-auth-firebase-social.d.ts +20 -102
- package/types/rdlabo-ionic-angular-kit-offline.d.ts +14 -1
package/README.md
CHANGED
|
@@ -62,21 +62,27 @@ Firebase, social login, Live Update, Preferences, Status Bar, in-app review, and
|
|
|
62
62
|
|
|
63
63
|
The `/auth-firebase/google` entry point uses `@capawesome/capacitor-google-sign-in` 0.1.x and therefore requires Capacitor 8. Applications remaining on Capacitor 7 can continue to use the core Kit and other compatible entry points, but cannot use this Google entry point.
|
|
64
64
|
|
|
65
|
+
Install only the native plugin for the provider entry point you import. `/auth-firebase/social` is deprecated but retained for backwards compatibility; it reexports Apple and Facebook and therefore requires both plugins. Migrate imports to `/auth-firebase/apple` and `/auth-firebase/facebook` when convenient; removal is not part of this change. `/auth-firebase/internal` is a provider-neutral shared implementation used by those entry points; it is not a supported application API.
|
|
66
|
+
|
|
67
|
+
Social login callbacks pin request identity via the authenticated `user` on the success payload. Failures in `before`/`success` (and Google `exchange`) are reported to `error`, return `{ status: false }`, and always run `finally`. Failures inside `error`/`finally` themselves reject the call. Native Apple runs on iOS only; web uses the Firebase popup. Cancellation is classified only when the native adapter preserves a cancellation code; unknown native errors are `other` (do not infer cancellation from localized messages).
|
|
68
|
+
|
|
65
69
|
## Entry points
|
|
66
70
|
|
|
67
|
-
| Import
|
|
68
|
-
|
|
|
69
|
-
| `@rdlabo/ionic-angular-kit`
|
|
70
|
-
| `@rdlabo/ionic-angular-kit/offline`
|
|
71
|
-
| `@rdlabo/ionic-angular-kit/theme`
|
|
72
|
-
| `@rdlabo/ionic-angular-kit/forms`
|
|
73
|
-
| `@rdlabo/ionic-angular-kit/review`
|
|
74
|
-
| `@rdlabo/ionic-angular-kit/printer`
|
|
75
|
-
| `@rdlabo/ionic-angular-kit/auth-firebase`
|
|
76
|
-
| `@rdlabo/ionic-angular-kit/auth-firebase/
|
|
77
|
-
| `@rdlabo/ionic-angular-kit/auth-firebase/
|
|
78
|
-
| `@rdlabo/ionic-angular-kit/
|
|
79
|
-
| `@rdlabo/ionic-angular-kit/
|
|
71
|
+
| Import | Responsibility |
|
|
72
|
+
| -------------------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
73
|
+
| `@rdlabo/ionic-angular-kit` | Storage, overlays, guards, HTTP, realtime, directives, keyboard, and utilities |
|
|
74
|
+
| `@rdlabo/ionic-angular-kit/offline` | **Experimental.** Scoped local replica, outbox, pull, replay, and request policies |
|
|
75
|
+
| `@rdlabo/ionic-angular-kit/theme` | Persisted light/dark theme and native status bar sync |
|
|
76
|
+
| `@rdlabo/ionic-angular-kit/forms` | Ionic error text and state classes for Angular Signal Forms |
|
|
77
|
+
| `@rdlabo/ionic-angular-kit/review` | Throttled native in-app review requests |
|
|
78
|
+
| `@rdlabo/ionic-angular-kit/printer` | DOM-to-PNG, Brother label, and PDF helpers |
|
|
79
|
+
| `@rdlabo/ionic-angular-kit/auth-firebase` | Firebase dependency wiring and authentication flows |
|
|
80
|
+
| `@rdlabo/ionic-angular-kit/auth-firebase/apple` | Apple sign-in/link (own Apple plugin only) |
|
|
81
|
+
| `@rdlabo/ionic-angular-kit/auth-firebase/facebook` | Facebook login/link/logout (own Facebook plugin only) |
|
|
82
|
+
| `@rdlabo/ionic-angular-kit/auth-firebase/google` | Google popup/native sign-in, Firebase session linking, and logout |
|
|
83
|
+
| `@rdlabo/ionic-angular-kit/auth-firebase/social` | **Deprecated, retained for compatibility.** Apple/Facebook helpers |
|
|
84
|
+
| `@rdlabo/ionic-angular-kit/app-update` | Atomic Angular service-worker update transitions |
|
|
85
|
+
| `@rdlabo/ionic-angular-kit/live-update` | Capawesome Live Update readiness provider |
|
|
80
86
|
|
|
81
87
|
Secondary entry points isolate optional native and SDK dependencies from the core bundle.
|
|
82
88
|
|
|
@@ -90,7 +96,7 @@ Most features expose a provider whose callbacks keep routes, copy, credentials,
|
|
|
90
96
|
|
|
91
97
|
- [Storage and Overlays](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/storage-overlays)
|
|
92
98
|
- [Forms](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/forms)
|
|
93
|
-
- [Check your Kit integration with ESLint](
|
|
99
|
+
- [Check your Kit integration with ESLint](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/eslint)
|
|
94
100
|
- [Authentication and HTTP](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/auth-http)
|
|
95
101
|
- [Offline and Realtime](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/offline-realtime)
|
|
96
102
|
- [Optional Features](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/optional-features)
|
package/docs/eslint.md
CHANGED
|
@@ -48,7 +48,7 @@ These rules are also included in `rdlabo.configs.recommended`.
|
|
|
48
48
|
|
|
49
49
|
`deny-overlay-create` reports `.create()` calls on `ModalController` and `PopoverController`. `prefer-modal-launcher` checks that `presentModal` calls live in `launch*` functions.
|
|
50
50
|
|
|
51
|
-
With `overlay` and `DetailPage` from your [overlay setup](
|
|
51
|
+
With `overlay` and `DetailPage` from your [overlay setup](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/storage-overlays), this is reported:
|
|
52
52
|
|
|
53
53
|
```ts
|
|
54
54
|
export const openDetail = () => overlay.presentModal(DetailPage);
|
|
@@ -87,7 +87,7 @@ The rule checks the wrapper call, not the async work's behavior. Keep submit act
|
|
|
87
87
|
|
|
88
88
|
By default, `require-ion-error-text` requires an error text source on Ionic controls with `[formField]`.
|
|
89
89
|
|
|
90
|
-
For Angular 22 apps using [Kit Signal Forms](
|
|
90
|
+
For Angular 22 apps using [Kit Signal Forms](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/forms), import `FormField` and `KitIonicFormField` in each relevant component and install `provideKitIonicSignalForms()`. Then override this entry in the HTML config's `rules`:
|
|
91
91
|
|
|
92
92
|
```js
|
|
93
93
|
'@rdlabo/rules/require-ion-error-text': [
|
package/docs/forms.md
CHANGED
|
@@ -56,4 +56,4 @@ export const appConfig: ApplicationConfig = {
|
|
|
56
56
|
|
|
57
57
|
Angular does not merge multiple `provideSignalFormsConfig` class configurations. If the application provides its own configuration, combine all required class mappings in one provider instead of registering both providers and relying on their order.
|
|
58
58
|
|
|
59
|
-
For the matching lint configuration, see [Check your Kit integration with ESLint](
|
|
59
|
+
For the matching lint configuration, see [Check your Kit integration with ESLint](https://docs.rdlabo.dev/projects/ionic-angular-kit/docs/eslint).
|
|
@@ -57,7 +57,19 @@ The `/printer` entry point contains pure helpers for DOM-to-PNG rendering, image
|
|
|
57
57
|
|
|
58
58
|
The `/auth-firebase` entry point initializes `firebase/auth` through `provideKitFirebase()` and exposes `KIT_FIREBASE_AUTH` plus flow helpers such as `kitSignIn`, `kitSignUp`, `kitSignOut`, `kitResolveAuthStatus`, and `kitReauthWithRetry`.
|
|
59
59
|
|
|
60
|
-
The kit performs no UI. Hooks carry loading, navigation, and error presentation back to the application. Social providers
|
|
60
|
+
The kit performs no UI. Hooks carry loading, navigation, and error presentation back to the application. Social providers have separate `/auth-firebase/apple`, `/auth-firebase/facebook`, and `/auth-firebase/google` entry points, so each provider needs only its own optional plugin. The combined `/auth-firebase/social` entry point is **deprecated and retained for backwards compatibility**; migrate its Apple imports to `/apple` and its Facebook imports to `/facebook`.
|
|
61
|
+
|
|
62
|
+
The compatibility entry point still loads both Apple and Facebook plugins. Its functions retain the same runtime identity, and existing Apple response objects remain source-compatible.
|
|
63
|
+
|
|
64
|
+
Social helpers capture the current Firebase user before `before` runs and check that identity around asynchronous work. Success hooks receive the exact authenticated `user`; use it to bind backend requests to the same session. An overlapping Apple, Facebook, or Google flow for the same `Auth` is rejected through `error('other', error)` with `status: false`, before its `before` hook or SDK call starts. The guard stays active through cleanup. Different `Auth` instances are independent.
|
|
65
|
+
|
|
66
|
+
Applications must also coordinate email/password authentication, sign-out, and direct Firebase calls with these flows. The guard covers kit social helpers in this JavaScript context; it cannot cancel an already-started Firebase request, roll back a completed provider link, or serialize changes from another browser tab.
|
|
67
|
+
|
|
68
|
+
Failures in `before`, exchange, or `success` run the error hook and return `status: false`. `finally` always runs, including on overlapping calls; errors from `error` or `finally` reject the promise. Hooks own their UI cleanup.
|
|
69
|
+
|
|
70
|
+
Apple consumers must install `@capawesome/capacitor-apple-sign-in` (`>=0.1.4 <1`) and run `npx cap sync` after replacing `@capacitor-community/apple-sign-in`. This native dependency migration also applies when using the deprecated `/social` entry point; its import and response types remain compatible. Native plugin changes require a new native binary.
|
|
71
|
+
|
|
72
|
+
The Apple helper uses native sign-in on iOS and the Firebase popup on web. Android Service ID and redirect configuration are not exposed by this helper. Capawesome's typed `SIGN_IN_CANCELED` error is reported as cancellation; other native errors remain operational failures. The native `idToken` maps to the existing `identityToken` response field. On web, `authorizationCode` is `null`, and the popup access token is returned separately as `accessToken`.
|
|
61
73
|
|
|
62
74
|
## Live Update
|
|
63
75
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { OAuthProvider, reauthenticateWithPopup, linkWithCredential, EmailAuthProvider, signInWithPopup, linkWithPopup } from 'firebase/auth';
|
|
2
|
+
import { Capacitor } from '@capacitor/core';
|
|
3
|
+
import { ErrorCode, AppleSignIn, SignInScope } from '@capawesome/capacitor-apple-sign-in';
|
|
4
|
+
import { classifyOAuthError, assertCurrentUser, applyOAuthCredential, requireUser, runOAuthOperation } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';
|
|
5
|
+
|
|
6
|
+
const emptyAppleResponse = () => ({
|
|
7
|
+
user: null,
|
|
8
|
+
email: null,
|
|
9
|
+
givenName: null,
|
|
10
|
+
familyName: null,
|
|
11
|
+
identityToken: null,
|
|
12
|
+
authorizationCode: null,
|
|
13
|
+
accessToken: null,
|
|
14
|
+
});
|
|
15
|
+
const classifyAppleError = (error) => {
|
|
16
|
+
const code = error?.code;
|
|
17
|
+
return code === ErrorCode.SignInCanceled ? 'cancelled' : classifyOAuthError(error);
|
|
18
|
+
};
|
|
19
|
+
/** Apple sign-in/link on iOS and web. Native Android is not configured by this helper.
|
|
20
|
+
* Pins the user before any asynchronous work and reports SDK and app-hook failures to error.
|
|
21
|
+
*/
|
|
22
|
+
const kitAppleLogin = async (auth, options) => {
|
|
23
|
+
const expectedUser = auth.currentUser;
|
|
24
|
+
const execute = async () => {
|
|
25
|
+
await options.before?.();
|
|
26
|
+
assertCurrentUser(auth, expectedUser);
|
|
27
|
+
let response;
|
|
28
|
+
let user;
|
|
29
|
+
if (Capacitor.isNativePlatform()) {
|
|
30
|
+
if (Capacitor.getPlatform() !== 'ios')
|
|
31
|
+
throw new Error('kit Apple login: native platform is not supported');
|
|
32
|
+
const native = await AppleSignIn.signIn({ scopes: [SignInScope.Email, SignInScope.FullName] });
|
|
33
|
+
response = {
|
|
34
|
+
user: native.user,
|
|
35
|
+
email: native.email,
|
|
36
|
+
givenName: native.givenName,
|
|
37
|
+
familyName: native.familyName,
|
|
38
|
+
identityToken: native.idToken,
|
|
39
|
+
authorizationCode: native.authorizationCode,
|
|
40
|
+
accessToken: null,
|
|
41
|
+
};
|
|
42
|
+
if (!response.identityToken)
|
|
43
|
+
throw new Error('kit Apple login: identity token is missing');
|
|
44
|
+
const credential = new OAuthProvider('apple.com').credential({ idToken: response.identityToken });
|
|
45
|
+
user = await applyOAuthCredential(auth, credential, options, expectedUser);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const provider = new OAuthProvider('apple.com');
|
|
49
|
+
provider.addScope('email');
|
|
50
|
+
provider.addScope('name');
|
|
51
|
+
if (options.mode === 'credential') {
|
|
52
|
+
user = requireUser(expectedUser);
|
|
53
|
+
await reauthenticateWithPopup(user, provider);
|
|
54
|
+
assertCurrentUser(auth, user);
|
|
55
|
+
await linkWithCredential(user, EmailAuthProvider.credential(options.emailLogin.email, options.emailLogin.password));
|
|
56
|
+
response = emptyAppleResponse();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const result = options.mode === 'new' ? await signInWithPopup(auth, provider) : await linkWithPopup(requireUser(expectedUser), provider);
|
|
60
|
+
user = result.user;
|
|
61
|
+
const credential = OAuthProvider.credentialFromResult(result);
|
|
62
|
+
response = {
|
|
63
|
+
...emptyAppleResponse(),
|
|
64
|
+
email: user.email,
|
|
65
|
+
identityToken: credential?.idToken ?? null,
|
|
66
|
+
accessToken: credential?.accessToken ?? null,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
assertCurrentUser(auth, user);
|
|
71
|
+
await options.success?.({ response, mode: options.mode, user });
|
|
72
|
+
assertCurrentUser(auth, user);
|
|
73
|
+
};
|
|
74
|
+
return runOAuthOperation(auth, execute, (error) => options.error?.(classifyAppleError(error), error), options.finally);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Generated bundle index. Do not edit.
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
export { kitAppleLogin };
|
|
82
|
+
//# sourceMappingURL=rdlabo-ionic-angular-kit-auth-firebase-apple.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rdlabo-ionic-angular-kit-auth-firebase-apple.mjs","sources":["../../../projects/kit/auth-firebase/apple/src/kit-apple.ts","../../../projects/kit/auth-firebase/apple/src/rdlabo-ionic-angular-kit-auth-firebase-apple.ts"],"sourcesContent":["import type { Auth, User } from 'firebase/auth';\nimport {\n EmailAuthProvider,\n linkWithCredential,\n linkWithPopup,\n OAuthProvider,\n reauthenticateWithPopup,\n signInWithPopup,\n} from 'firebase/auth';\nimport { Capacitor } from '@capacitor/core';\nimport { AppleSignIn, ErrorCode, SignInScope } from '@capawesome/capacitor-apple-sign-in';\nimport {\n applyOAuthCredential,\n assertCurrentUser,\n classifyOAuthError,\n requireUser,\n runOAuthOperation,\n} from '@rdlabo/ionic-angular-kit/auth-firebase/internal';\nimport type { KitOAuthMode, KitOAuthModeName, KitSocialHooks } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';\n\n/** Apple credentials. Native authorization codes and web access tokens are distinct values. */\nexport interface KitAppleResponse {\n user: string | null;\n email: string | null;\n givenName: string | null;\n familyName: string | null;\n identityToken: string | null;\n /** One-time authorization code from native Apple sign-in; null on web. */\n authorizationCode: string | null;\n /** Apple access token from the Firebase web popup; null on native.\n * Optional for source compatibility with existing Apple response objects. Kit always supplies it.\n */\n accessToken?: string | null;\n}\n\n/** Apple login options. The success hook receives the exact authenticated Firebase user. */\nexport type KitAppleLoginOptions = KitOAuthMode & KitSocialHooks<{ response: KitAppleResponse; mode: KitOAuthModeName; user: User }>;\n\nconst emptyAppleResponse = (): KitAppleResponse => ({\n user: null,\n email: null,\n givenName: null,\n familyName: null,\n identityToken: null,\n authorizationCode: null,\n accessToken: null,\n});\n\nconst classifyAppleError = (error: unknown) => {\n const code = (error as { code?: string } | null)?.code;\n return code === ErrorCode.SignInCanceled ? 'cancelled' : classifyOAuthError(error);\n};\n\n/** Apple sign-in/link on iOS and web. Native Android is not configured by this helper.\n * Pins the user before any asynchronous work and reports SDK and app-hook failures to error.\n */\nexport const kitAppleLogin = async (auth: Auth, options: KitAppleLoginOptions): Promise<{ status: boolean }> => {\n const expectedUser = auth.currentUser;\n const execute = async (): Promise<void> => {\n await options.before?.();\n assertCurrentUser(auth, expectedUser);\n let response: KitAppleResponse;\n let user: User;\n if (Capacitor.isNativePlatform()) {\n if (Capacitor.getPlatform() !== 'ios') throw new Error('kit Apple login: native platform is not supported');\n const native = await AppleSignIn.signIn({ scopes: [SignInScope.Email, SignInScope.FullName] });\n response = {\n user: native.user,\n email: native.email,\n givenName: native.givenName,\n familyName: native.familyName,\n identityToken: native.idToken,\n authorizationCode: native.authorizationCode,\n accessToken: null,\n };\n if (!response.identityToken) throw new Error('kit Apple login: identity token is missing');\n const credential = new OAuthProvider('apple.com').credential({ idToken: response.identityToken });\n user = await applyOAuthCredential(auth, credential, options, expectedUser);\n } else {\n const provider = new OAuthProvider('apple.com');\n provider.addScope('email');\n provider.addScope('name');\n if (options.mode === 'credential') {\n user = requireUser(expectedUser);\n await reauthenticateWithPopup(user, provider);\n assertCurrentUser(auth, user);\n await linkWithCredential(user, EmailAuthProvider.credential(options.emailLogin.email, options.emailLogin.password));\n response = emptyAppleResponse();\n } else {\n const result =\n options.mode === 'new' ? await signInWithPopup(auth, provider) : await linkWithPopup(requireUser(expectedUser), provider);\n user = result.user;\n const credential = OAuthProvider.credentialFromResult(result);\n response = {\n ...emptyAppleResponse(),\n email: user.email,\n identityToken: credential?.idToken ?? null,\n accessToken: credential?.accessToken ?? null,\n };\n }\n }\n assertCurrentUser(auth, user);\n await options.success?.({ response, mode: options.mode, user });\n assertCurrentUser(auth, user);\n };\n return runOAuthOperation(auth, execute, (error) => options.error?.(classifyAppleError(error), error), options.finally);\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAsCA,MAAM,kBAAkB,GAAG,OAAyB;AAClD,IAAA,IAAI,EAAE,IAAI;AACV,IAAA,KAAK,EAAE,IAAI;AACX,IAAA,SAAS,EAAE,IAAI;AACf,IAAA,UAAU,EAAE,IAAI;AAChB,IAAA,aAAa,EAAE,IAAI;AACnB,IAAA,iBAAiB,EAAE,IAAI;AACvB,IAAA,WAAW,EAAE,IAAI;AAClB,CAAA,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,KAAc,KAAI;AAC5C,IAAA,MAAM,IAAI,GAAI,KAAkC,EAAE,IAAI;AACtD,IAAA,OAAO,IAAI,KAAK,SAAS,CAAC,cAAc,GAAG,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC;AACpF,CAAC;AAED;;AAEG;AACI,MAAM,aAAa,GAAG,OAAO,IAAU,EAAE,OAA6B,KAAkC;AAC7G,IAAA,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW;AACrC,IAAA,MAAM,OAAO,GAAG,YAA0B;AACxC,QAAA,MAAM,OAAO,CAAC,MAAM,IAAI;AACxB,QAAA,iBAAiB,CAAC,IAAI,EAAE,YAAY,CAAC;AACrC,QAAA,IAAI,QAA0B;AAC9B,QAAA,IAAI,IAAU;AACd,QAAA,IAAI,SAAS,CAAC,gBAAgB,EAAE,EAAE;AAChC,YAAA,IAAI,SAAS,CAAC,WAAW,EAAE,KAAK,KAAK;AAAE,gBAAA,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC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AAK,EAAE,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;gBACnH,QAAQ,GAAG,kBAAkB,EAAE;YACjC;iBAAO;AACL,gBAAA,MAAM,MAAM,GACV,OAAO,CAAC,IAAI,KAAK,KAAK,GAAG,MAAM,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,MAAM,aAAa,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC;AAC3H,gBAAA,IAAI,GAAG,MAAM,CAAC,IAAI;gBAClB,MAAM,UAAU,GAAG,aAAa,CAAC,oBAAoB,CAAC,MAAM,CAAC;AAC7D,gBAAA,QAAQ,GAAG;AACT,oBAAA,GAAG,kBAAkB,EAAE;oBACvB,KAAK,EAAE,IAAI,CAAC,KAAK;AACjB,oBAAA,aAAa,EAAE,UAAU,EAAE,OAAO,IAAI,IAAI;AAC1C,oBAAA,WAAW,EAAE,UAAU,EAAE,WAAW,IAAI,IAAI;iBAC7C;YACH;QACF;AACA,QAAA,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;AAC7B,QAAA,MAAM,OAAO,CAAC,OAAO,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;AAC/D,QAAA,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;AAC/B,IAAA,CAAC;AACD,IAAA,OAAO,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,GAAG,kBAAkB,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC;AACxH;;AC1GA;;AAEG;;;;"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { OAuthProvider, FacebookAuthProvider } from 'firebase/auth';
|
|
2
|
+
import { Capacitor } from '@capacitor/core';
|
|
3
|
+
import { FacebookLogin } from '@capacitor-community/facebook-login';
|
|
4
|
+
import { assertCurrentUser, applyOAuthCredential, runOAuthOperation, classifyOAuthError } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';
|
|
5
|
+
|
|
6
|
+
const generateNonce = () => Array.from(crypto.getRandomValues(new Uint8Array(16)), (value) => value.toString(16).padStart(2, '0')).join('');
|
|
7
|
+
/** Await one animation frame where available (iOS WebView crash workaround; no-op off-browser). */
|
|
8
|
+
const nextFrame = () => new Promise((resolve) => {
|
|
9
|
+
if (typeof requestAnimationFrame === 'function') {
|
|
10
|
+
requestAnimationFrame(() => resolve());
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
resolve();
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
/** Web plugin cancellation shape: the login promise rejects with a response whose token is null. */
|
|
17
|
+
const isFacebookCancellation = (error) => {
|
|
18
|
+
if (typeof error !== 'object' || error === null || !('accessToken' in error)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const { accessToken } = error;
|
|
22
|
+
if (typeof accessToken !== 'object' || accessToken === null || !('token' in accessToken)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return accessToken.token === null;
|
|
26
|
+
};
|
|
27
|
+
/** Facebook login/link with a pinned Firebase user and classified failure hooks. */
|
|
28
|
+
const kitFacebookLogin = async (auth, options) => {
|
|
29
|
+
const expectedUser = auth.currentUser;
|
|
30
|
+
const execute = async () => {
|
|
31
|
+
await options.before?.();
|
|
32
|
+
assertCurrentUser(auth, expectedUser);
|
|
33
|
+
const nonce = generateNonce();
|
|
34
|
+
const event = await FacebookLogin.login({ permissions: options.permissions, nonce }).finally(nextFrame);
|
|
35
|
+
if (!event?.accessToken?.token)
|
|
36
|
+
throw Object.assign(new Error('Facebook login cancelled'), { code: 'auth/user-cancelled' });
|
|
37
|
+
const accessToken = event.accessToken.token;
|
|
38
|
+
const credential = Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'ios'
|
|
39
|
+
? new OAuthProvider('facebook.com').credential({ rawNonce: nonce, idToken: accessToken })
|
|
40
|
+
: FacebookAuthProvider.credential(accessToken);
|
|
41
|
+
const user = await applyOAuthCredential(auth, credential, options, expectedUser);
|
|
42
|
+
await options.success?.({ accessToken, mode: options.mode, user });
|
|
43
|
+
assertCurrentUser(auth, user);
|
|
44
|
+
};
|
|
45
|
+
return runOAuthOperation(auth, execute, (error) => options.error?.(isFacebookCancellation(error) ? 'cancelled' : classifyOAuthError(error), error), options.finally);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Log out of the Facebook SDK (best-effort; errors are ignored).
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* Apps that offer Facebook login typically call this alongside the Firebase sign-out, so it lives
|
|
52
|
+
* here to keep the `@capacitor-community/facebook-login` import out of the app.
|
|
53
|
+
* Skips the call when the Facebook SDK has no active session — otherwise `FB.logout()` logs
|
|
54
|
+
* "called without an access token" on web and native rejects for email/password users.
|
|
55
|
+
*/
|
|
56
|
+
const kitFacebookLogout = async () => {
|
|
57
|
+
const session = await FacebookLogin.getCurrentAccessToken().catch(() => null);
|
|
58
|
+
if (!session?.accessToken?.token) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
await FacebookLogin.logout().catch(() => undefined);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Generated bundle index. Do not edit.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
export { kitFacebookLogin, kitFacebookLogout };
|
|
69
|
+
//# sourceMappingURL=rdlabo-ionic-angular-kit-auth-firebase-facebook.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rdlabo-ionic-angular-kit-auth-firebase-facebook.mjs","sources":["../../../projects/kit/auth-firebase/facebook/src/kit-facebook.ts","../../../projects/kit/auth-firebase/facebook/src/rdlabo-ionic-angular-kit-auth-firebase-facebook.ts"],"sourcesContent":["import type { Auth, User } from 'firebase/auth';\nimport { FacebookAuthProvider, OAuthProvider } from 'firebase/auth';\nimport { Capacitor } from '@capacitor/core';\nimport { FacebookLogin } from '@capacitor-community/facebook-login';\nimport {\n applyOAuthCredential,\n assertCurrentUser,\n classifyOAuthError,\n runOAuthOperation,\n} from '@rdlabo/ionic-angular-kit/auth-firebase/internal';\nimport type { KitOAuthMode, KitOAuthModeName, KitSocialHooks } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';\n\n/** Facebook login options. Permissions and app effects are owned by the consumer. */\nexport type KitFacebookLoginOptions = KitOAuthMode &\n KitSocialHooks<{ accessToken: string; mode: KitOAuthModeName; user: User }> & {\n permissions: string[];\n };\n\nconst generateNonce = (): string =>\n Array.from(crypto.getRandomValues(new Uint8Array(16)), (value) => value.toString(16).padStart(2, '0')).join('');\n\n/** Await one animation frame where available (iOS WebView crash workaround; no-op off-browser). */\nconst nextFrame = (): Promise<void> =>\n new Promise<void>((resolve) => {\n if (typeof requestAnimationFrame === 'function') {\n requestAnimationFrame(() => resolve());\n } else {\n resolve();\n }\n });\n\n/** Web plugin cancellation shape: the login promise rejects with a response whose token is null. */\nconst isFacebookCancellation = (error: unknown): boolean => {\n if (typeof error !== 'object' || error === null || !('accessToken' in error)) {\n return false;\n }\n const { accessToken } = error;\n if (typeof accessToken !== 'object' || accessToken === null || !('token' in accessToken)) {\n return false;\n }\n return accessToken.token === null;\n};\n\n/** Facebook login/link with a pinned Firebase user and classified failure hooks. */\nexport const kitFacebookLogin = async (auth: Auth, options: KitFacebookLoginOptions): Promise<{ status: boolean }> => {\n const expectedUser = auth.currentUser;\n const execute = async (): Promise<void> => {\n await options.before?.();\n assertCurrentUser(auth, expectedUser);\n const nonce = generateNonce();\n const event = await FacebookLogin.login({ permissions: options.permissions, nonce }).finally(nextFrame);\n if (!event?.accessToken?.token) throw Object.assign(new Error('Facebook login cancelled'), { code: 'auth/user-cancelled' });\n const accessToken = event.accessToken.token;\n const credential =\n Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'ios'\n ? new OAuthProvider('facebook.com').credential({ rawNonce: nonce, idToken: accessToken })\n : FacebookAuthProvider.credential(accessToken);\n const user = await applyOAuthCredential(auth, credential, options, expectedUser);\n await options.success?.({ accessToken, mode: options.mode, user });\n assertCurrentUser(auth, user);\n };\n return runOAuthOperation(\n auth,\n execute,\n (error) => options.error?.(isFacebookCancellation(error) ? 'cancelled' : classifyOAuthError(error), error),\n options.finally,\n );\n};\n\n/**\n * Log out of the Facebook SDK (best-effort; errors are ignored).\n *\n * @remarks\n * Apps that offer Facebook login typically call this alongside the Firebase sign-out, so it lives\n * here to keep the `@capacitor-community/facebook-login` import out of the app.\n * Skips the call when the Facebook SDK has no active session — otherwise `FB.logout()` logs\n * \"called without an access token\" on web and native rejects for email/password users.\n */\nexport const kitFacebookLogout = async (): Promise<void> => {\n const session = await FacebookLogin.getCurrentAccessToken().catch(() => null);\n if (!session?.accessToken?.token) {\n return;\n }\n await FacebookLogin.logout().catch(() => undefined);\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,aAAa,GAAG,MACpB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AAEjH;AACA,MAAM,SAAS,GAAG,MAChB,IAAI,OAAO,CAAO,CAAC,OAAO,KAAI;AAC5B,IAAA,IAAI,OAAO,qBAAqB,KAAK,UAAU,EAAE;AAC/C,QAAA,qBAAqB,CAAC,MAAM,OAAO,EAAE,CAAC;IACxC;SAAO;AACL,QAAA,OAAO,EAAE;IACX;AACF,CAAC,CAAC;AAEJ;AACA,MAAM,sBAAsB,GAAG,CAAC,KAAc,KAAa;AACzD,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,K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,UAAU,CAAC,WAAW,CAAC;AAClD,QAAA,MAAM,IAAI,GAAG,MAAM,oBAAoB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC;AAChF,QAAA,MAAM,OAAO,CAAC,OAAO,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;AAClE,QAAA,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;AAC/B,IAAA,CAAC;AACD,IAAA,OAAO,iBAAiB,CACtB,IAAI,EACJ,OAAO,EACP,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,GAAG,sBAAsB,CAAC,KAAK,CAAC,GAAG,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,EAC1G,OAAO,CAAC,OAAO,CAChB;AACH;AAEA;;;;;;;;AAQG;AACI,MAAM,iBAAiB,GAAG,YAA0B;AACzD,IAAA,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,qBAAqB,EAAE,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC;AAC7E,IAAA,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE;QAChC;IACF;AACA,IAAA,MAAM,aAAa,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,MAAM,SAAS,CAAC;AACrD;;ACpFA;;AAEG;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GoogleSignIn, ErrorCode } from '@capawesome/capacitor-google-sign-in';
|
|
2
2
|
import { Capacitor } from '@capacitor/core';
|
|
3
|
+
import { classifyOAuthError, assertCurrentUser, requireUser, runOAuthOperation } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';
|
|
3
4
|
import { GoogleAuthProvider, reauthenticateWithPopup, linkWithCredential, EmailAuthProvider, signInWithPopup, linkWithPopup, signInWithCredential, reauthenticateWithCredential } from 'firebase/auth';
|
|
4
5
|
|
|
5
6
|
let initialization;
|
|
@@ -17,37 +18,22 @@ const initialize = (clientId) => {
|
|
|
17
18
|
initialization = { clientId, promise };
|
|
18
19
|
return promise;
|
|
19
20
|
};
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const assertCurrentUser = (auth, user) => {
|
|
26
|
-
if (auth.currentUser !== user) {
|
|
27
|
-
throw new Error('kit Google login: Firebase user changed');
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const classify = (error) => {
|
|
31
|
-
const code = error?.code;
|
|
32
|
-
if (code === 'auth/credential-already-in-use')
|
|
33
|
-
return 'already-in-use';
|
|
34
|
-
if (code === ErrorCode.SignInCanceled ||
|
|
35
|
-
code === 'auth/user-cancelled' ||
|
|
36
|
-
code === 'auth/popup-closed-by-user' ||
|
|
37
|
-
code === 'auth/cancelled-popup-request')
|
|
38
|
-
return 'cancelled';
|
|
39
|
-
return 'other';
|
|
40
|
-
};
|
|
21
|
+
const classify = (error) => error?.code === ErrorCode.SignInCanceled ? 'cancelled' : classifyOAuthError(error);
|
|
22
|
+
/** Google popup/native authentication with pinned users and app-owned exchange/feedback hooks.
|
|
23
|
+
* Failures in before/exchange/success are reported to error and return status:false.
|
|
24
|
+
* finally always runs; failures in error/finally themselves reject the call.
|
|
25
|
+
*/
|
|
41
26
|
const kitGoogleLogin = async (auth, options) => {
|
|
27
|
+
const expectedUser = auth.currentUser;
|
|
42
28
|
const execute = async () => {
|
|
43
29
|
await options.before?.();
|
|
44
|
-
|
|
30
|
+
assertCurrentUser(auth, expectedUser);
|
|
45
31
|
let idToken;
|
|
46
32
|
let user;
|
|
47
33
|
if (Capacitor.getPlatform() === 'web') {
|
|
48
34
|
const provider = new GoogleAuthProvider();
|
|
49
35
|
if (options.mode === 'reauthenticate') {
|
|
50
|
-
user = requireUser(
|
|
36
|
+
user = requireUser(expectedUser);
|
|
51
37
|
const result = await reauthenticateWithPopup(user, provider);
|
|
52
38
|
idToken = GoogleAuthProvider.credentialFromResult(result)?.idToken ?? '';
|
|
53
39
|
assertCurrentUser(auth, user);
|
|
@@ -56,7 +42,7 @@ const kitGoogleLogin = async (auth, options) => {
|
|
|
56
42
|
return;
|
|
57
43
|
}
|
|
58
44
|
if (options.mode === 'credential') {
|
|
59
|
-
user = requireUser(
|
|
45
|
+
user = requireUser(expectedUser);
|
|
60
46
|
await reauthenticateWithPopup(user, provider);
|
|
61
47
|
assertCurrentUser(auth, user);
|
|
62
48
|
await linkWithCredential(user, EmailAuthProvider.credential(options.emailLogin.email, options.emailLogin.password));
|
|
@@ -65,7 +51,7 @@ const kitGoogleLogin = async (auth, options) => {
|
|
|
65
51
|
assertCurrentUser(auth, user);
|
|
66
52
|
return;
|
|
67
53
|
}
|
|
68
|
-
const result = options.mode === 'new' ? await signInWithPopup(auth, provider) : await linkWithPopup(requireUser(
|
|
54
|
+
const result = options.mode === 'new' ? await signInWithPopup(auth, provider) : await linkWithPopup(requireUser(expectedUser), provider);
|
|
69
55
|
const credential = GoogleAuthProvider.credentialFromResult(result);
|
|
70
56
|
if (!credential?.idToken)
|
|
71
57
|
throw new Error('kit Google login: ID token is missing');
|
|
@@ -75,13 +61,12 @@ const kitGoogleLogin = async (auth, options) => {
|
|
|
75
61
|
else {
|
|
76
62
|
await initialize(options.clientId);
|
|
77
63
|
idToken = (await GoogleSignIn.signIn()).idToken;
|
|
64
|
+
assertCurrentUser(auth, expectedUser);
|
|
78
65
|
const credential = GoogleAuthProvider.credential(idToken);
|
|
79
66
|
if (options.mode === 'new')
|
|
80
67
|
user = (await signInWithCredential(auth, credential)).user;
|
|
81
68
|
else {
|
|
82
|
-
user = requireUser(
|
|
83
|
-
if (user !== expectedUser)
|
|
84
|
-
throw new Error('kit Google login: Firebase user changed');
|
|
69
|
+
user = requireUser(expectedUser);
|
|
85
70
|
if (options.mode === 'link')
|
|
86
71
|
await linkWithCredential(user, credential);
|
|
87
72
|
else if (options.mode === 'reauthenticate') {
|
|
@@ -108,13 +93,9 @@ const kitGoogleLogin = async (auth, options) => {
|
|
|
108
93
|
await options.success?.({ idToken, mode: options.mode, user });
|
|
109
94
|
assertCurrentUser(auth, user);
|
|
110
95
|
};
|
|
111
|
-
return execute()
|
|
112
|
-
.then(() => ({ status: true }), async (error) => {
|
|
113
|
-
await options.error?.(classify(error), error);
|
|
114
|
-
return { status: false };
|
|
115
|
-
})
|
|
116
|
-
.finally(() => options.finally?.());
|
|
96
|
+
return runOAuthOperation(auth, execute, (error) => options.error?.(classify(error), error), options.finally);
|
|
117
97
|
};
|
|
98
|
+
/** Best-effort native Google SDK sign-out. */
|
|
118
99
|
const kitGoogleLogout = () => GoogleSignIn.signOut().catch(() => undefined);
|
|
119
100
|
|
|
120
101
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rdlabo-ionic-angular-kit-auth-firebase-google.mjs","sources":["../../../projects/kit/auth-firebase/google/src/kit-google.ts","../../../projects/kit/auth-firebase/google/src/rdlabo-ionic-angular-kit-auth-firebase-google.ts"],"sourcesContent":["import { ErrorCode, GoogleSignIn } from '@capawesome/capacitor-google-sign-in';\nimport { Capacitor } from '@capacitor/core';\nimport type { Auth, User } from 'firebase/auth';\nimport {\n EmailAuthProvider,\n GoogleAuthProvider,\n linkWithCredential,\n linkWithPopup,\n reauthenticateWithCredential,\n reauthenticateWithPopup,\n signInWithCredential,\n signInWithPopup,\n} from 'firebase/auth';\n\nexport type KitGoogleLoginMode =\n | { mode: 'new' }\n | { mode: 'link' }\n | { mode: 'reauthenticate' }\n | { mode: 'credential'; emailLogin: { email: string; password: string } };\nexport type KitGoogleErrorCategory = 'already-in-use' | 'cancelled' | 'other';\nexport type KitGoogleLoginOptions = KitGoogleLoginMode & {\n clientId: string;\n before?: () => void | Promise<unknown>;\n exchange?: (idToken: string, user: User) => void | Promise<unknown>;\n success?: (info: { idToken: string; mode: KitGoogleLoginMode['mode']; user: User }) => void | Promise<unknown>;\n error?: (category: KitGoogleErrorCategory, error: unknown) => void | Promise<unknown>;\n finally?: () => void | Promise<unknown>;\n};\n\nlet initialization: { clientId: string; promise: Promise<void> } | undefined;\nconst initialize = (clientId: string): Promise<void> => {\n if (!clientId) {\n return Promise.reject(new Error('kit Google login: client ID is not configured'));\n }\n if (initialization?.clientId === clientId) return initialization.promise;\n const promise = GoogleSignIn.initialize({ clientId }).catch((error: unknown) => {\n if (initialization?.promise === promise) initialization = undefined;\n throw error;\n });\n initialization = { clientId, promise };\n return promise;\n};\n\nconst requireUser = (auth: Auth): User => {\n if (!auth.currentUser) throw new Error('kit Google login: no signed-in Firebase user');\n return auth.currentUser;\n};\n\nconst assertCurrentUser = (auth: Auth, user: User): void => {\n if (auth.currentUser !== user) {\n throw new Error('kit Google login: Firebase user changed');\n }\n};\n\nconst classify = (error: unknown): KitGoogleErrorCategory => {\n const code = (error as { code?: string } | null)?.code;\n if (code === 'auth/credential-already-in-use') return 'already-in-use';\n if (\n code === ErrorCode.SignInCanceled ||\n code === 'auth/user-cancelled' ||\n code === 'auth/popup-closed-by-user' ||\n code === 'auth/cancelled-popup-request'\n )\n return 'cancelled';\n return 'other';\n};\n\nexport const kitGoogleLogin = async (auth: Auth, options: KitGoogleLoginOptions): Promise<{ status: boolean }> => {\n const execute = async (): Promise<void> => {\n await options.before?.();\n const expectedUser = auth.currentUser;\n let idToken: string;\n let user: User;\n if (Capacitor.getPlatform() === 'web') {\n const provider = new GoogleAuthProvider();\n if (options.mode === 'reauthenticate') {\n user = requireUser(auth);\n const result = await reauthenticateWithPopup(user, provider);\n idToken = GoogleAuthProvider.credentialFromResult(result)?.idToken ?? '';\n assertCurrentUser(auth, user);\n await options.success?.({ idToken, mode: options.mode, user });\n assertCurrentUser(auth, user);\n return;\n }\n if (options.mode === 'credential') {\n user = requireUser(auth);\n await reauthenticateWithPopup(user, provider);\n assertCurrentUser(auth, user);\n await linkWithCredential(user, EmailAuthProvider.credential(options.emailLogin.email, options.emailLogin.password));\n assertCurrentUser(auth, user);\n await options.success?.({ idToken: '', mode: options.mode, user });\n assertCurrentUser(auth, user);\n return;\n }\n const result = options.mode === 'new' ? await signInWithPopup(auth, provider) : await linkWithPopup(requireUser(auth), provider);\n const credential = GoogleAuthProvider.credentialFromResult(result);\n if (!credential?.idToken) throw new Error('kit Google login: ID token is missing');\n idToken = credential.idToken;\n user = result.user;\n } else {\n await initialize(options.clientId);\n idToken = (await GoogleSignIn.signIn()).idToken;\n const credential = GoogleAuthProvider.credential(idToken);\n if (options.mode === 'new') user = (await signInWithCredential(auth, credential)).user;\n else {\n user = requireUser(auth);\n if (user !== expectedUser) throw new Error('kit Google login: Firebase user changed');\n if (options.mode === 'link') await linkWithCredential(user, credential);\n else if (options.mode === 'reauthenticate') {\n await reauthenticateWithCredential(user, credential);\n assertCurrentUser(auth, user);\n await options.success?.({ idToken, mode: options.mode, user });\n assertCurrentUser(auth, user);\n return;\n } else {\n await reauthenticateWithCredential(user, credential);\n assertCurrentUser(auth, user);\n await linkWithCredential(user, EmailAuthProvider.credential(options.emailLogin.email, options.emailLogin.password));\n assertCurrentUser(auth, user);\n await options.success?.({ idToken, mode: options.mode, user });\n assertCurrentUser(auth, user);\n return;\n }\n }\n }\n assertCurrentUser(auth, user);\n await options.exchange?.(idToken, user);\n assertCurrentUser(auth, user);\n await options.success?.({ idToken, mode: options.mode, user });\n assertCurrentUser(auth, user);\n };\n return execute()\n .then(\n () => ({ status: true }),\n async (error: unknown) => {\n await options.error?.(classify(error), error);\n return { status: false };\n },\n )\n .finally(() => options.finally?.());\n};\n\nexport const kitGoogleLogout = (): Promise<void> => GoogleSignIn.signOut().catch(() => undefined);\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AA6BA,IAAI,cAAwE;AAC5E,MAAM,UAAU,GAAG,CAAC,QAAgB,KAAmB;IACrD,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnF;AACA,IAAA,I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EAAE,KAAK,CAAC;AAC7C,QAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE;AAC1B,IAAA,CAAC;SAEF,OAAO,CAAC,MAAM,OAAO,CAAC,OAAO,IAAI,CAAC;AACvC;AAEO,MAAM,eAAe,GAAG,MAAqB,YAAY,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,MAAM,SAAS;;AC9IhG;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"rdlabo-ionic-angular-kit-auth-firebase-google.mjs","sources":["../../../projects/kit/auth-firebase/google/src/kit-google.ts","../../../projects/kit/auth-firebase/google/src/rdlabo-ionic-angular-kit-auth-firebase-google.ts"],"sourcesContent":["import { ErrorCode, GoogleSignIn } from '@capawesome/capacitor-google-sign-in';\nimport { Capacitor } from '@capacitor/core';\nimport { assertCurrentUser, classifyOAuthError, requireUser, runOAuthOperation } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';\nimport type { KitOAuthErrorCategory } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';\nimport type { Auth, User } from 'firebase/auth';\nimport {\n EmailAuthProvider,\n GoogleAuthProvider,\n linkWithCredential,\n linkWithPopup,\n reauthenticateWithCredential,\n reauthenticateWithPopup,\n signInWithCredential,\n signInWithPopup,\n} from 'firebase/auth';\n\n/** Sign in, link Google, reauthenticate, or add email/password after reauthentication. */\nexport type KitGoogleLoginMode =\n | { mode: 'new' }\n | { mode: 'link' }\n | { mode: 'reauthenticate' }\n | { mode: 'credential'; emailLogin: { email: string; password: string } };\n/** App-facing Google authentication error category. */\nexport type KitGoogleErrorCategory = KitOAuthErrorCategory;\n/** Google login configuration. exchange runs for new/link; hooks receive the authenticated user. */\nexport type KitGoogleLoginOptions = KitGoogleLoginMode & {\n clientId: string;\n before?: () => void | Promise<unknown>;\n exchange?: (idToken: string, user: User) => void | Promise<unknown>;\n success?: (info: { idToken: string; mode: KitGoogleLoginMode['mode']; user: User }) => void | Promise<unknown>;\n error?: (category: KitGoogleErrorCategory, error: unknown) => void | Promise<unknown>;\n finally?: () => void | Promise<unknown>;\n};\n\nlet initialization: { clientId: string; promise: Promise<void> } | undefined;\nconst initialize = (clientId: string): Promise<void> => {\n if (!clientId) {\n return Promise.reject(new Error('kit Google login: client ID is not configured'));\n }\n if (initialization?.clientId === clientId) return initialization.promise;\n const promise = GoogleSignIn.initialize({ clientId }).catch((error: unknown) => {\n if (initialization?.promise === promise) initialization = undefined;\n throw error;\n });\n initialization = { clientId, promise };\n return promise;\n};\n\nconst classify = (error: unknown): KitGoogleErrorCategory =>\n (error as { code?: string } | null)?.code === ErrorCode.SignInCanceled ? 'cancelled' : classifyOAuthError(error);\n\n/** Google popup/native authentication with pinned users and app-owned exchange/feedback hooks.\n * Failures in before/exchange/success are reported to error and return status:false.\n * finally always runs; failures in error/finally themselves reject the call.\n */\nexport const kitGoogleLogin = async (auth: Auth, options: KitGoogleLoginOptions): Promise<{ status: boolean }> => {\n const expectedUser = auth.currentUser;\n const execute = async (): Promise<void> => {\n await options.before?.();\n assertCurrentUser(auth, expectedUser);\n let idToken: string;\n let user: User;\n if (Capacitor.getPlatform() === 'web') {\n const provider = new GoogleAuthProvider();\n if (options.mode === 'reauthenticate') {\n user = requireUser(expectedUser);\n const result = await reauthenticateWithPopup(user, provider);\n idToken = GoogleAuthProvider.credentialFromResult(result)?.idToken ?? '';\n assertCurrentUser(auth, user);\n await options.success?.({ idToken, mode: options.mode, user });\n assertCurrentUser(auth, user);\n return;\n }\n if (options.mode === 'credential') {\n user = requireUser(expectedUser);\n await reauthenticateWithPopup(user, provider);\n assertCurrentUser(auth, user);\n await linkWithCredential(user, EmailAuthProvider.credential(options.emailLogin.email, options.emailLogin.password));\n assertCurrentUser(auth, user);\n await options.success?.({ idToken: '', mode: options.mode, user });\n assertCurrentUser(auth, user);\n return;\n }\n const result =\n options.mode === 'new' ? await signInWithPopup(auth, provider) : await linkWithPopup(requireUser(expectedUser), provider);\n const credential = GoogleAuthProvider.credentialFromResult(result);\n if (!credential?.idToken) throw new Error('kit Google login: ID token is missing');\n idToken = credential.idToken;\n user = result.user;\n } else {\n await initialize(options.clientId);\n idToken = (await GoogleSignIn.signIn()).idToken;\n assertCurrentUser(auth, expectedUser);\n const credential = GoogleAuthProvider.credential(idToken);\n if (options.mode === 'new') user = (await signInWithCredential(auth, credential)).user;\n else {\n user = requireUser(expectedUser);\n if (options.mode === 'link') await linkWithCredential(user, credential);\n else if (options.mode === 'reauthenticate') {\n await reauthenticateWithCredential(user, credential);\n assertCurrentUser(auth, user);\n await options.success?.({ idToken, mode: options.mode, user });\n assertCurrentUser(auth, user);\n return;\n } else {\n await reauthenticateWithCredential(user, credential);\n assertCurrentUser(auth, user);\n await linkWithCredential(user, EmailAuthProvider.credential(options.emailLogin.email, options.emailLogin.password));\n assertCurrentUser(auth, user);\n await options.success?.({ idToken, mode: options.mode, user });\n assertCurrentUser(auth, user);\n return;\n }\n }\n }\n assertCurrentUser(auth, user);\n await options.exchange?.(idToken, user);\n assertCurrentUser(auth, user);\n await options.success?.({ idToken, mode: options.mode, user });\n assertCurrentUser(auth, user);\n };\n return runOAuthOperation(auth, execute, (error) => options.error?.(classify(error), error), options.finally);\n};\n\n/** Best-effort native Google SDK sign-out. */\nexport const kitGoogleLogout = (): Promise<void> => GoogleSignIn.signOut().catch(() => undefined);\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAkCA,IAAI,cAAwE;AAC5E,MAAM,UAAU,GAAG,CAAC,QAAgB,KAAmB;IACrD,IAAI,CAAC,QAAQ,EAAE;QACb,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnF;AACA,IAAA,IAAI,cAAc,EAAE,QAAQ,KAAK,QAAQ;QAAE,OAAO,cAAc,CAAC,OAAO;AACxE,IAAA,MAAM,OAAO,GAAG,YAAY,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC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iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;QAC7B,MAAM,OAAO,CAAC,QAAQ,GAAG,OAAO,EAAE,IAAI,CAAC;AACvC,QAAA,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;AAC7B,QAAA,MAAM,OAAO,CAAC,OAAO,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC;AAC9D,QAAA,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;AAC/B,IAAA,CAAC;AACD,IAAA,OAAO,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC;AAC9G;AAEA;AACO,MAAM,eAAe,GAAG,MAAqB,YAAY,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,MAAM,SAAS;;AC7HhG;;AAEG;;;;"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { signInWithCredential, linkWithCredential, reauthenticateWithCredential, EmailAuthProvider } from 'firebase/auth';
|
|
2
|
+
|
|
3
|
+
const activeOperations = new WeakSet();
|
|
4
|
+
/** @internal Reject overlapping kit social flows for one Auth, including across providers.
|
|
5
|
+
* Holds the guard through error/finally hooks and releases it even when a hook rejects.
|
|
6
|
+
* Direct Firebase operations outside these helpers must be coordinated by the application.
|
|
7
|
+
*/
|
|
8
|
+
const runOAuthOperation = (auth, operation, onError, onFinally) => {
|
|
9
|
+
const busy = activeOperations.has(auth);
|
|
10
|
+
if (!busy)
|
|
11
|
+
activeOperations.add(auth);
|
|
12
|
+
const execute = async () => {
|
|
13
|
+
if (busy)
|
|
14
|
+
throw new Error('kit social: authentication already in progress');
|
|
15
|
+
await operation();
|
|
16
|
+
};
|
|
17
|
+
return execute()
|
|
18
|
+
.then(() => ({ status: true }), async (error) => {
|
|
19
|
+
await onError(error);
|
|
20
|
+
return { status: false };
|
|
21
|
+
})
|
|
22
|
+
.finally(() => onFinally?.())
|
|
23
|
+
.finally(() => {
|
|
24
|
+
if (!busy)
|
|
25
|
+
activeOperations.delete(auth);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
/** @internal Classify Firebase SDK failures without inspecting localized messages. */
|
|
29
|
+
const classifyOAuthError = (error) => {
|
|
30
|
+
const code = error?.code;
|
|
31
|
+
if (code === 'auth/credential-already-in-use')
|
|
32
|
+
return 'already-in-use';
|
|
33
|
+
if (code === 'auth/user-cancelled' || code === 'auth/popup-closed-by-user' || code === 'auth/cancelled-popup-request')
|
|
34
|
+
return 'cancelled';
|
|
35
|
+
return 'other';
|
|
36
|
+
};
|
|
37
|
+
/** @internal Require the identity captured at the start of a linking operation. */
|
|
38
|
+
const requireUser = (user) => {
|
|
39
|
+
if (!user)
|
|
40
|
+
throw new Error('kit social: no signed-in user to link/re-authenticate');
|
|
41
|
+
return user;
|
|
42
|
+
};
|
|
43
|
+
/** @internal Abort follow-up effects if the Firebase identity changed during an await. */
|
|
44
|
+
const assertCurrentUser = (auth, expectedUser) => {
|
|
45
|
+
if (auth.currentUser !== expectedUser)
|
|
46
|
+
throw new Error('kit social: Firebase user changed');
|
|
47
|
+
};
|
|
48
|
+
/** @internal Apply a provider credential to the captured user and return the authenticated identity. */
|
|
49
|
+
const applyOAuthCredential = async (auth, credential, mode, expectedUser) => {
|
|
50
|
+
assertCurrentUser(auth, expectedUser);
|
|
51
|
+
if (mode.mode === 'new') {
|
|
52
|
+
const { user } = await signInWithCredential(auth, credential);
|
|
53
|
+
assertCurrentUser(auth, user);
|
|
54
|
+
return user;
|
|
55
|
+
}
|
|
56
|
+
const user = requireUser(expectedUser);
|
|
57
|
+
if (mode.mode === 'link')
|
|
58
|
+
await linkWithCredential(user, credential);
|
|
59
|
+
else {
|
|
60
|
+
await reauthenticateWithCredential(user, credential);
|
|
61
|
+
assertCurrentUser(auth, user);
|
|
62
|
+
await linkWithCredential(user, EmailAuthProvider.credential(mode.emailLogin.email, mode.emailLogin.password));
|
|
63
|
+
}
|
|
64
|
+
assertCurrentUser(auth, user);
|
|
65
|
+
return user;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** @internal Shared implementation for kit auth entry points. Not a supported application API. */
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Generated bundle index. Do not edit.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
export { applyOAuthCredential, assertCurrentUser, classifyOAuthError, requireUser, runOAuthOperation };
|
|
75
|
+
//# sourceMappingURL=rdlabo-ionic-angular-kit-auth-firebase-internal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rdlabo-ionic-angular-kit-auth-firebase-internal.mjs","sources":["../../../projects/kit/auth-firebase/internal/src/kit-oauth.ts","../../../projects/kit/auth-firebase/internal/src/public-api.ts","../../../projects/kit/auth-firebase/internal/src/rdlabo-ionic-angular-kit-auth-firebase-internal.ts"],"sourcesContent":["import type { Auth, AuthCredential, User } from 'firebase/auth';\nimport { EmailAuthProvider, linkWithCredential, reauthenticateWithCredential, signInWithCredential } from 'firebase/auth';\n\n/** The app-facing classification of a social authentication failure. */\nexport type KitOAuthErrorCategory = 'already-in-use' | 'cancelled' | 'other';\n/** Sign in, link a provider, or reauthenticate before adding email/password login. */\nexport type KitOAuthMode = { mode: 'new' } | { mode: 'link' } | { mode: 'credential'; emailLogin: { email: string; password: string } };\n/** The discriminator of a social authentication operation. */\nexport type KitOAuthModeName = KitOAuthMode['mode'];\n\n/** App-owned effects. Failures in before/success are reported to error; finally always runs.\n * A handled failure returns status:false. A failure in error/finally itself rejects the call.\n */\nexport interface KitSocialHooks<Info> {\n before?: () => void | Promise<unknown>;\n success?: (info: Info) => void | Promise<unknown>;\n error?: (category: KitOAuthErrorCategory, error: unknown) => void | Promise<unknown>;\n finally?: () => void | Promise<unknown>;\n}\n\nconst activeOperations = new WeakSet<Auth>();\n\n/** @internal Reject overlapping kit social flows for one Auth, including across providers.\n * Holds the guard through error/finally hooks and releases it even when a hook rejects.\n * Direct Firebase operations outside these helpers must be coordinated by the application.\n */\nexport const runOAuthOperation = (\n auth: Auth,\n operation: () => Promise<void>,\n onError: (error: unknown) => void | Promise<unknown>,\n onFinally?: () => void | Promise<unknown>,\n): Promise<{ status: boolean }> => {\n const busy = activeOperations.has(auth);\n if (!busy) activeOperations.add(auth);\n const execute = async (): Promise<void> => {\n if (busy) throw new Error('kit social: authentication already in progress');\n await operation();\n };\n return execute()\n .then(\n () => ({ status: true }),\n async (error: unknown) => {\n await onError(error);\n return { status: false };\n },\n )\n .finally(() => onFinally?.())\n .finally(() => {\n if (!busy) activeOperations.delete(auth);\n });\n};\n\n/** @internal Classify Firebase SDK failures without inspecting localized messages. */\nexport const classifyOAuthError = (error: unknown): KitOAuthErrorCategory => {\n const code = (error as { code?: string | number } | null)?.code;\n if (code === 'auth/credential-already-in-use') return 'already-in-use';\n if (code === 'auth/user-cancelled' || code === 'auth/popup-closed-by-user' || code === 'auth/cancelled-popup-request') return 'cancelled';\n return 'other';\n};\n\n/** @internal Require the identity captured at the start of a linking operation. */\nexport const requireUser = (user: User | null): User => {\n if (!user) throw new Error('kit social: no signed-in user to link/re-authenticate');\n return user;\n};\n\n/** @internal Abort follow-up effects if the Firebase identity changed during an await. */\nexport const assertCurrentUser = (auth: Auth, expectedUser: User | null): void => {\n if (auth.currentUser !== expectedUser) throw new Error('kit social: Firebase user changed');\n};\n\n/** @internal Apply a provider credential to the captured user and return the authenticated identity. */\nexport const applyOAuthCredential = async (\n auth: Auth,\n credential: AuthCredential,\n mode: KitOAuthMode,\n expectedUser: User | null,\n): Promise<User> => {\n assertCurrentUser(auth, expectedUser);\n if (mode.mode === 'new') {\n const { user } = await signInWithCredential(auth, credential);\n assertCurrentUser(auth, user);\n return user;\n }\n const user = requireUser(expectedUser);\n if (mode.mode === 'link') await linkWithCredential(user, credential);\n else {\n await reauthenticateWithCredential(user, credential);\n assertCurrentUser(auth, user);\n await linkWithCredential(user, EmailAuthProvider.credential(mode.emailLogin.email, mode.emailLogin.password));\n }\n assertCurrentUser(auth, user);\n return user;\n};\n","/** @internal Shared implementation for kit auth entry points. Not a supported application API. */\nexport * from './kit-oauth';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;AAoBA,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAQ;AAE5C;;;AAGG;AACI,MAAM,iBAAiB,GAAG,CAC/B,IAAU,EACV,SAA8B,EAC9B,OAAoD,EACpD,SAAyC,KACT;IAChC,MAAM,IAAI,GAAG,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC;AACvC,IAAA,IAAI,CAAC,IAAI;AAAE,QAAA,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC;AACrC,IAAA,MAAM,OAAO,GAAG,YAA0B;AACxC,QAAA,IAAI,IAAI;AAAE,YAAA,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC;QAC3E,MAAM,SAAS,EAAE;AACnB,IAAA,CAAC;AACD,IAAA,OAAO,OAAO;AACX,SAAA,IAAI,CACH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EACxB,OAAO,KAAc,KAAI;AACvB,QAAA,MAAM,OAAO,CAAC,KAAK,CAAC;AACpB,QAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE;AAC1B,IAAA,CAAC;AAEF,SAAA,OAAO,CAAC,MAAM,SAAS,IAAI;SAC3B,OAAO,CAAC,MAAK;AACZ,QAAA,IAAI,CAAC,IAAI;AAAE,YAAA,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC;AAC1C,IAAA,CAAC,CAAC;AACN;AAEA;AACO,MAAM,kBAAkB,GAAG,CAAC,KAAc,KAA2B;AAC1E,IAAA,MAAM,IAAI,GAAI,KAA2C,EAAE,IAAI;IAC/D,IAAI,IAAI,KAAK,gCAAgC;AAAE,QAAA,OAAO,gB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