@rdlabo/ionic-angular-kit 22.0.1 → 22.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/README.md +19 -13
- 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/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/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
|
|
|
@@ -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,kBAA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AC7C;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 ed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M,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,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,KAAc,KAAI;AAC7E,QAAA,IAAI,cAAc,EAAE,OAAO,KAAK,OAAO;YAAE,cAAc,GAAG,SAAS;AACnE,QAAA,MAAM,KAAK;AACb,IAAA,CAAC,CAAC;AACF,IAAA,cAAc,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE;AACtC,IAAA,OAAO,OAAO;AAChB,CAAC;AAED,MAAM,WAAW,GAAG,CAAC,IAAU,KAAU;IACvC,IAAI,CAAC,IAAI,CAAC,WAAW;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;IACtF,OAAO,IAAI,CAAC,WAAW;AACzB,CAAC;AAED,MAAM,iBAAiB,GAAG,CAAC,IAA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IAAI,EAAE,IAAI,EAAE,CAAC;AAC9D,oBAAA,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;oBAC7B;gBACF;YACF;QACF;AACA,QAAA,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,OAAO;AACX,SAAA,IAAI,CACH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EACxB,OAAO,KAAc,KAAI;AACvB,QAAA,MAAM,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,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,KAAc,KAAI;AAC7E,QAAA,IAAI,cAAc,EAAE,OAAO,KAAK,OAAO;YAAE,cAAc,GAAG,SAAS;AACnE,QAAA,MAAM,KAAK;AACb,IAAA,CAAC,CAAC;AACF,IAAA,cAAc,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE;AACtC,IAAA,OAAO,OAAO;AAChB,CAAC;AAED,MAAM,QAAQ,GAAG,CAAC,KAAc,KAC7B,KAAkC,EAAE,IAAI,KAAK,SAAS,CAAC,cAAc,GAAG,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC;AAElH;;;AAGG;AACI,MAAM,cAAc,GAAG,OAAO,IAAU,EAAE,OAA8B,KAAkC;AAC/G,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,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M,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,M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,CAAC;AACrC,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE;QACvB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC;AAC7D,QAAA,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;AAC7B,QAAA,OAAO,IAAI;IACb;AACA,IAAA,MAAM,IAAI,GAAG,WAAW,CAAC,YAAY,CAAC;AACtC,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;AAAE,QAAA,MAAM,kBAAkB,CAAC,IAAI,EAAE,UAAU,CAAC;SAC/D;AACH,QAAA,MAAM,4BAA4B,CAAC,IAAI,EAAE,UAAU,CAAC;AACpD,QAAA,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;QAC7B,MAAM,kBAAkB,CAAC,IAAI,EAAE,iBAAiB,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC/G;AACA,IAAA,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC;AAC7B,IAAA,OAAO,IAAI;AACb;;AC7FA;;ACAA;;AAEG;;;;"}
|
|
@@ -1,226 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { FacebookLogin } from '@capacitor-community/facebook-login';
|
|
4
|
-
import { SignInWithApple } from '@capacitor-community/apple-sign-in';
|
|
1
|
+
import { kitAppleLogin as kitAppleLogin$1 } from '@rdlabo/ionic-angular-kit/auth-firebase/apple';
|
|
2
|
+
import { kitFacebookLogin as kitFacebookLogin$1, kitFacebookLogout as kitFacebookLogout$1 } from '@rdlabo/ionic-angular-kit/auth-firebase/facebook';
|
|
5
3
|
|
|
6
|
-
/**
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
return nonce;
|
|
14
|
-
};
|
|
15
|
-
const classifyOAuthError = (e) => {
|
|
16
|
-
const code = e?.code;
|
|
17
|
-
if (code === 'auth/credential-already-in-use') {
|
|
18
|
-
return 'already-in-use';
|
|
19
|
-
}
|
|
20
|
-
if (code === 'auth/user-cancelled' || code === 'auth/popup-closed-by-user' || code === 'auth/cancelled-popup-request') {
|
|
21
|
-
return 'cancelled';
|
|
22
|
-
}
|
|
23
|
-
return 'other';
|
|
24
|
-
};
|
|
25
|
-
/** Convert a possibly synchronously-throwing Promise producer into an explicit result. */
|
|
26
|
-
const settle = (operation) => {
|
|
27
|
-
const execute = async () => operation();
|
|
28
|
-
return execute().then((value) => ({ status: 'fulfilled', value }), (reason) => ({ status: 'rejected', reason }));
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* The shared 3-mode credential state machine (internal).
|
|
32
|
-
*
|
|
33
|
-
* @remarks
|
|
34
|
-
* `new` signs in with the credential, `link` links it, `credential` re-authenticates with the social
|
|
35
|
-
* credential and then links an email/password. Any Firebase error is classified and handed to
|
|
36
|
-
* `error` (returning `false`); on success the app's `success` hook (backend + feedback) runs with the
|
|
37
|
-
* identity payload, and it returns `true`.
|
|
38
|
-
*/
|
|
39
|
-
const applyOAuthCredential = async (auth, credential, mode, effects) => {
|
|
40
|
-
const result = await settle(async () => {
|
|
41
|
-
if (mode.mode === 'new') {
|
|
42
|
-
await signInWithCredential(auth, credential);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
const user = auth.currentUser;
|
|
46
|
-
if (!user) {
|
|
47
|
-
throw new Error('kit social: no signed-in user to link/re-authenticate');
|
|
48
|
-
}
|
|
49
|
-
if (mode.mode === 'link') {
|
|
50
|
-
await linkWithCredential(user, credential);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
await reauthenticateWithCredential(user, credential);
|
|
54
|
-
await linkWithCredential(user, EmailAuthProvider.credential(mode.emailLogin.email, mode.emailLogin.password));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
if (result.status === 'rejected') {
|
|
59
|
-
await effects.error(classifyOAuthError(result.reason), result.reason);
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
await effects.success();
|
|
63
|
-
return true;
|
|
64
|
-
};
|
|
65
|
-
/** Await one animation frame where available (iOS WebView crash workaround; no-op off-browser). */
|
|
66
|
-
const nextFrame = () => new Promise((resolve) => {
|
|
67
|
-
if (typeof requestAnimationFrame === 'function') {
|
|
68
|
-
requestAnimationFrame(() => resolve());
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
resolve();
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
/** Web plugin cancellation shape: the login promise rejects with a response whose token is null. */
|
|
75
|
-
const isFacebookCancellation = (error) => {
|
|
76
|
-
if (typeof error !== 'object' || error === null || !('accessToken' in error)) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
const { accessToken } = error;
|
|
80
|
-
if (typeof accessToken !== 'object' || accessToken === null || !('token' in accessToken)) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
return accessToken.token === null;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Facebook login / link, bundled: native plugin → credential → the shared 3-mode state machine.
|
|
87
|
-
*
|
|
88
|
-
* @remarks
|
|
89
|
-
* On iOS the credential is built from the OIDC token with a nonce (`OAuthProvider('facebook.com')`);
|
|
90
|
-
* elsewhere from the access token (`FacebookAuthProvider`). Returns `{ status: false }` on a
|
|
91
|
-
* cancelled/failed plugin login or a handled Firebase error (the app was already notified via the
|
|
92
|
-
* hooks).
|
|
93
|
-
*/
|
|
94
|
-
const kitFacebookLogin = async (auth, options) => {
|
|
95
|
-
const execute = async () => {
|
|
96
|
-
await options.before?.();
|
|
97
|
-
const nonce = generateNonce();
|
|
98
|
-
const login = await settle(() => FacebookLogin.login({ permissions: options.permissions, nonce }));
|
|
99
|
-
await nextFrame();
|
|
100
|
-
if (login.status === 'rejected') {
|
|
101
|
-
if (!isFacebookCancellation(login.reason))
|
|
102
|
-
await options.error?.('other', login.reason);
|
|
103
|
-
return { status: false };
|
|
104
|
-
}
|
|
105
|
-
const event = login.value;
|
|
106
|
-
if (!event?.accessToken?.token)
|
|
107
|
-
return { status: false };
|
|
108
|
-
const accessToken = event.accessToken.token;
|
|
109
|
-
const credential = Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'ios'
|
|
110
|
-
? new OAuthProvider('facebook.com').credential({ rawNonce: nonce, idToken: accessToken })
|
|
111
|
-
: FacebookAuthProvider.credential(accessToken);
|
|
112
|
-
const status = await applyOAuthCredential(auth, credential, options, {
|
|
113
|
-
success: () => options.success?.({ accessToken, mode: options.mode }),
|
|
114
|
-
error: (category, error) => options.error?.(category, error),
|
|
115
|
-
});
|
|
116
|
-
return { status };
|
|
117
|
-
};
|
|
118
|
-
return execute().finally(() => options.finally?.());
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Log out of the Facebook SDK (best-effort; errors are ignored).
|
|
122
|
-
*
|
|
123
|
-
* @remarks
|
|
124
|
-
* Apps that offer Facebook login typically call this alongside the Firebase sign-out, so it lives
|
|
125
|
-
* here to keep the `@capacitor-community/facebook-login` import out of the app.
|
|
126
|
-
* Skips the call when the Facebook SDK has no active session — otherwise `FB.logout()` logs
|
|
127
|
-
* "called without an access token" on web and native rejects for email/password users.
|
|
128
|
-
*/
|
|
129
|
-
const kitFacebookLogout = async () => {
|
|
130
|
-
const session = await FacebookLogin.getCurrentAccessToken().catch(() => null);
|
|
131
|
-
if (!session?.accessToken?.token) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
await FacebookLogin.logout().catch(() => undefined);
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* Sign in with Apple / link, bundled. Native uses the plugin; the web uses the Firebase popup.
|
|
138
|
-
*
|
|
139
|
-
* @remarks
|
|
140
|
-
* - **Native**: `SignInWithApple.authorize()` → `OAuthProvider('apple.com')` credential → the shared
|
|
141
|
-
* 3-mode state machine.
|
|
142
|
-
* - **Web**: `signInWithPopup` / `linkWithPopup` (with `email`/`name` scopes), or, for `credential`,
|
|
143
|
-
* `reauthenticateWithPopup` then link the email/password. The identity payload for the backend is
|
|
144
|
-
* synthesized from the popup result.
|
|
145
|
-
*
|
|
146
|
-
* Every failure path (including popup errors) is routed through `onError`.
|
|
147
|
-
*/
|
|
148
|
-
const kitAppleLogin = async (auth, options) => {
|
|
149
|
-
const execute = async () => {
|
|
150
|
-
await options.before?.();
|
|
151
|
-
if (Capacitor.isNativePlatform()) {
|
|
152
|
-
const authorize = await SignInWithApple.authorize().catch(() => undefined);
|
|
153
|
-
if (!authorize)
|
|
154
|
-
return { status: false };
|
|
155
|
-
const r = authorize.response;
|
|
156
|
-
const response = {
|
|
157
|
-
user: r.user ?? null,
|
|
158
|
-
email: r.email ?? null,
|
|
159
|
-
givenName: r.givenName ?? null,
|
|
160
|
-
familyName: r.familyName ?? null,
|
|
161
|
-
identityToken: r.identityToken ?? null,
|
|
162
|
-
authorizationCode: r.authorizationCode ?? null,
|
|
163
|
-
};
|
|
164
|
-
const credential = new OAuthProvider('apple.com').credential({ idToken: response.identityToken ?? undefined });
|
|
165
|
-
const status = await applyOAuthCredential(auth, credential, options, {
|
|
166
|
-
success: () => options.success?.({ response, mode: options.mode }),
|
|
167
|
-
error: (category, error) => options.error?.(category, error),
|
|
168
|
-
});
|
|
169
|
-
return { status };
|
|
170
|
-
}
|
|
171
|
-
// Web: the popup performs the sign-in/link itself.
|
|
172
|
-
const provider = new OAuthProvider('apple.com');
|
|
173
|
-
provider.addScope('email');
|
|
174
|
-
provider.addScope('name');
|
|
175
|
-
if (options.mode === 'credential') {
|
|
176
|
-
const operation = await settle(async () => {
|
|
177
|
-
const user = requireUser(auth);
|
|
178
|
-
await reauthenticateWithPopup(user, provider);
|
|
179
|
-
await linkWithCredential(user, EmailAuthProvider.credential(options.emailLogin.email, options.emailLogin.password));
|
|
180
|
-
});
|
|
181
|
-
if (operation.status === 'rejected') {
|
|
182
|
-
await options.error?.(classifyOAuthError(operation.reason), operation.reason);
|
|
183
|
-
return { status: false };
|
|
184
|
-
}
|
|
185
|
-
await options.success?.({ response: emptyAppleResponse(), mode: 'credential' });
|
|
186
|
-
return { status: true };
|
|
187
|
-
}
|
|
188
|
-
const popup = await settle(() => options.mode === 'new' ? signInWithPopup(auth, provider) : linkWithPopup(requireUser(auth), provider));
|
|
189
|
-
if (popup.status === 'rejected') {
|
|
190
|
-
await options.error?.(classifyOAuthError(popup.reason), popup.reason);
|
|
191
|
-
return { status: false };
|
|
192
|
-
}
|
|
193
|
-
const result = popup.value;
|
|
194
|
-
const credential = OAuthProvider.credentialFromResult(result);
|
|
195
|
-
const response = {
|
|
196
|
-
...emptyAppleResponse(),
|
|
197
|
-
email: result.user?.email ?? null,
|
|
198
|
-
identityToken: credential?.idToken ?? null,
|
|
199
|
-
authorizationCode: credential?.accessToken ?? null,
|
|
200
|
-
};
|
|
201
|
-
await options.success?.({ response, mode: options.mode });
|
|
202
|
-
return { status: true };
|
|
203
|
-
};
|
|
204
|
-
return execute().finally(() => options.finally?.());
|
|
205
|
-
};
|
|
206
|
-
const emptyAppleResponse = () => ({
|
|
207
|
-
user: null,
|
|
208
|
-
email: null,
|
|
209
|
-
givenName: null,
|
|
210
|
-
familyName: null,
|
|
211
|
-
identityToken: null,
|
|
212
|
-
authorizationCode: null,
|
|
213
|
-
});
|
|
214
|
-
const requireUser = (auth) => {
|
|
215
|
-
const user = auth.currentUser;
|
|
216
|
-
if (!user) {
|
|
217
|
-
throw new Error('kit social: no signed-in user to link');
|
|
218
|
-
}
|
|
219
|
-
return user;
|
|
220
|
-
};
|
|
4
|
+
/** @deprecated Import kitAppleLogin from @rdlabo/ionic-angular-kit/auth-firebase/apple. Kept for backwards compatibility. */
|
|
5
|
+
const kitAppleLogin = kitAppleLogin$1;
|
|
6
|
+
/** @deprecated Import kitFacebookLogin from @rdlabo/ionic-angular-kit/auth-firebase/facebook. Kept for backwards compatibility. */
|
|
7
|
+
const kitFacebookLogin = kitFacebookLogin$1;
|
|
8
|
+
/** @deprecated Import kitFacebookLogout from @rdlabo/ionic-angular-kit/auth-firebase/facebook. Kept for backwards compatibility. */
|
|
9
|
+
const kitFacebookLogout = kitFacebookLogout$1;
|
|
221
10
|
|
|
222
11
|
// Social login (Facebook / Apple). Its own entry point so only apps that use it pull in the native
|
|
223
|
-
// plugins `@capacitor-community/facebook-login` and `@capacitor-
|
|
12
|
+
// plugins `@capacitor-community/facebook-login` and `@capawesome/capacitor-apple-sign-in`; the core
|
|
224
13
|
// `auth-firebase` entry stays free of them.
|
|
225
14
|
//
|
|
226
15
|
// Public surface is curated: two bundled flows plus their option types. The nonce util, the error
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rdlabo-ionic-angular-kit-auth-firebase-social.mjs","sources":["../../../projects/kit/auth-firebase/social/src/kit-social.ts","../../../projects/kit/auth-firebase/social/src/public-api.ts","../../../projects/kit/auth-firebase/social/src/rdlabo-ionic-angular-kit-auth-firebase-social.ts"],"sourcesContent":["import type { Auth, AuthCredential } from 'firebase/auth';\nimport {\n EmailAuthProvider,\n FacebookAuthProvider,\n linkWithCredential,\n linkWithPopup,\n OAuthProvider,\n reauthenticateWithCredential,\n reauthenticateWithPopup,\n signInWithCredential,\n signInWithPopup,\n} from 'firebase/auth';\nimport { Capacitor } from '@capacitor/core';\nimport { FacebookLogin } from '@capacitor-community/facebook-login';\nimport { SignInWithApple } from '@capacitor-community/apple-sign-in';\n\n/** How a social-credential failure is classified for the app's error hook. */\nexport type KitOAuthErrorCategory = 'already-in-use' | 'cancelled' | 'other';\n\n/** The mode a social login runs in. */\nexport type KitOAuthModeName = 'new' | 'link' | 'credential';\n\n/**\n * The mode discriminator. `'credential'` links an email/password to the (re-authenticated) social\n * account, so it requires the new email/password; `'new'` / `'link'` do not.\n */\nexport type KitOAuthMode = { mode: 'new' } | { mode: 'link' } | { mode: 'credential'; emailLogin: { email: string; password: string } };\n\n/**\n * The apple identity payload handed to the `success` hook for the backend call. Populated from the\n * native plugin on device, or synthesized from the popup result on the web.\n */\nexport interface KitAppleResponse {\n user: string | null;\n email: string | null;\n givenName: string | null;\n familyName: string | null;\n identityToken: string | null;\n authorizationCode: string | null;\n}\n\n/**\n * The uniform lifecycle hooks for a social flow — the same `before / success / error / finally`\n * shape as {@link KitFirebaseAuthService}'s hooks, so a call site reads the same everywhere. All are\n * optional; the kit renders nothing itself.\n *\n * @typeParam Info - the identity payload handed to {@link success} (Facebook access token / Apple\n * response), so an app can notify its backend and give feedback in one place.\n *\n * @remarks\n * `before` runs before the plugin login starts, `success` after the mode's Firebase op succeeds\n * (carrying the identity payload — do the backend call and the toast here), `error` on a classified\n * failure (`'cancelled'` is passed through so the app can stay silent on a user cancel), and\n * `finally` always. The kit swallows none of these errors.\n */\ninterface 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\n/** Options for {@link kitFacebookLogin}. */\nexport type KitFacebookLoginOptions = KitOAuthMode &\n KitSocialHooks<{ accessToken: string; mode: KitOAuthModeName }> & {\n /** Facebook permissions to request. */\n permissions: string[];\n };\n\n/** Options for {@link kitAppleLogin}. */\nexport type KitAppleLoginOptions = KitOAuthMode & KitSocialHooks<{ response: KitAppleResponse; mode: KitOAuthModeName }>;\n\n/** Generate a random nonce for the Facebook OIDC (Limited Login) flow. */\nconst generateNonce = (length = 16): string => {\n const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n let nonce = '';\n for (let i = 0; i < length; i++) {\n nonce += charset[Math.floor(Math.random() * charset.length)];\n }\n return nonce;\n};\n\nconst classifyOAuthError = (e: unknown): KitOAuthErrorCategory => {\n const code = (e as { code?: string } | undefined)?.code;\n if (code === 'auth/credential-already-in-use') {\n return 'already-in-use';\n }\n if (code === 'auth/user-cancelled' || code === 'auth/popup-closed-by-user' || code === 'auth/cancelled-popup-request') {\n return 'cancelled';\n }\n return 'other';\n};\n\ntype Settled<T> = { status: 'fulfilled'; value: T } | { status: 'rejected'; reason: unknown };\n\n/** Convert a possibly synchronously-throwing Promise producer into an explicit result. */\nconst settle = <T>(operation: () => Promise<T>): Promise<Settled<T>> => {\n const execute = async (): Promise<T> => operation();\n return execute().then(\n (value) => ({ status: 'fulfilled', value }),\n (reason: unknown) => ({ status: 'rejected', reason }),\n );\n};\n\n/**\n * The shared 3-mode credential state machine (internal).\n *\n * @remarks\n * `new` signs in with the credential, `link` links it, `credential` re-authenticates with the social\n * credential and then links an email/password. Any Firebase error is classified and handed to\n * `error` (returning `false`); on success the app's `success` hook (backend + feedback) runs with the\n * identity payload, and it returns `true`.\n */\nconst applyOAuthCredential = async (\n auth: Auth,\n credential: AuthCredential,\n mode: KitOAuthMode,\n effects: {\n success: () => void | Promise<unknown>;\n error: (category: KitOAuthErrorCategory, error: unknown) => void | Promise<unknown>;\n },\n): Promise<boolean> => {\n const result = await settle(async () => {\n if (mode.mode === 'new') {\n await signInWithCredential(auth, credential);\n } else {\n const user = auth.currentUser;\n if (!user) {\n throw new Error('kit social: no signed-in user to link/re-authenticate');\n }\n if (mode.mode === 'link') {\n await linkWithCredential(user, credential);\n } else {\n await reauthenticateWithCredential(user, credential);\n await linkWithCredential(user, EmailAuthProvider.credential(mode.emailLogin.email, mode.emailLogin.password));\n }\n }\n });\n if (result.status === 'rejected') {\n await effects.error(classifyOAuthError(result.reason), result.reason);\n return false;\n }\n await effects.success();\n return true;\n};\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/**\n * Facebook login / link, bundled: native plugin → credential → the shared 3-mode state machine.\n *\n * @remarks\n * On iOS the credential is built from the OIDC token with a nonce (`OAuthProvider('facebook.com')`);\n * elsewhere from the access token (`FacebookAuthProvider`). Returns `{ status: false }` on a\n * cancelled/failed plugin login or a handled Firebase error (the app was already notified via the\n * hooks).\n */\nexport const kitFacebookLogin = async (auth: Auth, options: KitFacebookLoginOptions): Promise<{ status: boolean }> => {\n const execute = async (): Promise<{ status: boolean }> => {\n await options.before?.();\n const nonce = generateNonce();\n const login = await settle(() => FacebookLogin.login({ permissions: options.permissions, nonce }));\n await nextFrame();\n if (login.status === 'rejected') {\n if (!isFacebookCancellation(login.reason)) await options.error?.('other', login.reason);\n return { status: false };\n }\n const event = login.value;\n if (!event?.accessToken?.token) return { status: false };\n const accessToken = event.accessToken.token;\n const credential: AuthCredential =\n Capacitor.isNativePlatform() && Capacitor.getPlatform() === 'ios'\n ? new OAuthProvider('facebook.com').credential({ rawNonce: nonce, idToken: accessToken })!\n : FacebookAuthProvider.credential(accessToken);\n\n const status = await applyOAuthCredential(auth, credential, options, {\n success: () => options.success?.({ accessToken, mode: options.mode }),\n error: (category, error) => options.error?.(category, error),\n });\n return { status };\n };\n return execute().finally(() => options.finally?.());\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/**\n * Sign in with Apple / link, bundled. Native uses the plugin; the web uses the Firebase popup.\n *\n * @remarks\n * - **Native**: `SignInWithApple.authorize()` → `OAuthProvider('apple.com')` credential → the shared\n * 3-mode state machine.\n * - **Web**: `signInWithPopup` / `linkWithPopup` (with `email`/`name` scopes), or, for `credential`,\n * `reauthenticateWithPopup` then link the email/password. The identity payload for the backend is\n * synthesized from the popup result.\n *\n * Every failure path (including popup errors) is routed through `onError`.\n */\nexport const kitAppleLogin = async (auth: Auth, options: KitAppleLoginOptions): Promise<{ status: boolean }> => {\n const execute = async (): Promise<{ status: boolean }> => {\n await options.before?.();\n if (Capacitor.isNativePlatform()) {\n const authorize = await SignInWithApple.authorize().catch(() => undefined);\n if (!authorize) return { status: false };\n const r = authorize.response;\n const response: KitAppleResponse = {\n user: r.user ?? null,\n email: r.email ?? null,\n givenName: r.givenName ?? null,\n familyName: r.familyName ?? null,\n identityToken: r.identityToken ?? null,\n authorizationCode: r.authorizationCode ?? null,\n };\n const credential = new OAuthProvider('apple.com').credential({ idToken: response.identityToken ?? undefined })!;\n const status = await applyOAuthCredential(auth, credential, options, {\n success: () => options.success?.({ response, mode: options.mode }),\n error: (category, error) => options.error?.(category, error),\n });\n return { status };\n }\n\n // Web: the popup performs the sign-in/link itself.\n const provider = new OAuthProvider('apple.com');\n provider.addScope('email');\n provider.addScope('name');\n\n if (options.mode === 'credential') {\n const operation = await settle(async () => {\n const user = requireUser(auth);\n await reauthenticateWithPopup(user, provider);\n await linkWithCredential(user, EmailAuthProvider.credential(options.emailLogin.email, options.emailLogin.password));\n });\n if (operation.status === 'rejected') {\n await options.error?.(classifyOAuthError(operation.reason), operation.reason);\n return { status: false };\n }\n await options.success?.({ response: emptyAppleResponse(), mode: 'credential' });\n return { status: true };\n }\n\n const popup = await settle(() =>\n options.mode === 'new' ? signInWithPopup(auth, provider) : linkWithPopup(requireUser(auth), provider),\n );\n if (popup.status === 'rejected') {\n await options.error?.(classifyOAuthError(popup.reason), popup.reason);\n return { status: false };\n }\n const result = popup.value;\n const credential = OAuthProvider.credentialFromResult(result);\n const response: KitAppleResponse = {\n ...emptyAppleResponse(),\n email: result.user?.email ?? null,\n identityToken: credential?.idToken ?? null,\n authorizationCode: credential?.accessToken ?? null,\n };\n await options.success?.({ response, mode: options.mode });\n return { status: true };\n };\n return execute().finally(() => options.finally?.());\n};\n\nconst emptyAppleResponse = (): KitAppleResponse => ({\n user: null,\n email: null,\n givenName: null,\n familyName: null,\n identityToken: null,\n authorizationCode: null,\n});\n\nconst requireUser = (auth: Auth) => {\n const user = auth.currentUser;\n if (!user) {\n throw new Error('kit social: no signed-in user to link');\n }\n return user;\n};\n","// Social login (Facebook / Apple). Its own entry point so only apps that use it pull in the native\n// plugins `@capacitor-community/facebook-login` and `@capacitor-community/apple-sign-in`; the core\n// `auth-firebase` entry stays free of them.\n//\n// Public surface is curated: two bundled flows plus their option types. The nonce util, the error\n// classifier and the 3-mode credential state machine are internal implementation details.\nexport * from './kit-social';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAwEA;AACA,MAAM,aAAa,GAAG,CAAC,MAAM,GAAG,EAAE,KAAY;IAC5C,MAAM,OAAO,GAAG,gEAAgE;IAChF,IAAI,KAAK,GAAG,EAAE;AACd,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;AAC/B,QAAA,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9D;AACA,IAAA,OAAO,KAAK;AACd,CAAC;AAED,MAAM,kBAAkB,GAAG,CAAC,CAAU,KAA2B;AAC/D,IAAA,MAAM,IAAI,GAAI,CAAmC,EAAE,IAAI;AACvD,IAAA,IAAI,IAAI,KAAK,gCAAgC,EAAE;AA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I;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;AACxB,CAAA,CAAC;AAEF,MAAM,WAAW,GAAG,CAAC,IAAU,KAAI;AACjC,IAAA,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW;IAC7B,IAAI,CAAC,IAAI,EAAE;AACT,QAAA,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC;IAC1D;AACA,IAAA,OAAO,IAAI;AACb,CAAC;;ACvTD;AACA;AACA;AACA;AACA;AACA;;ACLA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"rdlabo-ionic-angular-kit-auth-firebase-social.mjs","sources":["../../../projects/kit/auth-firebase/social/src/kit-social.ts","../../../projects/kit/auth-firebase/social/src/public-api.ts","../../../projects/kit/auth-firebase/social/src/rdlabo-ionic-angular-kit-auth-firebase-social.ts"],"sourcesContent":["import { kitAppleLogin as appleLogin } from '@rdlabo/ionic-angular-kit/auth-firebase/apple';\nimport type {\n KitAppleLoginOptions as AppleLoginOptions,\n KitAppleResponse as AppleResponse,\n KitOAuthErrorCategory as OAuthErrorCategory,\n KitOAuthMode as OAuthMode,\n KitOAuthModeName as OAuthModeName,\n} from '@rdlabo/ionic-angular-kit/auth-firebase/apple';\nimport { kitFacebookLogin as facebookLogin, kitFacebookLogout as facebookLogout } from '@rdlabo/ionic-angular-kit/auth-firebase/facebook';\nimport type { KitFacebookLoginOptions as FacebookLoginOptions } from '@rdlabo/ionic-angular-kit/auth-firebase/facebook';\n\n/** @deprecated Import kitAppleLogin from @rdlabo/ionic-angular-kit/auth-firebase/apple. Kept for backwards compatibility. */\nexport const kitAppleLogin: typeof appleLogin = appleLogin;\n/** @deprecated Import kitFacebookLogin from @rdlabo/ionic-angular-kit/auth-firebase/facebook. Kept for backwards compatibility. */\nexport const kitFacebookLogin: typeof facebookLogin = facebookLogin;\n/** @deprecated Import kitFacebookLogout from @rdlabo/ionic-angular-kit/auth-firebase/facebook. Kept for backwards compatibility. */\nexport const kitFacebookLogout: typeof facebookLogout = facebookLogout;\n/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/apple. */\nexport type KitAppleLoginOptions = AppleLoginOptions;\n/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/apple. */\nexport type KitAppleResponse = AppleResponse;\n/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/apple or /facebook. */\nexport type KitOAuthErrorCategory = OAuthErrorCategory;\n/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/apple or /facebook. */\nexport type KitOAuthMode = OAuthMode;\n/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/apple or /facebook. */\nexport type KitOAuthModeName = OAuthModeName;\n/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/facebook. */\nexport type KitFacebookLoginOptions = FacebookLoginOptions;\n","// Social login (Facebook / Apple). Its own entry point so only apps that use it pull in the native\n// plugins `@capacitor-community/facebook-login` and `@capawesome/capacitor-apple-sign-in`; the core\n// `auth-firebase` entry stays free of them.\n//\n// Public surface is curated: two bundled flows plus their option types. The nonce util, the error\n// classifier and the 3-mode credential state machine are internal implementation details.\nexport * from './kit-social';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["appleLogin","facebookLogin","facebookLogout"],"mappings":";;;AAWA;AACO,MAAM,aAAa,GAAsBA;AAChD;AACO,MAAM,gBAAgB,GAAyBC;AACtD;AACO,MAAM,iBAAiB,GAA0BC;;AChBxD;AACA;AACA;AACA;AACA;AACA;;ACLA;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rdlabo/ionic-angular-kit",
|
|
3
|
-
"version": "22.0.
|
|
3
|
+
"version": "22.0.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/rdlabo-dev/ionic-angular-library.git"
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"@capacitor/status-bar": ">=7.0.0 <9.0.0",
|
|
25
25
|
"@capacitor-community/in-app-review": ">=7.0.0 <9.0.0",
|
|
26
26
|
"@capacitor-community/facebook-login": ">=8.0.0 <9.0.0",
|
|
27
|
-
"@capacitor-community/apple-sign-in": "*",
|
|
28
27
|
"@capawesome/capacitor-google-sign-in": "^0.1.4",
|
|
29
28
|
"@rdlabo/capacitor-brotherprint": ">=7.0.0 <9.0.0",
|
|
30
29
|
"dom-to-image-more": "^3.0.0",
|
|
31
30
|
"pdf-lib": "^1.17.1",
|
|
32
31
|
"firebase": ">=11 <13",
|
|
33
|
-
"rxjs": "^7.8.0"
|
|
32
|
+
"rxjs": "^7.8.0",
|
|
33
|
+
"@capawesome/capacitor-apple-sign-in": ">=0.1.4 <1"
|
|
34
34
|
},
|
|
35
35
|
"peerDependenciesMeta": {
|
|
36
36
|
"@angular/service-worker": {
|
|
@@ -54,9 +54,6 @@
|
|
|
54
54
|
"@capacitor-community/facebook-login": {
|
|
55
55
|
"optional": true
|
|
56
56
|
},
|
|
57
|
-
"@capacitor-community/apple-sign-in": {
|
|
58
|
-
"optional": true
|
|
59
|
-
},
|
|
60
57
|
"@capawesome/capacitor-google-sign-in": {
|
|
61
58
|
"optional": true
|
|
62
59
|
},
|
|
@@ -68,6 +65,9 @@
|
|
|
68
65
|
},
|
|
69
66
|
"pdf-lib": {
|
|
70
67
|
"optional": true
|
|
68
|
+
},
|
|
69
|
+
"@capawesome/capacitor-apple-sign-in": {
|
|
70
|
+
"optional": true
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
@@ -92,10 +92,22 @@
|
|
|
92
92
|
"types": "./types/rdlabo-ionic-angular-kit-auth-firebase.d.ts",
|
|
93
93
|
"default": "./fesm2022/rdlabo-ionic-angular-kit-auth-firebase.mjs"
|
|
94
94
|
},
|
|
95
|
+
"./auth-firebase/apple": {
|
|
96
|
+
"types": "./types/rdlabo-ionic-angular-kit-auth-firebase-apple.d.ts",
|
|
97
|
+
"default": "./fesm2022/rdlabo-ionic-angular-kit-auth-firebase-apple.mjs"
|
|
98
|
+
},
|
|
99
|
+
"./auth-firebase/facebook": {
|
|
100
|
+
"types": "./types/rdlabo-ionic-angular-kit-auth-firebase-facebook.d.ts",
|
|
101
|
+
"default": "./fesm2022/rdlabo-ionic-angular-kit-auth-firebase-facebook.mjs"
|
|
102
|
+
},
|
|
95
103
|
"./auth-firebase/google": {
|
|
96
104
|
"types": "./types/rdlabo-ionic-angular-kit-auth-firebase-google.d.ts",
|
|
97
105
|
"default": "./fesm2022/rdlabo-ionic-angular-kit-auth-firebase-google.mjs"
|
|
98
106
|
},
|
|
107
|
+
"./auth-firebase/internal": {
|
|
108
|
+
"types": "./types/rdlabo-ionic-angular-kit-auth-firebase-internal.d.ts",
|
|
109
|
+
"default": "./fesm2022/rdlabo-ionic-angular-kit-auth-firebase-internal.mjs"
|
|
110
|
+
},
|
|
99
111
|
"./auth-firebase/social": {
|
|
100
112
|
"types": "./types/rdlabo-ionic-angular-kit-auth-firebase-social.d.ts",
|
|
101
113
|
"default": "./fesm2022/rdlabo-ionic-angular-kit-auth-firebase-social.mjs"
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { User, Auth } from 'firebase/auth';
|
|
2
|
+
import { KitOAuthMode, KitSocialHooks, KitOAuthModeName } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';
|
|
3
|
+
export { KitOAuthErrorCategory, KitOAuthMode, KitOAuthModeName } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';
|
|
4
|
+
|
|
5
|
+
/** Apple credentials. Native authorization codes and web access tokens are distinct values. */
|
|
6
|
+
interface KitAppleResponse {
|
|
7
|
+
user: string | null;
|
|
8
|
+
email: string | null;
|
|
9
|
+
givenName: string | null;
|
|
10
|
+
familyName: string | null;
|
|
11
|
+
identityToken: string | null;
|
|
12
|
+
/** One-time authorization code from native Apple sign-in; null on web. */
|
|
13
|
+
authorizationCode: string | null;
|
|
14
|
+
/** Apple access token from the Firebase web popup; null on native.
|
|
15
|
+
* Optional for source compatibility with existing Apple response objects. Kit always supplies it.
|
|
16
|
+
*/
|
|
17
|
+
accessToken?: string | null;
|
|
18
|
+
}
|
|
19
|
+
/** Apple login options. The success hook receives the exact authenticated Firebase user. */
|
|
20
|
+
type KitAppleLoginOptions = KitOAuthMode & KitSocialHooks<{
|
|
21
|
+
response: KitAppleResponse;
|
|
22
|
+
mode: KitOAuthModeName;
|
|
23
|
+
user: User;
|
|
24
|
+
}>;
|
|
25
|
+
/** Apple sign-in/link on iOS and web. Native Android is not configured by this helper.
|
|
26
|
+
* Pins the user before any asynchronous work and reports SDK and app-hook failures to error.
|
|
27
|
+
*/
|
|
28
|
+
declare const kitAppleLogin: (auth: Auth, options: KitAppleLoginOptions) => Promise<{
|
|
29
|
+
status: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
|
|
32
|
+
export { kitAppleLogin };
|
|
33
|
+
export type { KitAppleLoginOptions, KitAppleResponse };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { User, Auth } from 'firebase/auth';
|
|
2
|
+
import { KitOAuthMode, KitSocialHooks, KitOAuthModeName } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';
|
|
3
|
+
export { KitOAuthErrorCategory, KitOAuthMode, KitOAuthModeName } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';
|
|
4
|
+
|
|
5
|
+
/** Facebook login options. Permissions and app effects are owned by the consumer. */
|
|
6
|
+
type KitFacebookLoginOptions = KitOAuthMode & KitSocialHooks<{
|
|
7
|
+
accessToken: string;
|
|
8
|
+
mode: KitOAuthModeName;
|
|
9
|
+
user: User;
|
|
10
|
+
}> & {
|
|
11
|
+
permissions: string[];
|
|
12
|
+
};
|
|
13
|
+
/** Facebook login/link with a pinned Firebase user and classified failure hooks. */
|
|
14
|
+
declare const kitFacebookLogin: (auth: Auth, options: KitFacebookLoginOptions) => Promise<{
|
|
15
|
+
status: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Log out of the Facebook SDK (best-effort; errors are ignored).
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Apps that offer Facebook login typically call this alongside the Firebase sign-out, so it lives
|
|
22
|
+
* here to keep the `@capacitor-community/facebook-login` import out of the app.
|
|
23
|
+
* Skips the call when the Facebook SDK has no active session — otherwise `FB.logout()` logs
|
|
24
|
+
* "called without an access token" on web and native rejects for email/password users.
|
|
25
|
+
*/
|
|
26
|
+
declare const kitFacebookLogout: () => Promise<void>;
|
|
27
|
+
|
|
28
|
+
export { kitFacebookLogin, kitFacebookLogout };
|
|
29
|
+
export type { KitFacebookLoginOptions };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { KitOAuthErrorCategory } from '@rdlabo/ionic-angular-kit/auth-firebase/internal';
|
|
1
2
|
import { User, Auth } from 'firebase/auth';
|
|
2
3
|
|
|
4
|
+
/** Sign in, link Google, reauthenticate, or add email/password after reauthentication. */
|
|
3
5
|
type KitGoogleLoginMode = {
|
|
4
6
|
mode: 'new';
|
|
5
7
|
} | {
|
|
@@ -13,7 +15,9 @@ type KitGoogleLoginMode = {
|
|
|
13
15
|
password: string;
|
|
14
16
|
};
|
|
15
17
|
};
|
|
16
|
-
|
|
18
|
+
/** App-facing Google authentication error category. */
|
|
19
|
+
type KitGoogleErrorCategory = KitOAuthErrorCategory;
|
|
20
|
+
/** Google login configuration. exchange runs for new/link; hooks receive the authenticated user. */
|
|
17
21
|
type KitGoogleLoginOptions = KitGoogleLoginMode & {
|
|
18
22
|
clientId: string;
|
|
19
23
|
before?: () => void | Promise<unknown>;
|
|
@@ -26,9 +30,14 @@ type KitGoogleLoginOptions = KitGoogleLoginMode & {
|
|
|
26
30
|
error?: (category: KitGoogleErrorCategory, error: unknown) => void | Promise<unknown>;
|
|
27
31
|
finally?: () => void | Promise<unknown>;
|
|
28
32
|
};
|
|
33
|
+
/** Google popup/native authentication with pinned users and app-owned exchange/feedback hooks.
|
|
34
|
+
* Failures in before/exchange/success are reported to error and return status:false.
|
|
35
|
+
* finally always runs; failures in error/finally themselves reject the call.
|
|
36
|
+
*/
|
|
29
37
|
declare const kitGoogleLogin: (auth: Auth, options: KitGoogleLoginOptions) => Promise<{
|
|
30
38
|
status: boolean;
|
|
31
39
|
}>;
|
|
40
|
+
/** Best-effort native Google SDK sign-out. */
|
|
32
41
|
declare const kitGoogleLogout: () => Promise<void>;
|
|
33
42
|
|
|
34
43
|
export { kitGoogleLogin, kitGoogleLogout };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Auth, AuthCredential, User } from 'firebase/auth';
|
|
2
|
+
|
|
3
|
+
/** The app-facing classification of a social authentication failure. */
|
|
4
|
+
type KitOAuthErrorCategory = 'already-in-use' | 'cancelled' | 'other';
|
|
5
|
+
/** Sign in, link a provider, or reauthenticate before adding email/password login. */
|
|
6
|
+
type KitOAuthMode = {
|
|
7
|
+
mode: 'new';
|
|
8
|
+
} | {
|
|
9
|
+
mode: 'link';
|
|
10
|
+
} | {
|
|
11
|
+
mode: 'credential';
|
|
12
|
+
emailLogin: {
|
|
13
|
+
email: string;
|
|
14
|
+
password: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
/** The discriminator of a social authentication operation. */
|
|
18
|
+
type KitOAuthModeName = KitOAuthMode['mode'];
|
|
19
|
+
/** App-owned effects. Failures in before/success are reported to error; finally always runs.
|
|
20
|
+
* A handled failure returns status:false. A failure in error/finally itself rejects the call.
|
|
21
|
+
*/
|
|
22
|
+
interface KitSocialHooks<Info> {
|
|
23
|
+
before?: () => void | Promise<unknown>;
|
|
24
|
+
success?: (info: Info) => void | Promise<unknown>;
|
|
25
|
+
error?: (category: KitOAuthErrorCategory, error: unknown) => void | Promise<unknown>;
|
|
26
|
+
finally?: () => void | Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
/** @internal Reject overlapping kit social flows for one Auth, including across providers.
|
|
29
|
+
* Holds the guard through error/finally hooks and releases it even when a hook rejects.
|
|
30
|
+
* Direct Firebase operations outside these helpers must be coordinated by the application.
|
|
31
|
+
*/
|
|
32
|
+
declare const runOAuthOperation: (auth: Auth, operation: () => Promise<void>, onError: (error: unknown) => void | Promise<unknown>, onFinally?: () => void | Promise<unknown>) => Promise<{
|
|
33
|
+
status: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
/** @internal Classify Firebase SDK failures without inspecting localized messages. */
|
|
36
|
+
declare const classifyOAuthError: (error: unknown) => KitOAuthErrorCategory;
|
|
37
|
+
/** @internal Require the identity captured at the start of a linking operation. */
|
|
38
|
+
declare const requireUser: (user: User | null) => User;
|
|
39
|
+
/** @internal Abort follow-up effects if the Firebase identity changed during an await. */
|
|
40
|
+
declare const assertCurrentUser: (auth: Auth, expectedUser: User | null) => void;
|
|
41
|
+
/** @internal Apply a provider credential to the captured user and return the authenticated identity. */
|
|
42
|
+
declare const applyOAuthCredential: (auth: Auth, credential: AuthCredential, mode: KitOAuthMode, expectedUser: User | null) => Promise<User>;
|
|
43
|
+
|
|
44
|
+
export { applyOAuthCredential, assertCurrentUser, classifyOAuthError, requireUser, runOAuthOperation };
|
|
45
|
+
export type { KitOAuthErrorCategory, KitOAuthMode, KitOAuthModeName, KitSocialHooks };
|
|
@@ -1,106 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KitAppleLoginOptions as KitAppleLoginOptions$1, KitAppleResponse as KitAppleResponse$1, KitOAuthErrorCategory as KitOAuthErrorCategory$1, KitOAuthMode as KitOAuthMode$1, KitOAuthModeName as KitOAuthModeName$1, kitAppleLogin as kitAppleLogin$1 } from '@rdlabo/ionic-angular-kit/auth-firebase/apple';
|
|
2
|
+
import { KitFacebookLoginOptions as KitFacebookLoginOptions$1, kitFacebookLogin as kitFacebookLogin$1, kitFacebookLogout as kitFacebookLogout$1 } from '@rdlabo/ionic-angular-kit/auth-firebase/facebook';
|
|
2
3
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* The apple identity payload handed to the `success` hook for the backend call. Populated from the
|
|
24
|
-
* native plugin on device, or synthesized from the popup result on the web.
|
|
25
|
-
*/
|
|
26
|
-
interface KitAppleResponse {
|
|
27
|
-
user: string | null;
|
|
28
|
-
email: string | null;
|
|
29
|
-
givenName: string | null;
|
|
30
|
-
familyName: string | null;
|
|
31
|
-
identityToken: string | null;
|
|
32
|
-
authorizationCode: string | null;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* The uniform lifecycle hooks for a social flow — the same `before / success / error / finally`
|
|
36
|
-
* shape as {@link KitFirebaseAuthService}'s hooks, so a call site reads the same everywhere. All are
|
|
37
|
-
* optional; the kit renders nothing itself.
|
|
38
|
-
*
|
|
39
|
-
* @typeParam Info - the identity payload handed to {@link success} (Facebook access token / Apple
|
|
40
|
-
* response), so an app can notify its backend and give feedback in one place.
|
|
41
|
-
*
|
|
42
|
-
* @remarks
|
|
43
|
-
* `before` runs before the plugin login starts, `success` after the mode's Firebase op succeeds
|
|
44
|
-
* (carrying the identity payload — do the backend call and the toast here), `error` on a classified
|
|
45
|
-
* failure (`'cancelled'` is passed through so the app can stay silent on a user cancel), and
|
|
46
|
-
* `finally` always. The kit swallows none of these errors.
|
|
47
|
-
*/
|
|
48
|
-
interface KitSocialHooks<Info> {
|
|
49
|
-
before?: () => void | Promise<unknown>;
|
|
50
|
-
success?: (info: Info) => void | Promise<unknown>;
|
|
51
|
-
error?: (category: KitOAuthErrorCategory, error: unknown) => void | Promise<unknown>;
|
|
52
|
-
finally?: () => void | Promise<unknown>;
|
|
53
|
-
}
|
|
54
|
-
/** Options for {@link kitFacebookLogin}. */
|
|
55
|
-
type KitFacebookLoginOptions = KitOAuthMode & KitSocialHooks<{
|
|
56
|
-
accessToken: string;
|
|
57
|
-
mode: KitOAuthModeName;
|
|
58
|
-
}> & {
|
|
59
|
-
/** Facebook permissions to request. */
|
|
60
|
-
permissions: string[];
|
|
61
|
-
};
|
|
62
|
-
/** Options for {@link kitAppleLogin}. */
|
|
63
|
-
type KitAppleLoginOptions = KitOAuthMode & KitSocialHooks<{
|
|
64
|
-
response: KitAppleResponse;
|
|
65
|
-
mode: KitOAuthModeName;
|
|
66
|
-
}>;
|
|
67
|
-
/**
|
|
68
|
-
* Facebook login / link, bundled: native plugin → credential → the shared 3-mode state machine.
|
|
69
|
-
*
|
|
70
|
-
* @remarks
|
|
71
|
-
* On iOS the credential is built from the OIDC token with a nonce (`OAuthProvider('facebook.com')`);
|
|
72
|
-
* elsewhere from the access token (`FacebookAuthProvider`). Returns `{ status: false }` on a
|
|
73
|
-
* cancelled/failed plugin login or a handled Firebase error (the app was already notified via the
|
|
74
|
-
* hooks).
|
|
75
|
-
*/
|
|
76
|
-
declare const kitFacebookLogin: (auth: Auth, options: KitFacebookLoginOptions) => Promise<{
|
|
77
|
-
status: boolean;
|
|
78
|
-
}>;
|
|
79
|
-
/**
|
|
80
|
-
* Log out of the Facebook SDK (best-effort; errors are ignored).
|
|
81
|
-
*
|
|
82
|
-
* @remarks
|
|
83
|
-
* Apps that offer Facebook login typically call this alongside the Firebase sign-out, so it lives
|
|
84
|
-
* here to keep the `@capacitor-community/facebook-login` import out of the app.
|
|
85
|
-
* Skips the call when the Facebook SDK has no active session — otherwise `FB.logout()` logs
|
|
86
|
-
* "called without an access token" on web and native rejects for email/password users.
|
|
87
|
-
*/
|
|
88
|
-
declare const kitFacebookLogout: () => Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
* Sign in with Apple / link, bundled. Native uses the plugin; the web uses the Firebase popup.
|
|
91
|
-
*
|
|
92
|
-
* @remarks
|
|
93
|
-
* - **Native**: `SignInWithApple.authorize()` → `OAuthProvider('apple.com')` credential → the shared
|
|
94
|
-
* 3-mode state machine.
|
|
95
|
-
* - **Web**: `signInWithPopup` / `linkWithPopup` (with `email`/`name` scopes), or, for `credential`,
|
|
96
|
-
* `reauthenticateWithPopup` then link the email/password. The identity payload for the backend is
|
|
97
|
-
* synthesized from the popup result.
|
|
98
|
-
*
|
|
99
|
-
* Every failure path (including popup errors) is routed through `onError`.
|
|
100
|
-
*/
|
|
101
|
-
declare const kitAppleLogin: (auth: Auth, options: KitAppleLoginOptions) => Promise<{
|
|
102
|
-
status: boolean;
|
|
103
|
-
}>;
|
|
4
|
+
/** @deprecated Import kitAppleLogin from @rdlabo/ionic-angular-kit/auth-firebase/apple. Kept for backwards compatibility. */
|
|
5
|
+
declare const kitAppleLogin: typeof kitAppleLogin$1;
|
|
6
|
+
/** @deprecated Import kitFacebookLogin from @rdlabo/ionic-angular-kit/auth-firebase/facebook. Kept for backwards compatibility. */
|
|
7
|
+
declare const kitFacebookLogin: typeof kitFacebookLogin$1;
|
|
8
|
+
/** @deprecated Import kitFacebookLogout from @rdlabo/ionic-angular-kit/auth-firebase/facebook. Kept for backwards compatibility. */
|
|
9
|
+
declare const kitFacebookLogout: typeof kitFacebookLogout$1;
|
|
10
|
+
/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/apple. */
|
|
11
|
+
type KitAppleLoginOptions = KitAppleLoginOptions$1;
|
|
12
|
+
/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/apple. */
|
|
13
|
+
type KitAppleResponse = KitAppleResponse$1;
|
|
14
|
+
/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/apple or /facebook. */
|
|
15
|
+
type KitOAuthErrorCategory = KitOAuthErrorCategory$1;
|
|
16
|
+
/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/apple or /facebook. */
|
|
17
|
+
type KitOAuthMode = KitOAuthMode$1;
|
|
18
|
+
/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/apple or /facebook. */
|
|
19
|
+
type KitOAuthModeName = KitOAuthModeName$1;
|
|
20
|
+
/** @deprecated Import this type from @rdlabo/ionic-angular-kit/auth-firebase/facebook. */
|
|
21
|
+
type KitFacebookLoginOptions = KitFacebookLoginOptions$1;
|
|
104
22
|
|
|
105
23
|
export { kitAppleLogin, kitFacebookLogin, kitFacebookLogout };
|
|
106
24
|
export type { KitAppleLoginOptions, KitAppleResponse, KitFacebookLoginOptions, KitOAuthErrorCategory, KitOAuthMode, KitOAuthModeName };
|