@sneat/auth-ui 0.27.41 → 0.27.43
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/esm2022/index.js +1 -0
- package/esm2022/index.js.map +1 -1
- package/esm2022/lib/pages/login-page/auth-panel.component.js +8 -5
- package/esm2022/lib/pages/login-page/auth-panel.component.js.map +1 -1
- package/esm2022/lib/pages/login-page/login-with-telegram.component.js +11 -4
- package/esm2022/lib/pages/login-page/login-with-telegram.component.js.map +1 -1
- package/esm2022/lib/pages/login-page/sneat-auth-with-telegram.service.js +45 -4
- package/esm2022/lib/pages/login-page/sneat-auth-with-telegram.service.js.map +1 -1
- package/esm2022/provider-buttons/index.js +2 -0
- package/esm2022/provider-buttons/index.js.map +1 -0
- package/esm2022/provider-buttons/provider-buttons.component.js +88 -0
- package/esm2022/provider-buttons/provider-buttons.component.js.map +1 -0
- package/esm2022/provider-buttons/sneat-auth-ui-provider-buttons.js +5 -0
- package/esm2022/provider-buttons/sneat-auth-ui-provider-buttons.js.map +1 -0
- package/index.d.ts +1 -0
- package/lib/pages/login-page/auth-panel.component.d.ts +2 -0
- package/lib/pages/login-page/login-with-telegram.component.d.ts +1 -0
- package/lib/pages/login-page/sneat-auth-with-telegram.service.d.ts +6 -0
- package/package.json +6 -1
- package/provider-buttons/README.md +31 -0
- package/provider-buttons/index.d.ts +2 -0
- package/provider-buttons/provider-buttons.component.d.ts +81 -0
- package/provider-buttons/sneat-auth-ui-provider-buttons.d.ts +5 -0
- package/tsconfig.lib.prod.tsbuildinfo +1 -1
package/esm2022/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './lib/pages/sneat-auth-routing.module';
|
|
2
2
|
export * from './lib/pages/login-page/auth-panel.component';
|
|
3
3
|
export * from './lib/pages/login-page/telegram-login-config';
|
|
4
|
+
export { LoginWithTelegramComponent } from './lib/pages/login-page/login-with-telegram.component';
|
|
4
5
|
export * from './lib/components';
|
|
5
6
|
export * from './lib/pipes/person-names.pipe';
|
|
6
7
|
export * from './lib/sso';
|
package/esm2022/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/auth/ui/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,6CAA6C,CAAC;AAE5D,cAAc,8CAA8C,CAAC;AAC7D,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,WAAW,CAAC;AAC1B,cAAc,6CAA6C,CAAC","sourcesContent":["export * from './lib/pages/sneat-auth-routing.module';\nexport * from './lib/pages/login-page/auth-panel.component';\nexport type { AuthPanelInitialMode } from './lib/pages/login-page/email-login-form/email-login-form.component';\nexport * from './lib/pages/login-page/telegram-login-config';\nexport * from './lib/components';\nexport * from './lib/pipes/person-names.pipe';\nexport * from './lib/sso';\nexport * from './lib/pages/login-page/auth-panel-ui-config';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/auth/ui/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,6CAA6C,CAAC;AAE5D,cAAc,8CAA8C,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,sDAAsD,CAAC;AAClG,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,WAAW,CAAC;AAC1B,cAAc,6CAA6C,CAAC","sourcesContent":["export * from './lib/pages/sneat-auth-routing.module';\nexport * from './lib/pages/login-page/auth-panel.component';\nexport type { AuthPanelInitialMode } from './lib/pages/login-page/email-login-form/email-login-form.component';\nexport * from './lib/pages/login-page/telegram-login-config';\nexport { LoginWithTelegramComponent } from './lib/pages/login-page/login-with-telegram.component';\nexport * from './lib/components';\nexport * from './lib/pipes/person-names.pipe';\nexport * from './lib/sso';\nexport * from './lib/pages/login-page/auth-panel-ui-config';\n"]}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { AuthProviderButtonsComponent, OAUTH_PROVIDER_IDS, } from '@sneat/auth-ui/provider-buttons';
|
|
1
2
|
import { ChangeDetectionStrategy, Component, DestroyRef, EventEmitter, Output, computed, inject, input, signal, } from '@angular/core';
|
|
2
3
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
3
4
|
import { RouterLink } from '@angular/router';
|
|
4
5
|
import { Capacitor } from '@capacitor/core';
|
|
5
6
|
import { AuthStatuses, SneatAuthStateService, SneatUserService, authProviderTitle, isAccountExistsWithDifferentCredential, isSneatAccountReady, } from '@sneat/auth-core';
|
|
6
7
|
import { ErrorLogger } from '@sneat/core';
|
|
7
|
-
import { IonButton, IonCard, IonCol, IonGrid, IonIcon,
|
|
8
|
+
import { IonButton, IonCard, IonCol, IonGrid, IonIcon, IonItemDivider, IonLabel, IonRow, IonSpinner, IonText, } from '@ionic/angular';
|
|
8
9
|
import { EmailLoginFormComponent, } from './email-login-form/email-login-form.component';
|
|
9
10
|
import { LoginWithTelegramComponent } from './login-with-telegram.component';
|
|
10
11
|
import { safeAuthReturnPath } from './safe-auth-return-path';
|
|
@@ -28,6 +29,9 @@ export class AuthPanelComponent {
|
|
|
28
29
|
this.accountReadyChange = new EventEmitter();
|
|
29
30
|
this.signingWith = signal(undefined, /* @ts-ignore */
|
|
30
31
|
...(ngDevMode ? [{ debugName: "signingWith" }] : /* istanbul ignore next */ []));
|
|
32
|
+
this.oauthProviders = OAUTH_PROVIDER_IDS.filter((provider) => this.providerVisible(provider));
|
|
33
|
+
this.oauthSigningWith = computed(() => OAUTH_PROVIDER_IDS.find((provider) => provider === this.signingWith()), /* @ts-ignore */
|
|
34
|
+
...(ngDevMode ? [{ debugName: "oauthSigningWith" }] : /* istanbul ignore next */ []));
|
|
31
35
|
this.authRecoveryNeeded = signal(false, /* @ts-ignore */
|
|
32
36
|
...(ngDevMode ? [{ debugName: "authRecoveryNeeded" }] : /* istanbul ignore next */ []));
|
|
33
37
|
/**
|
|
@@ -159,12 +163,13 @@ export class AuthPanelComponent {
|
|
|
159
163
|
this.userService.onUserSignedIn(authState);
|
|
160
164
|
}
|
|
161
165
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: AuthPanelComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
162
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.3", type: AuthPanelComponent, isStandalone: true, selector: "sneat-auth-panel", inputs: { returnTo: { classPropertyName: "returnTo", publicName: "returnTo", isSignal: true, isRequired: false, transformFunction: null }, initialMode: { classPropertyName: "initialMode", publicName: "initialMode", isSignal: true, isRequired: false, transformFunction: null }, showIntro: { classPropertyName: "showIntro", publicName: "showIntro", isSignal: true, isRequired: false, transformFunction: null }, showCredentials: { classPropertyName: "showCredentials", publicName: "showCredentials", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { accountReadyChange: "accountReadyChange" }, providers: [RandomIdService], ngImport: i0, template: "@if (authRecoveryNeeded()) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n We couldn't complete sign-in. Try again with email or another sign-in\n method.\n </p>\n </div>\n}\n\n@if (pendingLink(); as link) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n @if (link.email) {\n <b>{{ link.email }}</b> already has an account.\n } @else {\n This email already has an account.\n }\n Sign in the way you did before \u2014 with email or another sign-in method \u2014\n @if (link.autoLink) {\n and we'll connect {{ link.provider }} to it automatically.\n } @else {\n then connect {{ link.provider }} from your account page.\n }\n </p>\n </div>\n}\n\n@if (recordState() === 'failed') {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>Your account is still being prepared. Retry before continuing.</p>\n <ion-button fill=\"outline\" (click)=\"retryUserRecordInitialization()\">\n Retry account setup\n </ion-button>\n </div>\n} @else if (recordState() === 'loading') {\n <div class=\"ion-padding ion-text-center\" role=\"status\" aria-live=\"polite\">\n <ion-spinner name=\"lines-small\" />\n <p>Preparing your account\u2026</p>\n </div>\n} @else {\n @if (showCredentials() || authRecoveryNeeded()) {\n @if (showIntro()) {\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">Sign in with your Sneat account.</ion-text>\n </p>\n }\n\n <sneat-email-login-form\n [returnTo]=\"safeReturnTo()\"\n [initialMode]=\"initialMode()\"\n (signingWithChange)=\"onEmailFormStatusChanged($event)\"\n (loggedIn)=\"onLoggedIn($event)\"\n />\n\n <div class=\"ion-padding-horizontal ion-text-center\">\n <ion-button\n fill=\"outline\"\n expand=\"block\"\n routerLink=\"/sso\"\n [queryParams]=\"ssoQueryParams()\"\n [disabled]=\"!!signingWith()\"\n >\n <ion-icon name=\"business-outline\" slot=\"start\" />\n Sign in with company SSO\n </ion-button>\n </div>\n\n @if (uiConfig.quickLoginProviders?.length !== 0) {\n <ion-card>\n @if (uiConfig.showQuickLoginHeader !== false) {\n <ion-item-divider color=\"light\">\n <ion-label\n color=\"medium\"\n style=\"text-align: center; width: 100%; font-weight: bold\"\n >\n Quick login\n </ion-label>\n </ion-item-divider>\n }\n <ion-grid class=\"ion-grid-layout\">\n @if (!isNativePlatform && providerVisible('telegram')) {\n <ion-row>\n <ion-col>\n <div class=\"ion-padding\" style=\"text-align: center\">\n <sneat-login-with-telegram />\n </div>\n </ion-col>\n </ion-row>\n }\n <ion-row>\n @if (providerVisible('google.com')) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n (click)=\"loginWith('google.com')\"\n tappable\n [disabled]=\"!!signingWith()\"\n >\n @if (signingWith() === 'google.com') {\n <ion-spinner slot=\"start\" name=\"lines-small\" />\n } @else {\n <ion-icon\n color=\"danger\"\n name=\"logo-google\"\n slot=\"start\"\n />\n }\n <ion-label color=\"danger\"> Login with Google</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n }\n @if (providerVisible('apple.com')) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n (click)=\"loginWith('apple.com')\"\n tappable\n [disabled]=\"!!signingWith()\"\n >\n @if (signingWith() === 'apple.com') {\n <ion-spinner slot=\"start\" name=\"lines-small\" />\n } @else {\n <ion-icon color=\"dark\" name=\"logo-apple\" slot=\"start\" />\n }\n <ion-label color=\"dark\">Login with Apple</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n }\n </ion-row>\n <ion-row>\n @if (providerVisible('microsoft.com')) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n (click)=\"loginWith('microsoft.com')\"\n tappable\n [disabled]=\"!!signingWith()\"\n >\n @if (signingWith() === 'microsoft.com') {\n <ion-spinner\n slot=\"start\"\n color=\"secondary\"\n name=\"lines-small\"\n />\n } @else {\n <ion-icon\n slot=\"start\"\n color=\"secondary\"\n name=\"logo-windows\"\n />\n }\n <ion-label color=\"secondary\"\n >Login with Microsoft</ion-label\n >\n </ion-item>\n </ion-list>\n </ion-col>\n }\n @if (providerVisible('facebook.com')) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n (click)=\"loginWith('facebook.com')\"\n tappable\n [disabled]=\"!!signingWith()\"\n >\n @if (signingWith() === 'facebook.com') {\n <ion-spinner\n slot=\"start\"\n color=\"primary\"\n name=\"lines-small\"\n />\n } @else {\n <ion-icon\n slot=\"start\"\n color=\"primary\"\n name=\"logo-facebook\"\n />\n }\n <ion-label color=\"primary\">Login with Facebook</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n }\n </ion-row>\n <ion-row>\n @if (providerVisible('github.com')) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n (click)=\"loginWith('github.com')\"\n tappable\n [disabled]=\"!!signingWith()\"\n >\n @if (signingWith() === 'github.com') {\n <ion-spinner\n slot=\"start\"\n color=\"tertiary\"\n name=\"lines-small\"\n />\n } @else {\n <ion-icon\n slot=\"start\"\n color=\"tertiary\"\n name=\"logo-github\"\n />\n }\n <ion-label color=\"tertiary\">Login with GitHub</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n }\n </ion-row>\n </ion-grid>\n </ion-card>\n }\n }\n}\n", dependencies: [{ kind: "directive", type: RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "browserUrl", "routerLink"] }, { kind: "component", type: EmailLoginFormComponent, selector: "sneat-email-login-form", inputs: ["returnTo", "initialMode"], outputs: ["signingWithChange", "loggedIn"] }, { kind: "component", type: LoginWithTelegramComponent, selector: "sneat-login-with-telegram", inputs: ["isUserAuthenticated", "botID", "size", "requestAccess", "userPic"] }, { kind: "component", type: IonButton, selector: "ion-button", inputs: ["buttonType", "color", "disabled", "download", "expand", "fill", "form", "href", "mode", "rel", "routerAnimation", "routerDirection", "shape", "size", "strong", "target", "type"], outputs: ["ionFocus", "ionBlur"] }, { kind: "component", type: IonCard, selector: "ion-card", inputs: ["button", "color", "disabled", "download", "href", "mode", "rel", "routerAnimation", "routerDirection", "target", "type"] }, { kind: "component", type: IonCol, selector: "ion-col", inputs: ["offset", "offsetLg", "offsetMd", "offsetSm", "offsetXl", "offsetXs", "pull", "pullLg", "pullMd", "pullSm", "pullXl", "pullXs", "push", "pushLg", "pushMd", "pushSm", "pushXl", "pushXs", "size", "sizeLg", "sizeMd", "sizeSm", "sizeXl", "sizeXs"] }, { kind: "component", type: IonGrid, selector: "ion-grid", inputs: ["fixed"] }, { kind: "component", type: IonIcon, selector: "ion-icon", inputs: ["color", "flipRtl", "icon", "ios", "lazy", "md", "mode", "name", "sanitize", "size", "src"] }, { kind: "component", type: IonItem, selector: "ion-item", inputs: ["button", "color", "detail", "detailIcon", "disabled", "download", "href", "lines", "mode", "rel", "routerAnimation", "routerDirection", "target", "type"] }, { kind: "component", type: IonItemDivider, selector: "ion-item-divider", inputs: ["color", "mode", "sticky"] }, { kind: "component", type: IonLabel, selector: "ion-label", inputs: ["color", "mode", "position"] }, { kind: "component", type: IonList, selector: "ion-list", inputs: ["inset", "lines", "mode"] }, { kind: "component", type: IonRow, selector: "ion-row" }, { kind: "component", type: IonSpinner, selector: "ion-spinner", inputs: ["color", "duration", "name", "paused"] }, { kind: "component", type: IonText, selector: "ion-text", inputs: ["color", "mode"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
166
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.3", type: AuthPanelComponent, isStandalone: true, selector: "sneat-auth-panel", inputs: { returnTo: { classPropertyName: "returnTo", publicName: "returnTo", isSignal: true, isRequired: false, transformFunction: null }, initialMode: { classPropertyName: "initialMode", publicName: "initialMode", isSignal: true, isRequired: false, transformFunction: null }, showIntro: { classPropertyName: "showIntro", publicName: "showIntro", isSignal: true, isRequired: false, transformFunction: null }, showCredentials: { classPropertyName: "showCredentials", publicName: "showCredentials", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { accountReadyChange: "accountReadyChange" }, providers: [RandomIdService], ngImport: i0, template: "@if (authRecoveryNeeded()) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n We couldn't complete sign-in. Try again with email or another sign-in\n method.\n </p>\n </div>\n}\n\n@if (pendingLink(); as link) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n @if (link.email) {\n <b>{{ link.email }}</b> already has an account.\n } @else {\n This email already has an account.\n }\n Sign in the way you did before \u2014 with email or another sign-in method \u2014\n @if (link.autoLink) {\n and we'll connect {{ link.provider }} to it automatically.\n } @else {\n then connect {{ link.provider }} from your account page.\n }\n </p>\n </div>\n}\n\n@if (recordState() === 'failed') {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>Your account is still being prepared. Retry before continuing.</p>\n <ion-button fill=\"outline\" (click)=\"retryUserRecordInitialization()\">\n Retry account setup\n </ion-button>\n </div>\n} @else if (recordState() === 'loading') {\n <div class=\"ion-padding ion-text-center\" role=\"status\" aria-live=\"polite\">\n <ion-spinner name=\"lines-small\" />\n <p>Preparing your account\u2026</p>\n </div>\n} @else {\n @if (showCredentials() || authRecoveryNeeded()) {\n @if (showIntro()) {\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">Sign in with your Sneat account.</ion-text>\n </p>\n }\n\n <sneat-email-login-form\n [returnTo]=\"safeReturnTo()\"\n [initialMode]=\"initialMode()\"\n (signingWithChange)=\"onEmailFormStatusChanged($event)\"\n (loggedIn)=\"onLoggedIn($event)\"\n />\n\n <div class=\"ion-padding-horizontal ion-text-center\">\n <ion-button\n fill=\"outline\"\n expand=\"block\"\n routerLink=\"/sso\"\n [queryParams]=\"ssoQueryParams()\"\n [disabled]=\"!!signingWith()\"\n >\n <ion-icon name=\"business-outline\" slot=\"start\" />\n Sign in with company SSO\n </ion-button>\n </div>\n\n @if (uiConfig.quickLoginProviders?.length !== 0) {\n <ion-card>\n @if (uiConfig.showQuickLoginHeader !== false) {\n <ion-item-divider color=\"light\">\n <ion-label\n color=\"medium\"\n style=\"text-align: center; width: 100%; font-weight: bold\"\n >\n Quick login\n </ion-label>\n </ion-item-divider>\n }\n <ion-grid class=\"ion-grid-layout\">\n @if (!isNativePlatform && providerVisible('telegram')) {\n <ion-row>\n <ion-col>\n <div class=\"ion-padding\" style=\"text-align: center\">\n <sneat-login-with-telegram />\n </div>\n </ion-col>\n </ion-row>\n }\n <sneat-auth-provider-buttons\n [providers]=\"oauthProviders\"\n [busy]=\"oauthSigningWith()\"\n [disabled]=\"!!signingWith()\"\n (providerSelected)=\"loginWith($event)\"\n />\n </ion-grid>\n </ion-card>\n }\n }\n}\n", dependencies: [{ kind: "directive", type: RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "browserUrl", "routerLink"] }, { kind: "component", type: AuthProviderButtonsComponent, selector: "sneat-auth-provider-buttons", inputs: ["providers", "busy", "disabled", "labels"], outputs: ["providerSelected"] }, { kind: "component", type: EmailLoginFormComponent, selector: "sneat-email-login-form", inputs: ["returnTo", "initialMode"], outputs: ["signingWithChange", "loggedIn"] }, { kind: "component", type: LoginWithTelegramComponent, selector: "sneat-login-with-telegram", inputs: ["isUserAuthenticated", "botID", "size", "requestAccess", "userPic"] }, { kind: "component", type: IonButton, selector: "ion-button", inputs: ["buttonType", "color", "disabled", "download", "expand", "fill", "form", "href", "mode", "rel", "routerAnimation", "routerDirection", "shape", "size", "strong", "target", "type"], outputs: ["ionFocus", "ionBlur"] }, { kind: "component", type: IonCard, selector: "ion-card", inputs: ["button", "color", "disabled", "download", "href", "mode", "rel", "routerAnimation", "routerDirection", "target", "type"] }, { kind: "component", type: IonCol, selector: "ion-col", inputs: ["offset", "offsetLg", "offsetMd", "offsetSm", "offsetXl", "offsetXs", "pull", "pullLg", "pullMd", "pullSm", "pullXl", "pullXs", "push", "pushLg", "pushMd", "pushSm", "pushXl", "pushXs", "size", "sizeLg", "sizeMd", "sizeSm", "sizeXl", "sizeXs"] }, { kind: "component", type: IonGrid, selector: "ion-grid", inputs: ["fixed"] }, { kind: "component", type: IonIcon, selector: "ion-icon", inputs: ["color", "flipRtl", "icon", "ios", "lazy", "md", "mode", "name", "sanitize", "size", "src"] }, { kind: "component", type: IonItemDivider, selector: "ion-item-divider", inputs: ["color", "mode", "sticky"] }, { kind: "component", type: IonLabel, selector: "ion-label", inputs: ["color", "mode", "position"] }, { kind: "component", type: IonRow, selector: "ion-row" }, { kind: "component", type: IonSpinner, selector: "ion-spinner", inputs: ["color", "duration", "name", "paused"] }, { kind: "component", type: IonText, selector: "ion-text", inputs: ["color", "mode"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
163
167
|
}
|
|
164
168
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: AuthPanelComponent, decorators: [{
|
|
165
169
|
type: Component,
|
|
166
170
|
args: [{ selector: 'sneat-auth-panel', changeDetection: ChangeDetectionStrategy.OnPush, imports: [
|
|
167
171
|
RouterLink,
|
|
172
|
+
AuthProviderButtonsComponent,
|
|
168
173
|
EmailLoginFormComponent,
|
|
169
174
|
LoginWithTelegramComponent,
|
|
170
175
|
IonButton,
|
|
@@ -172,14 +177,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImpor
|
|
|
172
177
|
IonCol,
|
|
173
178
|
IonGrid,
|
|
174
179
|
IonIcon,
|
|
175
|
-
IonItem,
|
|
176
180
|
IonItemDivider,
|
|
177
181
|
IonLabel,
|
|
178
|
-
IonList,
|
|
179
182
|
IonRow,
|
|
180
183
|
IonSpinner,
|
|
181
184
|
IonText,
|
|
182
|
-
], providers: [RandomIdService], template: "@if (authRecoveryNeeded()) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n We couldn't complete sign-in. Try again with email or another sign-in\n method.\n </p>\n </div>\n}\n\n@if (pendingLink(); as link) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n @if (link.email) {\n <b>{{ link.email }}</b> already has an account.\n } @else {\n This email already has an account.\n }\n Sign in the way you did before \u2014 with email or another sign-in method \u2014\n @if (link.autoLink) {\n and we'll connect {{ link.provider }} to it automatically.\n } @else {\n then connect {{ link.provider }} from your account page.\n }\n </p>\n </div>\n}\n\n@if (recordState() === 'failed') {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>Your account is still being prepared. Retry before continuing.</p>\n <ion-button fill=\"outline\" (click)=\"retryUserRecordInitialization()\">\n Retry account setup\n </ion-button>\n </div>\n} @else if (recordState() === 'loading') {\n <div class=\"ion-padding ion-text-center\" role=\"status\" aria-live=\"polite\">\n <ion-spinner name=\"lines-small\" />\n <p>Preparing your account\u2026</p>\n </div>\n} @else {\n @if (showCredentials() || authRecoveryNeeded()) {\n @if (showIntro()) {\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">Sign in with your Sneat account.</ion-text>\n </p>\n }\n\n <sneat-email-login-form\n [returnTo]=\"safeReturnTo()\"\n [initialMode]=\"initialMode()\"\n (signingWithChange)=\"onEmailFormStatusChanged($event)\"\n (loggedIn)=\"onLoggedIn($event)\"\n />\n\n <div class=\"ion-padding-horizontal ion-text-center\">\n <ion-button\n fill=\"outline\"\n expand=\"block\"\n routerLink=\"/sso\"\n [queryParams]=\"ssoQueryParams()\"\n [disabled]=\"!!signingWith()\"\n >\n <ion-icon name=\"business-outline\" slot=\"start\" />\n Sign in with company SSO\n </ion-button>\n </div>\n\n @if (uiConfig.quickLoginProviders?.length !== 0) {\n <ion-card>\n @if (uiConfig.showQuickLoginHeader !== false) {\n <ion-item-divider color=\"light\">\n <ion-label\n color=\"medium\"\n style=\"text-align: center; width: 100%; font-weight: bold\"\n >\n Quick login\n </ion-label>\n </ion-item-divider>\n }\n <ion-grid class=\"ion-grid-layout\">\n @if (!isNativePlatform && providerVisible('telegram')) {\n <ion-row>\n <ion-col>\n <div class=\"ion-padding\" style=\"text-align: center\">\n <sneat-login-with-telegram />\n </div>\n </ion-col>\n </ion-row>\n }\n <
|
|
185
|
+
], providers: [RandomIdService], template: "@if (authRecoveryNeeded()) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n We couldn't complete sign-in. Try again with email or another sign-in\n method.\n </p>\n </div>\n}\n\n@if (pendingLink(); as link) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n @if (link.email) {\n <b>{{ link.email }}</b> already has an account.\n } @else {\n This email already has an account.\n }\n Sign in the way you did before \u2014 with email or another sign-in method \u2014\n @if (link.autoLink) {\n and we'll connect {{ link.provider }} to it automatically.\n } @else {\n then connect {{ link.provider }} from your account page.\n }\n </p>\n </div>\n}\n\n@if (recordState() === 'failed') {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>Your account is still being prepared. Retry before continuing.</p>\n <ion-button fill=\"outline\" (click)=\"retryUserRecordInitialization()\">\n Retry account setup\n </ion-button>\n </div>\n} @else if (recordState() === 'loading') {\n <div class=\"ion-padding ion-text-center\" role=\"status\" aria-live=\"polite\">\n <ion-spinner name=\"lines-small\" />\n <p>Preparing your account\u2026</p>\n </div>\n} @else {\n @if (showCredentials() || authRecoveryNeeded()) {\n @if (showIntro()) {\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">Sign in with your Sneat account.</ion-text>\n </p>\n }\n\n <sneat-email-login-form\n [returnTo]=\"safeReturnTo()\"\n [initialMode]=\"initialMode()\"\n (signingWithChange)=\"onEmailFormStatusChanged($event)\"\n (loggedIn)=\"onLoggedIn($event)\"\n />\n\n <div class=\"ion-padding-horizontal ion-text-center\">\n <ion-button\n fill=\"outline\"\n expand=\"block\"\n routerLink=\"/sso\"\n [queryParams]=\"ssoQueryParams()\"\n [disabled]=\"!!signingWith()\"\n >\n <ion-icon name=\"business-outline\" slot=\"start\" />\n Sign in with company SSO\n </ion-button>\n </div>\n\n @if (uiConfig.quickLoginProviders?.length !== 0) {\n <ion-card>\n @if (uiConfig.showQuickLoginHeader !== false) {\n <ion-item-divider color=\"light\">\n <ion-label\n color=\"medium\"\n style=\"text-align: center; width: 100%; font-weight: bold\"\n >\n Quick login\n </ion-label>\n </ion-item-divider>\n }\n <ion-grid class=\"ion-grid-layout\">\n @if (!isNativePlatform && providerVisible('telegram')) {\n <ion-row>\n <ion-col>\n <div class=\"ion-padding\" style=\"text-align: center\">\n <sneat-login-with-telegram />\n </div>\n </ion-col>\n </ion-row>\n }\n <sneat-auth-provider-buttons\n [providers]=\"oauthProviders\"\n [busy]=\"oauthSigningWith()\"\n [disabled]=\"!!signingWith()\"\n (providerSelected)=\"loginWith($event)\"\n />\n </ion-grid>\n </ion-card>\n }\n }\n}\n" }]
|
|
183
186
|
}], propDecorators: { returnTo: [{ type: i0.Input, args: [{ isSignal: true, alias: "returnTo", required: false }] }], initialMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "initialMode", required: false }] }], showIntro: [{ type: i0.Input, args: [{ isSignal: true, alias: "showIntro", required: false }] }], showCredentials: [{ type: i0.Input, args: [{ isSignal: true, alias: "showCredentials", required: false }] }], accountReadyChange: [{
|
|
184
187
|
type: Output
|
|
185
188
|
}] } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-panel.component.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/auth-panel.component.ts","../../../../../../../../libs/auth/ui/src/lib/pages/login-page/auth-panel.component.html"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,SAAS,EACT,UAAU,EACV,YAAY,EAEZ,MAAM,EACN,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAEL,YAAY,EAEZ,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,sCAAsC,EACtC,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAC;AAExD,OAAO,EACL,SAAS,EACT,OAAO,EACP,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,EACP,cAAc,EACd,QAAQ,EACR,OAAO,EACP,MAAM,EACN,UAAU,EACV,OAAO,GACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGL,uBAAuB,GACxB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EACL,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,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AAY,CAAC,OAAO,CAAC,gBAAgB,EAAE,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACpE,CAAC;QACH,CAAC;QACD,MAAM,SAAS,GAAoB;YACjC,MAAM,EAAE,YAAY,CAAC,aAAa;YAClC,IAAI,EAAE,cAAc,CAAC,IAAI;SAC1B,CAAC;QACF,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC;8GArKU,kBAAkB;kGAAlB,kBAAkB,uqBAFlB,CAAC,eAAe,CAAC,0BCnF9B,0uPA4NA,4CDzJI,UAAU,kPACV,uBAAuB,oJACvB,0BAA0B,oJAC1B,SAAS,sRACT,OAAO,yLACP,MAAM,kTACN,OAAO,wEACP,OAAO,2JACP,OAAO,0NACP,cAAc,kGACd,QAAQ,6FACR,OAAO,yFACP,MAAM,oDACN,UAAU,yGACV,OAAO;;2FAIE,kBAAkB;kBAvB9B,SAAS;+BACE,kBAAkB,mBAEX,uBAAuB,CAAC,MAAM,WACtC;wBACP,UAAU;wBACV,uBAAuB;wBACvB,0BAA0B;wBAC1B,SAAS;wBACT,OAAO;wBACP,MAAM;wBACN,OAAO;wBACP,OAAO;wBACP,OAAO;wBACP,cAAc;wBACd,QAAQ;wBACR,OAAO;wBACP,MAAM;wBACN,UAAU;wBACV,OAAO;qBACR,aACU,CAAC,eAAe,CAAC;;sBAY3B,MAAM","sourcesContent":["import {\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n EventEmitter,\n OnInit,\n Output,\n computed,\n inject,\n input,\n signal,\n} from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { RouterLink } from '@angular/router';\nimport { Capacitor } from '@capacitor/core';\nimport {\n AuthProviderID,\n AuthStatuses,\n ISneatAuthState,\n SneatAuthStateService,\n SneatUserService,\n authProviderTitle,\n isAccountExistsWithDifferentCredential,\n isSneatAccountReady,\n} from '@sneat/auth-core';\nimport { ErrorLogger, IErrorLogger } from '@sneat/core';\nimport { UserCredential } from 'firebase/auth';\nimport {\n IonButton,\n IonCard,\n IonCol,\n IonGrid,\n IonIcon,\n IonItem,\n IonItemDivider,\n IonLabel,\n IonList,\n IonRow,\n IonSpinner,\n IonText,\n} from '@ionic/angular';\nimport {\n AuthPanelInitialMode,\n EmailFormSigningWith,\n EmailLoginFormComponent,\n} from './email-login-form/email-login-form.component';\nimport { LoginWithTelegramComponent } from './login-with-telegram.component';\nimport { safeAuthReturnPath } from './safe-auth-return-path';\nimport {\n clearLoginRedirectIntent,\n markLoginRedirectIntent,\n} from './login-redirect-intent';\nimport { combineLatest } from 'rxjs';\nimport { AUTH_PANEL_UI_CONFIG } from './auth-panel-ui-config';\nimport { RandomIdService } from '@sneat/random';\n\nexport interface AuthPanelAccountReadyChange {\n readonly uid?: string;\n readonly ready: boolean;\n}\n\n/** Shared auth methods without page-shell or navigation side effects. */\n@Component({\n selector: 'sneat-auth-panel',\n templateUrl: './auth-panel.component.html',\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [\n RouterLink,\n EmailLoginFormComponent,\n LoginWithTelegramComponent,\n IonButton,\n IonCard,\n IonCol,\n IonGrid,\n IonIcon,\n IonItem,\n IonItemDivider,\n IonLabel,\n IonList,\n IonRow,\n IonSpinner,\n IonText,\n ],\n providers: [RandomIdService],\n})\nexport class AuthPanelComponent implements OnInit {\n protected readonly uiConfig = inject(AUTH_PANEL_UI_CONFIG);\n protected providerVisible(provider: AuthProviderID | 'telegram'): boolean {\n return this.uiConfig.quickLoginProviders?.includes(provider) ?? true;\n }\n\n readonly returnTo = input<string | undefined>();\n readonly initialMode = input<AuthPanelInitialMode | undefined>();\n readonly showIntro = input(true);\n readonly showCredentials = input(true);\n @Output() readonly accountReadyChange =\n new EventEmitter<AuthPanelAccountReadyChange>();\n\n protected readonly signingWith = signal<\n AuthProviderID | EmailFormSigningWith | undefined\n >(undefined);\n protected readonly authRecoveryNeeded = signal(false);\n /**\n * Set when sign-in hit an email that already has an account: names the\n * provider that will be connected once the user signs in the usual way.\n */\n protected readonly pendingLink = signal<\n | {\n readonly provider: string;\n readonly email?: string;\n /** False when no credential could be kept to link later. */\n readonly autoLink: boolean;\n }\n | undefined\n >(undefined);\n protected readonly recordState = signal<\n 'signed-out' | 'loading' | 'ready' | 'failed'\n >('loading');\n protected readonly isNativePlatform = Capacitor.isNativePlatform();\n protected readonly safeReturnTo = computed(() =>\n safeAuthReturnPath(this.returnTo()),\n );\n protected readonly ssoQueryParams = computed(() => {\n const returnTo = this.safeReturnTo();\n return returnTo ? { returnTo } : undefined;\n });\n\n private readonly authStateService = inject(SneatAuthStateService);\n private readonly userService = inject(SneatUserService);\n private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);\n private readonly destroyRef = inject(DestroyRef);\n\n ngOnInit(): void {\n // A redirect sign-in that hit an existing account is read after this\n // page renders, so follow the pending link rather than reading it once.\n this.authStateService.pendingCredentialLinkChanges\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe((link) => {\n if (link) {\n this.pendingLink.set({\n provider: authProviderTitle(link.providerId),\n email: link.email,\n autoLink: true,\n });\n }\n });\n // This initial BehaviorSubject value is emitted after inputs and output\n // listeners are connected. Consumers can gate account-dependent work until\n // the matching user record is ready, even when auth resolved before mount.\n combineLatest([this.authStateService.authState, this.userService.userState])\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe(([authState, userState]) => {\n const uid = authState.user?.uid;\n const authRecoveryNeeded = authState.loadingPhase === 'failed';\n const sameIdentity =\n !!uid &&\n userState.status === 'authenticated' &&\n userState.user?.uid === uid &&\n !userState.user.isAnonymous;\n const ready = isSneatAccountReady(authState, userState);\n const failed =\n !authRecoveryNeeded &&\n authState.status === 'authenticated' &&\n !authState.user?.isAnonymous &&\n sameIdentity &&\n userState.userRecordStatus === 'failed';\n const signedOut =\n authState.status === 'notAuthenticated' ||\n authState.user?.isAnonymous === true;\n this.authRecoveryNeeded.set(authRecoveryNeeded);\n this.recordState.set(\n ready\n ? 'ready'\n : failed\n ? 'failed'\n : signedOut || authRecoveryNeeded\n ? 'signed-out'\n : 'loading',\n );\n if (\n ready ||\n authRecoveryNeeded ||\n authState.status === 'notAuthenticated'\n ) {\n this.signingWith.set(undefined);\n }\n this.accountReadyChange.emit({\n uid,\n ready,\n });\n });\n }\n\n protected retryUserRecordInitialization(): void {\n this.userService.retryUserRecordInitialization();\n }\n\n protected onEmailFormStatusChanged(signingWith?: EmailFormSigningWith): void {\n this.signingWith.set(signingWith);\n }\n\n protected async loginWith(provider: AuthProviderID): Promise<void> {\n this.signingWith.set(provider);\n markLoginRedirectIntent(this.safeReturnTo());\n try {\n await this.authStateService.signInWith(provider);\n clearLoginRedirectIntent();\n } catch (error) {\n clearLoginRedirectIntent();\n this.signingWith.set(undefined);\n if (isAccountExistsWithDifferentCredential(error)) {\n // A pending link for another provider (an earlier attempt) is not\n // this one: say how to connect this provider by hand.\n if (\n this.authStateService.pendingCredentialLink?.providerId !== provider\n ) {\n this.pendingLink.set({\n provider: authProviderTitle(provider),\n autoLink: false,\n });\n }\n return;\n }\n const message = (error as { errorMessage?: string }).errorMessage;\n if (\n message !== 'The user canceled the sign-in flow.' &&\n !message?.includes(\n 'com.apple.AuthenticationServices.AuthorizationError error 1001.',\n )\n ) {\n this.errorLogger.logError(error, `Failed to sign-in with ${provider}`);\n }\n this.signingWith.set(undefined);\n }\n }\n\n protected onLoggedIn(userCredential: UserCredential): void {\n this.signingWith.set(undefined);\n if (!userCredential.user) return;\n if (userCredential.user.email) {\n const previousEmail = localStorage.getItem('emailForSignIn') || '';\n if (!previousEmail) {\n localStorage.setItem('emailForSignIn', userCredential.user.email);\n }\n }\n const authState: ISneatAuthState = {\n status: AuthStatuses.authenticated,\n user: userCredential.user,\n };\n this.userService.onUserSignedIn(authState);\n }\n}\n","@if (authRecoveryNeeded()) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n We couldn't complete sign-in. Try again with email or another sign-in\n method.\n </p>\n </div>\n}\n\n@if (pendingLink(); as link) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n @if (link.email) {\n <b>{{ link.email }}</b> already has an account.\n } @else {\n This email already has an account.\n }\n Sign in the way you did before — with email or another sign-in method —\n @if (link.autoLink) {\n and we'll connect {{ link.provider }} to it automatically.\n } @else {\n then connect {{ link.provider }} from your account page.\n }\n </p>\n </div>\n}\n\n@if (recordState() === 'failed') {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>Your account is still being prepared. Retry before continuing.</p>\n <ion-button fill=\"outline\" (click)=\"retryUserRecordInitialization()\">\n Retry account setup\n </ion-button>\n </div>\n} @else if (recordState() === 'loading') {\n <div class=\"ion-padding ion-text-center\" role=\"status\" aria-live=\"polite\">\n <ion-spinner name=\"lines-small\" />\n <p>Preparing your account…</p>\n </div>\n} @else {\n @if (showCredentials() || authRecoveryNeeded()) {\n @if (showIntro()) {\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">Sign in with your Sneat account.</ion-text>\n </p>\n }\n\n <sneat-email-login-form\n [returnTo]=\"safeReturnTo()\"\n [initialMode]=\"initialMode()\"\n (signingWithChange)=\"onEmailFormStatusChanged($event)\"\n (loggedIn)=\"onLoggedIn($event)\"\n />\n\n <div class=\"ion-padding-horizontal ion-text-center\">\n <ion-button\n fill=\"outline\"\n expand=\"block\"\n routerLink=\"/sso\"\n [queryParams]=\"ssoQueryParams()\"\n [disabled]=\"!!signingWith()\"\n >\n <ion-icon name=\"business-outline\" slot=\"start\" />\n Sign in with company SSO\n </ion-button>\n </div>\n\n @if (uiConfig.quickLoginProviders?.length !== 0) {\n <ion-card>\n @if (uiConfig.showQuickLoginHeader !== false) {\n <ion-item-divider color=\"light\">\n <ion-label\n color=\"medium\"\n style=\"text-align: center; width: 100%; font-weight: bold\"\n >\n Quick login\n </ion-label>\n </ion-item-divider>\n }\n <ion-grid class=\"ion-grid-layout\">\n @if (!isNativePlatform && providerVisible('telegram')) {\n <ion-row>\n <ion-col>\n <div class=\"ion-padding\" style=\"text-align: center\">\n <sneat-login-with-telegram />\n </div>\n </ion-col>\n </ion-row>\n }\n <ion-row>\n @if (providerVisible('google.com')) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n (click)=\"loginWith('google.com')\"\n tappable\n [disabled]=\"!!signingWith()\"\n >\n @if (signingWith() === 'google.com') {\n <ion-spinner slot=\"start\" name=\"lines-small\" />\n } @else {\n <ion-icon\n color=\"danger\"\n name=\"logo-google\"\n slot=\"start\"\n />\n }\n <ion-label color=\"danger\"> Login with Google</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n }\n @if (providerVisible('apple.com')) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n (click)=\"loginWith('apple.com')\"\n tappable\n [disabled]=\"!!signingWith()\"\n >\n @if (signingWith() === 'apple.com') {\n <ion-spinner slot=\"start\" name=\"lines-small\" />\n } @else {\n <ion-icon color=\"dark\" name=\"logo-apple\" slot=\"start\" />\n }\n <ion-label color=\"dark\">Login with Apple</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n }\n </ion-row>\n <ion-row>\n @if (providerVisible('microsoft.com')) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n (click)=\"loginWith('microsoft.com')\"\n tappable\n [disabled]=\"!!signingWith()\"\n >\n @if (signingWith() === 'microsoft.com') {\n <ion-spinner\n slot=\"start\"\n color=\"secondary\"\n name=\"lines-small\"\n />\n } @else {\n <ion-icon\n slot=\"start\"\n color=\"secondary\"\n name=\"logo-windows\"\n />\n }\n <ion-label color=\"secondary\"\n >Login with Microsoft</ion-label\n >\n </ion-item>\n </ion-list>\n </ion-col>\n }\n @if (providerVisible('facebook.com')) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n (click)=\"loginWith('facebook.com')\"\n tappable\n [disabled]=\"!!signingWith()\"\n >\n @if (signingWith() === 'facebook.com') {\n <ion-spinner\n slot=\"start\"\n color=\"primary\"\n name=\"lines-small\"\n />\n } @else {\n <ion-icon\n slot=\"start\"\n color=\"primary\"\n name=\"logo-facebook\"\n />\n }\n <ion-label color=\"primary\">Login with Facebook</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n }\n </ion-row>\n <ion-row>\n @if (providerVisible('github.com')) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n (click)=\"loginWith('github.com')\"\n tappable\n [disabled]=\"!!signingWith()\"\n >\n @if (signingWith() === 'github.com') {\n <ion-spinner\n slot=\"start\"\n color=\"tertiary\"\n name=\"lines-small\"\n />\n } @else {\n <ion-icon\n slot=\"start\"\n color=\"tertiary\"\n name=\"logo-github\"\n />\n }\n <ion-label color=\"tertiary\">Login with GitHub</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n }\n </ion-row>\n </ion-grid>\n </ion-card>\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"auth-panel.component.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/auth-panel.component.ts","../../../../../../../../libs/auth/ui/src/lib/pages/login-page/auth-panel.component.html"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,SAAS,EACT,UAAU,EACV,YAAY,EAEZ,MAAM,EACN,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAEL,YAAY,EAEZ,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,sCAAsC,EACtC,mBAAmB,GACpB,MAA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,6FACR,MAAM,oDACN,UAAU,yGACV,OAAO;;2FAIE,kBAAkB;kBAtB9B,SAAS;+BACE,kBAAkB,mBAEX,uBAAuB,CAAC,MAAM,WACtC;wBACP,UAAU;wBACV,4BAA4B;wBAC5B,uBAAuB;wBACvB,0BAA0B;wBAC1B,SAAS;wBACT,OAAO;wBACP,MAAM;wBACN,OAAO;wBACP,OAAO;wBACP,cAAc;wBACd,QAAQ;wBACR,MAAM;wBACN,UAAU;wBACV,OAAO;qBACR,aACU,CAAC,eAAe,CAAC;;sBAY3B,MAAM","sourcesContent":["import {\n AuthProviderButtonsComponent,\n OAUTH_PROVIDER_IDS,\n} from '@sneat/auth-ui/provider-buttons';\nimport {\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n EventEmitter,\n OnInit,\n Output,\n computed,\n inject,\n input,\n signal,\n} from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { RouterLink } from '@angular/router';\nimport { Capacitor } from '@capacitor/core';\nimport {\n AuthProviderID,\n AuthStatuses,\n ISneatAuthState,\n SneatAuthStateService,\n SneatUserService,\n authProviderTitle,\n isAccountExistsWithDifferentCredential,\n isSneatAccountReady,\n} from '@sneat/auth-core';\nimport { ErrorLogger, IErrorLogger } from '@sneat/core';\nimport { UserCredential } from 'firebase/auth';\nimport {\n IonButton,\n IonCard,\n IonCol,\n IonGrid,\n IonIcon,\n IonItemDivider,\n IonLabel,\n IonRow,\n IonSpinner,\n IonText,\n} from '@ionic/angular';\nimport {\n AuthPanelInitialMode,\n EmailFormSigningWith,\n EmailLoginFormComponent,\n} from './email-login-form/email-login-form.component';\nimport { LoginWithTelegramComponent } from './login-with-telegram.component';\nimport { safeAuthReturnPath } from './safe-auth-return-path';\nimport {\n clearLoginRedirectIntent,\n markLoginRedirectIntent,\n} from './login-redirect-intent';\nimport { combineLatest } from 'rxjs';\nimport { AUTH_PANEL_UI_CONFIG } from './auth-panel-ui-config';\nimport { RandomIdService } from '@sneat/random';\n\nexport interface AuthPanelAccountReadyChange {\n readonly uid?: string;\n readonly ready: boolean;\n}\n\n/** Shared auth methods without page-shell or navigation side effects. */\n@Component({\n selector: 'sneat-auth-panel',\n templateUrl: './auth-panel.component.html',\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [\n RouterLink,\n AuthProviderButtonsComponent,\n EmailLoginFormComponent,\n LoginWithTelegramComponent,\n IonButton,\n IonCard,\n IonCol,\n IonGrid,\n IonIcon,\n IonItemDivider,\n IonLabel,\n IonRow,\n IonSpinner,\n IonText,\n ],\n providers: [RandomIdService],\n})\nexport class AuthPanelComponent implements OnInit {\n protected readonly uiConfig = inject(AUTH_PANEL_UI_CONFIG);\n protected providerVisible(provider: AuthProviderID | 'telegram'): boolean {\n return this.uiConfig.quickLoginProviders?.includes(provider) ?? true;\n }\n\n readonly returnTo = input<string | undefined>();\n readonly initialMode = input<AuthPanelInitialMode | undefined>();\n readonly showIntro = input(true);\n readonly showCredentials = input(true);\n @Output() readonly accountReadyChange =\n new EventEmitter<AuthPanelAccountReadyChange>();\n\n protected readonly signingWith = signal<\n AuthProviderID | EmailFormSigningWith | undefined\n >(undefined);\n protected readonly oauthProviders = OAUTH_PROVIDER_IDS.filter((provider) =>\n this.providerVisible(provider),\n );\n protected readonly oauthSigningWith = computed(() =>\n OAUTH_PROVIDER_IDS.find((provider) => provider === this.signingWith()),\n );\n protected readonly authRecoveryNeeded = signal(false);\n /**\n * Set when sign-in hit an email that already has an account: names the\n * provider that will be connected once the user signs in the usual way.\n */\n protected readonly pendingLink = signal<\n | {\n readonly provider: string;\n readonly email?: string;\n /** False when no credential could be kept to link later. */\n readonly autoLink: boolean;\n }\n | undefined\n >(undefined);\n protected readonly recordState = signal<\n 'signed-out' | 'loading' | 'ready' | 'failed'\n >('loading');\n protected readonly isNativePlatform = Capacitor.isNativePlatform();\n protected readonly safeReturnTo = computed(() =>\n safeAuthReturnPath(this.returnTo()),\n );\n protected readonly ssoQueryParams = computed(() => {\n const returnTo = this.safeReturnTo();\n return returnTo ? { returnTo } : undefined;\n });\n\n private readonly authStateService = inject(SneatAuthStateService);\n private readonly userService = inject(SneatUserService);\n private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);\n private readonly destroyRef = inject(DestroyRef);\n\n ngOnInit(): void {\n // A redirect sign-in that hit an existing account is read after this\n // page renders, so follow the pending link rather than reading it once.\n this.authStateService.pendingCredentialLinkChanges\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe((link) => {\n if (link) {\n this.pendingLink.set({\n provider: authProviderTitle(link.providerId),\n email: link.email,\n autoLink: true,\n });\n }\n });\n // This initial BehaviorSubject value is emitted after inputs and output\n // listeners are connected. Consumers can gate account-dependent work until\n // the matching user record is ready, even when auth resolved before mount.\n combineLatest([this.authStateService.authState, this.userService.userState])\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe(([authState, userState]) => {\n const uid = authState.user?.uid;\n const authRecoveryNeeded = authState.loadingPhase === 'failed';\n const sameIdentity =\n !!uid &&\n userState.status === 'authenticated' &&\n userState.user?.uid === uid &&\n !userState.user.isAnonymous;\n const ready = isSneatAccountReady(authState, userState);\n const failed =\n !authRecoveryNeeded &&\n authState.status === 'authenticated' &&\n !authState.user?.isAnonymous &&\n sameIdentity &&\n userState.userRecordStatus === 'failed';\n const signedOut =\n authState.status === 'notAuthenticated' ||\n authState.user?.isAnonymous === true;\n this.authRecoveryNeeded.set(authRecoveryNeeded);\n this.recordState.set(\n ready\n ? 'ready'\n : failed\n ? 'failed'\n : signedOut || authRecoveryNeeded\n ? 'signed-out'\n : 'loading',\n );\n if (\n ready ||\n authRecoveryNeeded ||\n authState.status === 'notAuthenticated'\n ) {\n this.signingWith.set(undefined);\n }\n this.accountReadyChange.emit({\n uid,\n ready,\n });\n });\n }\n\n protected retryUserRecordInitialization(): void {\n this.userService.retryUserRecordInitialization();\n }\n\n protected onEmailFormStatusChanged(signingWith?: EmailFormSigningWith): void {\n this.signingWith.set(signingWith);\n }\n\n protected async loginWith(provider: AuthProviderID): Promise<void> {\n this.signingWith.set(provider);\n markLoginRedirectIntent(this.safeReturnTo());\n try {\n await this.authStateService.signInWith(provider);\n clearLoginRedirectIntent();\n } catch (error) {\n clearLoginRedirectIntent();\n this.signingWith.set(undefined);\n if (isAccountExistsWithDifferentCredential(error)) {\n // A pending link for another provider (an earlier attempt) is not\n // this one: say how to connect this provider by hand.\n if (\n this.authStateService.pendingCredentialLink?.providerId !== provider\n ) {\n this.pendingLink.set({\n provider: authProviderTitle(provider),\n autoLink: false,\n });\n }\n return;\n }\n const message = (error as { errorMessage?: string }).errorMessage;\n if (\n message !== 'The user canceled the sign-in flow.' &&\n !message?.includes(\n 'com.apple.AuthenticationServices.AuthorizationError error 1001.',\n )\n ) {\n this.errorLogger.logError(error, `Failed to sign-in with ${provider}`);\n }\n this.signingWith.set(undefined);\n }\n }\n\n protected onLoggedIn(userCredential: UserCredential): void {\n this.signingWith.set(undefined);\n if (!userCredential.user) return;\n if (userCredential.user.email) {\n const previousEmail = localStorage.getItem('emailForSignIn') || '';\n if (!previousEmail) {\n localStorage.setItem('emailForSignIn', userCredential.user.email);\n }\n }\n const authState: ISneatAuthState = {\n status: AuthStatuses.authenticated,\n user: userCredential.user,\n };\n this.userService.onUserSignedIn(authState);\n }\n}\n","@if (authRecoveryNeeded()) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n We couldn't complete sign-in. Try again with email or another sign-in\n method.\n </p>\n </div>\n}\n\n@if (pendingLink(); as link) {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>\n @if (link.email) {\n <b>{{ link.email }}</b> already has an account.\n } @else {\n This email already has an account.\n }\n Sign in the way you did before — with email or another sign-in method —\n @if (link.autoLink) {\n and we'll connect {{ link.provider }} to it automatically.\n } @else {\n then connect {{ link.provider }} from your account page.\n }\n </p>\n </div>\n}\n\n@if (recordState() === 'failed') {\n <div class=\"ion-padding ion-text-center\" role=\"alert\">\n <p>Your account is still being prepared. Retry before continuing.</p>\n <ion-button fill=\"outline\" (click)=\"retryUserRecordInitialization()\">\n Retry account setup\n </ion-button>\n </div>\n} @else if (recordState() === 'loading') {\n <div class=\"ion-padding ion-text-center\" role=\"status\" aria-live=\"polite\">\n <ion-spinner name=\"lines-small\" />\n <p>Preparing your account…</p>\n </div>\n} @else {\n @if (showCredentials() || authRecoveryNeeded()) {\n @if (showIntro()) {\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">Sign in with your Sneat account.</ion-text>\n </p>\n }\n\n <sneat-email-login-form\n [returnTo]=\"safeReturnTo()\"\n [initialMode]=\"initialMode()\"\n (signingWithChange)=\"onEmailFormStatusChanged($event)\"\n (loggedIn)=\"onLoggedIn($event)\"\n />\n\n <div class=\"ion-padding-horizontal ion-text-center\">\n <ion-button\n fill=\"outline\"\n expand=\"block\"\n routerLink=\"/sso\"\n [queryParams]=\"ssoQueryParams()\"\n [disabled]=\"!!signingWith()\"\n >\n <ion-icon name=\"business-outline\" slot=\"start\" />\n Sign in with company SSO\n </ion-button>\n </div>\n\n @if (uiConfig.quickLoginProviders?.length !== 0) {\n <ion-card>\n @if (uiConfig.showQuickLoginHeader !== false) {\n <ion-item-divider color=\"light\">\n <ion-label\n color=\"medium\"\n style=\"text-align: center; width: 100%; font-weight: bold\"\n >\n Quick login\n </ion-label>\n </ion-item-divider>\n }\n <ion-grid class=\"ion-grid-layout\">\n @if (!isNativePlatform && providerVisible('telegram')) {\n <ion-row>\n <ion-col>\n <div class=\"ion-padding\" style=\"text-align: center\">\n <sneat-login-with-telegram />\n </div>\n </ion-col>\n </ion-row>\n }\n <sneat-auth-provider-buttons\n [providers]=\"oauthProviders\"\n [busy]=\"oauthSigningWith()\"\n [disabled]=\"!!signingWith()\"\n (providerSelected)=\"loginWith($event)\"\n />\n </ion-grid>\n </ion-card>\n }\n }\n}\n"]}
|
|
@@ -2,6 +2,7 @@ import { DOCUMENT } from '@angular/common';
|
|
|
2
2
|
import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, inject, input, signal, } from '@angular/core';
|
|
3
3
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
4
4
|
import { ErrorLogger } from '@sneat/core';
|
|
5
|
+
import { newRandomId } from '@sneat/random';
|
|
5
6
|
import { SneatAuthWithTelegramService, } from './sneat-auth-with-telegram.service';
|
|
6
7
|
import { TelegramLoginConfig, resolveTelegramBotID, } from './telegram-login-config';
|
|
7
8
|
import { loadTelegramLoginScript, telegramLoginApi, } from './telegram-login-js';
|
|
@@ -23,6 +24,12 @@ export class LoginWithTelegramComponent {
|
|
|
23
24
|
this.telegramLoginConfig = inject(TelegramLoginConfig, {
|
|
24
25
|
optional: true,
|
|
25
26
|
});
|
|
27
|
+
this.legacyCallbackName = `sneatTelegramAuth_${newRandomId({
|
|
28
|
+
len: 20,
|
|
29
|
+
digits: true,
|
|
30
|
+
lowerCaseLetters: true,
|
|
31
|
+
upperCaseLetters: true,
|
|
32
|
+
})}`;
|
|
26
33
|
this.isUserAuthenticated = input(false, /* @ts-ignore */
|
|
27
34
|
...(ngDevMode ? [{ debugName: "isUserAuthenticated" }] : /* istanbul ignore next */ []));
|
|
28
35
|
this.botID = input(resolveTelegramBotID(this.telegramLoginConfig, location.hostname), /* @ts-ignore */
|
|
@@ -40,8 +47,8 @@ export class LoginWithTelegramComponent {
|
|
|
40
47
|
this.destroyRef.onDestroy(() => {
|
|
41
48
|
clearInterval(this.nonceTimer);
|
|
42
49
|
const host = this.document.defaultView;
|
|
43
|
-
if (host && host.
|
|
44
|
-
delete host.
|
|
50
|
+
if (host && host[this.legacyCallbackName] === this.legacyCallback)
|
|
51
|
+
delete host[this.legacyCallbackName];
|
|
45
52
|
});
|
|
46
53
|
}
|
|
47
54
|
ngOnInit() {
|
|
@@ -115,7 +122,7 @@ export class LoginWithTelegramComponent {
|
|
|
115
122
|
const host = this.document.defaultView;
|
|
116
123
|
if (!host)
|
|
117
124
|
return;
|
|
118
|
-
host.
|
|
125
|
+
host[this.legacyCallbackName] = this.legacyCallback;
|
|
119
126
|
const script = this.document.createElement('script');
|
|
120
127
|
script.src = 'https://telegram.org/js/telegram-widget.js?22';
|
|
121
128
|
script.setAttribute('data-telegram-login', botID);
|
|
@@ -124,7 +131,7 @@ export class LoginWithTelegramComponent {
|
|
|
124
131
|
if (!this.userPic()) {
|
|
125
132
|
script.setAttribute('data-userpic', 'false');
|
|
126
133
|
}
|
|
127
|
-
script.setAttribute('data-onauth',
|
|
134
|
+
script.setAttribute('data-onauth', `${this.legacyCallbackName}(user)`);
|
|
128
135
|
this.el.nativeElement.appendChild(script);
|
|
129
136
|
}
|
|
130
137
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: LoginWithTelegramComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login-with-telegram.component.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/login-with-telegram.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACL,uBAAuB,EACvB,SAAS,EACT,UAAU,EACV,UAAU,EAEV,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAC;AACxD,OAAO,EAGL,4BAA4B,GAC7B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;;AAE7B,+DAA+D;AAC/D,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE5C;;;;GAIG;AAwCH,MAAM,OAAO,0BAA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C,iBAAiB,CACrC,KAAK,EACL,UAAU,EACV,IAAI,CAAC,mBAAmB,EAAE,CAC3B,CAAC;QACJ,CAAC,CAAC;QAEF,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,WAEnB,CAAC;QACT,IAAI,CAAC,IAAI;YAAE,OAAO;QAClB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAErD,MAAM,CAAC,GAAG,GAAG,+CAA+C,CAAC;QAC7D,MAAM,CAAC,YAAY,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;QAClD,MAAM,CAAC,YAAY,CAAC,qBAAqB,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QACjE,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YACpB,MAAM,CAAC,YAAY,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;QACD,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,sBAAsB,CAAC,CAAC;QAC3D,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;8GA7IU,0BAA0B;kGAA1B,0BAA0B,ivBAtC1B,CAAC,4BAA4B,CAAC,0BAG/B;;;;;;;;;;;GAWT;;2FAwBU,0BAA0B;kBAvCtC,SAAS;gCACG,CAAC,4BAA4B,CAAC,YAC/B,2BAA2B,mBACpB,uBAAuB,CAAC,MAAM,YACrC;;;;;;;;;;;GAWT","sourcesContent":["import { DOCUMENT } from '@angular/common';\nimport {\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n OnInit,\n inject,\n input,\n signal,\n} from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { ErrorLogger, IErrorLogger } from '@sneat/core';\nimport {\n ITelegramAuthData,\n ITelegramOIDCNonce,\n SneatAuthWithTelegramService,\n} from './sneat-auth-with-telegram.service';\nimport {\n TelegramLoginConfig,\n resolveTelegramBotID,\n} from './telegram-login-config';\nimport {\n ITelegramLoginResult,\n loadTelegramLoginScript,\n telegramLoginApi,\n} from './telegram-login-js';\n\n/** Server nonces live 10 minutes; refresh well inside that. */\nconst OIDC_NONCE_REFRESH_MS = 8 * 60 * 1000;\n\n/**\n * Telegram login button. Bots with OpenID login configured server-side use\n * Telegram's OpenID popup (telegram-login.js); others keep the legacy Login\n * Widget (telegram-widget.js), e.g. the local dev bot.\n */\n@Component({\n providers: [SneatAuthWithTelegramService],\n selector: 'sneat-login-with-telegram',\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: `\n @if (oidc(); as cfg) {\n <button\n type=\"button\"\n class=\"tg-oidc-login\"\n [attr.data-size]=\"size()\"\n (click)=\"loginWithOIDC(cfg)\"\n >\n Log in with Telegram\n </button>\n }\n `,\n styles: [\n `\n .tg-oidc-login {\n background: #54a9eb;\n color: #fff;\n border: 0;\n border-radius: 20px;\n font-weight: 500;\n cursor: pointer;\n font-size: 16px;\n padding: 10px 21px;\n }\n .tg-oidc-login[data-size='medium'] {\n font-size: 14px;\n padding: 8px 16px;\n }\n .tg-oidc-login[data-size='small'] {\n font-size: 13px;\n padding: 6px 12px;\n }\n `,\n ],\n})\nexport class LoginWithTelegramComponent implements OnInit {\n private readonly el = inject(ElementRef);\n private readonly document = inject<Document>(DOCUMENT);\n private readonly destroyRef = inject(DestroyRef);\n private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);\n readonly authWithTelegram = inject(SneatAuthWithTelegramService);\n private readonly telegramLoginConfig = inject(TelegramLoginConfig, {\n optional: true,\n });\n\n private nonceTimer?: ReturnType<typeof setInterval>;\n private legacyCallback?: (data: ITelegramAuthData) => void;\n\n constructor() {\n // Register while the view is alive, never from a late loader continuation.\n this.destroyRef.onDestroy(() => {\n clearInterval(this.nonceTimer);\n const host = this.document.defaultView as\n | (Window & { onTelegramAuth?: (data: ITelegramAuthData) => void })\n | null;\n if (host && host.onTelegramAuth === this.legacyCallback)\n delete host.onTelegramAuth;\n });\n }\n\n public readonly isUserAuthenticated = input(false);\n\n public readonly botID = input<string>(\n resolveTelegramBotID(this.telegramLoginConfig, location.hostname),\n );\n\n public readonly size = input<'small' | 'medium' | 'large'>('large');\n public readonly requestAccess = input<'write' | 'read'>('write');\n public readonly userPic = input(true);\n\n /** Set once the OpenID popup can be offered: Client ID plus a live nonce. */\n protected readonly oidc = signal<ITelegramOIDCNonce | undefined>(undefined);\n\n ngOnInit() {\n const botID = this.botID();\n if (!botID) {\n return;\n }\n this.authWithTelegram\n .getTelegramOIDCNonce(botID)\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe({\n next: (cfg) => this.startOIDC(botID, cfg),\n // The server answers 400 for a bot without OpenID login configured.\n error: () => this.startLegacyWidget(botID),\n });\n }\n\n protected loginWithOIDC(cfg: ITelegramOIDCNonce): void {\n if (this.destroyRef.destroyed) return;\n const api = telegramLoginApi(this.document.defaultView ?? window);\n if (!api) {\n this.errorLogger.logErrorHandler('Telegram login library not loaded')(\n new Error('window.Telegram.Login is undefined'),\n );\n return;\n }\n const botID = this.botID();\n // Called straight from the click handler: the library opens its popup\n // synchronously, which keeps the browser's popup blocker out of the way.\n api.auth(\n {\n client_id: Number(cfg.clientID),\n nonce: cfg.nonce,\n request_access: this.requestAccess() === 'write' ? ['write'] : [],\n },\n (result: ITelegramLoginResult) => {\n if (result.id_token && !this.destroyRef.destroyed) {\n this.authWithTelegram.loginWithTelegramOIDC(\n botID,\n result.id_token,\n this.isUserAuthenticated(),\n );\n this.refreshNonce(botID);\n }\n // result.error (e.g. the user closed the popup) needs no action:\n // the button stays, and the user can try again.\n },\n );\n }\n\n private startOIDC(botID: string, cfg: ITelegramOIDCNonce): void {\n loadTelegramLoginScript(this.document).then(() => {\n if (this.destroyRef.destroyed) return;\n this.oidc.set(cfg);\n clearInterval(this.nonceTimer);\n this.nonceTimer = setInterval(\n () => this.refreshNonce(botID),\n OIDC_NONCE_REFRESH_MS,\n );\n }, this.errorLogger.logErrorHandler('Failed to load Telegram login library'));\n }\n\n private refreshNonce(botID: string): void {\n this.authWithTelegram\n .getTelegramOIDCNonce(botID)\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe({\n next: (cfg) => this.oidc.set(cfg),\n error: this.errorLogger.logErrorHandler(\n 'Failed to refresh Telegram login nonce',\n ),\n });\n }\n\n private startLegacyWidget(botID: string): void {\n if (this.destroyRef.destroyed) return;\n this.legacyCallback = (tgAuthData: ITelegramAuthData) => {\n if (this.destroyRef.destroyed) return;\n // https://core.telegram.org/widgets/login-legacy\n // After a successful authorization, the widget returns data\n // by calling the callback function data-onauth with the JSON-object containing\n // id, first_name, last_name, username, photo_url, auth_date and hash fields.\n this.authWithTelegram.loginWithTelegram(\n botID,\n tgAuthData,\n this.isUserAuthenticated(),\n );\n };\n\n const host = this.document.defaultView as\n | (Window & { onTelegramAuth?: (data: ITelegramAuthData) => void })\n | null;\n if (!host) return;\n host.onTelegramAuth = this.legacyCallback;\n const script = this.document.createElement('script');\n\n script.src = 'https://telegram.org/js/telegram-widget.js?22';\n script.setAttribute('data-telegram-login', botID);\n script.setAttribute('data-request-access', this.requestAccess());\n script.setAttribute('data-size', this.size());\n if (!this.userPic()) {\n script.setAttribute('data-userpic', 'false');\n }\n script.setAttribute('data-onauth', 'onTelegramAuth(user)');\n this.el.nativeElement.appendChild(script);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"login-with-telegram.component.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/login-with-telegram.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACL,uBAAuB,EACvB,SAAS,EACT,UAAU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qB,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QACjE,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YACpB,MAAM,CAAC,YAAY,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;QACD,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,GAAG,IAAI,CAAC,kBAAkB,QAAQ,CAAC,CAAC;QACvE,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;8GA/IU,0BAA0B;kGAA1B,0BAA0B,ivBAtC1B,CAAC,4BAA4B,CAAC,0BAG/B;;;;;;;;;;;GAWT;;2FAwBU,0BAA0B;kBAvCtC,SAAS;gCACG,CAAC,4BAA4B,CAAC,YAC/B,2BAA2B,mBACpB,uBAAuB,CAAC,MAAM,YACrC;;;;;;;;;;;GAWT","sourcesContent":["import { DOCUMENT } from '@angular/common';\nimport {\n ChangeDetectionStrategy,\n Component,\n DestroyRef,\n ElementRef,\n OnInit,\n inject,\n input,\n signal,\n} from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { ErrorLogger, IErrorLogger } from '@sneat/core';\nimport { newRandomId } from '@sneat/random';\nimport {\n ITelegramAuthData,\n ITelegramOIDCNonce,\n SneatAuthWithTelegramService,\n} from './sneat-auth-with-telegram.service';\nimport {\n TelegramLoginConfig,\n resolveTelegramBotID,\n} from './telegram-login-config';\nimport {\n ITelegramLoginResult,\n loadTelegramLoginScript,\n telegramLoginApi,\n} from './telegram-login-js';\n\n/** Server nonces live 10 minutes; refresh well inside that. */\nconst OIDC_NONCE_REFRESH_MS = 8 * 60 * 1000;\n\ntype LegacyTelegramWindow = Window & {\n [name: `sneatTelegramAuth_${string}`]:\n ((data: ITelegramAuthData) => void) | undefined;\n};\n\n/**\n * Telegram login button. Bots with OpenID login configured server-side use\n * Telegram's OpenID popup (telegram-login.js); others keep the legacy Login\n * Widget (telegram-widget.js), e.g. the local dev bot.\n */\n@Component({\n providers: [SneatAuthWithTelegramService],\n selector: 'sneat-login-with-telegram',\n changeDetection: ChangeDetectionStrategy.OnPush,\n template: `\n @if (oidc(); as cfg) {\n <button\n type=\"button\"\n class=\"tg-oidc-login\"\n [attr.data-size]=\"size()\"\n (click)=\"loginWithOIDC(cfg)\"\n >\n Log in with Telegram\n </button>\n }\n `,\n styles: [\n `\n .tg-oidc-login {\n background: #54a9eb;\n color: #fff;\n border: 0;\n border-radius: 20px;\n font-weight: 500;\n cursor: pointer;\n font-size: 16px;\n padding: 10px 21px;\n }\n .tg-oidc-login[data-size='medium'] {\n font-size: 14px;\n padding: 8px 16px;\n }\n .tg-oidc-login[data-size='small'] {\n font-size: 13px;\n padding: 6px 12px;\n }\n `,\n ],\n})\nexport class LoginWithTelegramComponent implements OnInit {\n private readonly el = inject(ElementRef);\n private readonly document = inject<Document>(DOCUMENT);\n private readonly destroyRef = inject(DestroyRef);\n private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);\n readonly authWithTelegram = inject(SneatAuthWithTelegramService);\n private readonly telegramLoginConfig = inject(TelegramLoginConfig, {\n optional: true,\n });\n\n private nonceTimer?: ReturnType<typeof setInterval>;\n private legacyCallback?: (data: ITelegramAuthData) => void;\n private readonly legacyCallbackName = `sneatTelegramAuth_${newRandomId({\n len: 20,\n digits: true,\n lowerCaseLetters: true,\n upperCaseLetters: true,\n })}` as const;\n\n constructor() {\n // Register while the view is alive, never from a late loader continuation.\n this.destroyRef.onDestroy(() => {\n clearInterval(this.nonceTimer);\n const host = this.document.defaultView as LegacyTelegramWindow | null;\n if (host && host[this.legacyCallbackName] === this.legacyCallback)\n delete host[this.legacyCallbackName];\n });\n }\n\n public readonly isUserAuthenticated = input(false);\n\n public readonly botID = input<string>(\n resolveTelegramBotID(this.telegramLoginConfig, location.hostname),\n );\n\n public readonly size = input<'small' | 'medium' | 'large'>('large');\n public readonly requestAccess = input<'write' | 'read'>('write');\n public readonly userPic = input(true);\n\n /** Set once the OpenID popup can be offered: Client ID plus a live nonce. */\n protected readonly oidc = signal<ITelegramOIDCNonce | undefined>(undefined);\n\n ngOnInit() {\n const botID = this.botID();\n if (!botID) {\n return;\n }\n this.authWithTelegram\n .getTelegramOIDCNonce(botID)\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe({\n next: (cfg) => this.startOIDC(botID, cfg),\n // The server answers 400 for a bot without OpenID login configured.\n error: () => this.startLegacyWidget(botID),\n });\n }\n\n protected loginWithOIDC(cfg: ITelegramOIDCNonce): void {\n if (this.destroyRef.destroyed) return;\n const api = telegramLoginApi(this.document.defaultView ?? window);\n if (!api) {\n this.errorLogger.logErrorHandler('Telegram login library not loaded')(\n new Error('window.Telegram.Login is undefined'),\n );\n return;\n }\n const botID = this.botID();\n // Called straight from the click handler: the library opens its popup\n // synchronously, which keeps the browser's popup blocker out of the way.\n api.auth(\n {\n client_id: Number(cfg.clientID),\n nonce: cfg.nonce,\n request_access: this.requestAccess() === 'write' ? ['write'] : [],\n },\n (result: ITelegramLoginResult) => {\n if (result.id_token && !this.destroyRef.destroyed) {\n this.authWithTelegram.loginWithTelegramOIDC(\n botID,\n result.id_token,\n this.isUserAuthenticated(),\n );\n this.refreshNonce(botID);\n }\n // result.error (e.g. the user closed the popup) needs no action:\n // the button stays, and the user can try again.\n },\n );\n }\n\n private startOIDC(botID: string, cfg: ITelegramOIDCNonce): void {\n loadTelegramLoginScript(this.document).then(() => {\n if (this.destroyRef.destroyed) return;\n this.oidc.set(cfg);\n clearInterval(this.nonceTimer);\n this.nonceTimer = setInterval(\n () => this.refreshNonce(botID),\n OIDC_NONCE_REFRESH_MS,\n );\n }, this.errorLogger.logErrorHandler('Failed to load Telegram login library'));\n }\n\n private refreshNonce(botID: string): void {\n this.authWithTelegram\n .getTelegramOIDCNonce(botID)\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe({\n next: (cfg) => this.oidc.set(cfg),\n error: this.errorLogger.logErrorHandler(\n 'Failed to refresh Telegram login nonce',\n ),\n });\n }\n\n private startLegacyWidget(botID: string): void {\n if (this.destroyRef.destroyed) return;\n this.legacyCallback = (tgAuthData: ITelegramAuthData) => {\n if (this.destroyRef.destroyed) return;\n // https://core.telegram.org/widgets/login-legacy\n // After a successful authorization, the widget returns data\n // by calling the callback function data-onauth with the JSON-object containing\n // id, first_name, last_name, username, photo_url, auth_date and hash fields.\n this.authWithTelegram.loginWithTelegram(\n botID,\n tgAuthData,\n this.isUserAuthenticated(),\n );\n };\n\n const host = this.document.defaultView as LegacyTelegramWindow | null;\n if (!host) return;\n host[this.legacyCallbackName] = this.legacyCallback;\n const script = this.document.createElement('script');\n\n script.src = 'https://telegram.org/js/telegram-widget.js?22';\n script.setAttribute('data-telegram-login', botID);\n script.setAttribute('data-request-access', this.requestAccess());\n script.setAttribute('data-size', this.size());\n if (!this.userPic()) {\n script.setAttribute('data-userpic', 'false');\n }\n script.setAttribute('data-onauth', `${this.legacyCallbackName}(user)`);\n this.el.nativeElement.appendChild(script);\n }\n}\n"]}
|
|
@@ -1,13 +1,45 @@
|
|
|
1
|
-
import { Injectable, inject } from '@angular/core';
|
|
1
|
+
import { DestroyRef, Injectable, inject } from '@angular/core';
|
|
2
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
2
3
|
import { SneatApiService } from '@sneat/api';
|
|
3
|
-
import { SneatAuthStateService } from '@sneat/auth-core';
|
|
4
|
+
import { AuthStatuses, SneatAuthStateService, } from '@sneat/auth-core';
|
|
4
5
|
import { ErrorLogger } from '@sneat/core';
|
|
6
|
+
import { filter, take, takeUntil } from 'rxjs';
|
|
5
7
|
import * as i0 from "@angular/core";
|
|
6
8
|
export class SneatAuthWithTelegramService {
|
|
7
9
|
constructor() {
|
|
8
10
|
this.errorLogger = inject(ErrorLogger);
|
|
9
11
|
this.apiService = inject(SneatApiService);
|
|
10
12
|
this.authService = inject(SneatAuthStateService);
|
|
13
|
+
this.destroyRef = inject(DestroyRef);
|
|
14
|
+
this.linkContextInvalidated = false;
|
|
15
|
+
// Auth state replays its current principal synchronously. If it is not
|
|
16
|
+
// ready, authenticated linking fails closed for this control's lifetime.
|
|
17
|
+
let initialState;
|
|
18
|
+
this.authService.authState
|
|
19
|
+
.pipe(take(1), takeUntilDestroyed(this.destroyRef))
|
|
20
|
+
.subscribe((state) => {
|
|
21
|
+
initialState = state;
|
|
22
|
+
});
|
|
23
|
+
this.linkUserID =
|
|
24
|
+
initialState?.status === AuthStatuses.authenticated
|
|
25
|
+
? initialState.user?.uid
|
|
26
|
+
: undefined;
|
|
27
|
+
this.authService.authState
|
|
28
|
+
.pipe(takeUntilDestroyed(this.destroyRef))
|
|
29
|
+
.subscribe((state) => {
|
|
30
|
+
if (!this.matchesLinkUser(state)) {
|
|
31
|
+
// Never revive an old popup after an A -> B -> A account transition.
|
|
32
|
+
this.linkContextInvalidated = true;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
matchesLinkUser(state) {
|
|
37
|
+
return (!!this.linkUserID &&
|
|
38
|
+
state.status === AuthStatuses.authenticated &&
|
|
39
|
+
state.user?.uid === this.linkUserID);
|
|
40
|
+
}
|
|
41
|
+
linkContextIsCurrent() {
|
|
42
|
+
return !!this.linkUserID && !this.linkContextInvalidated;
|
|
11
43
|
}
|
|
12
44
|
/** Legacy Login Widget: posts the widget's signed payload. */
|
|
13
45
|
loginWithTelegram(botID, tgAuthData, isUserAuthenticated) {
|
|
@@ -25,11 +57,20 @@ export class SneatAuthWithTelegramService {
|
|
|
25
57
|
this.signIn('auth/login-from-telegram-oidc?botID=' + botID, { id_token: idToken }, isUserAuthenticated);
|
|
26
58
|
}
|
|
27
59
|
signIn(endpoint, body, isUserAuthenticated) {
|
|
60
|
+
if (isUserAuthenticated && !this.linkContextIsCurrent()) {
|
|
61
|
+
this.errorLogger.logErrorHandler('Telegram account linking stopped')(new Error('Your sign-in changed. Reload this page before authorizing Telegram.'));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
28
64
|
const request = isUserAuthenticated
|
|
29
65
|
? this.apiService.post(endpoint, body)
|
|
30
66
|
: this.apiService.postAsAnonymous(endpoint, body);
|
|
31
|
-
|
|
67
|
+
const guardedRequest = isUserAuthenticated
|
|
68
|
+
? request.pipe(takeUntil(this.authService.authState.pipe(filter((state) => !this.matchesLinkUser(state)))))
|
|
69
|
+
: request;
|
|
70
|
+
guardedRequest.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({
|
|
32
71
|
next: (response) => {
|
|
72
|
+
if (isUserAuthenticated && !this.linkContextIsCurrent())
|
|
73
|
+
return;
|
|
33
74
|
this.authService
|
|
34
75
|
.signInWithToken(response.token)
|
|
35
76
|
.catch(this.errorLogger.logErrorHandler('Failed to sign-in with custom token'));
|
|
@@ -42,5 +83,5 @@ export class SneatAuthWithTelegramService {
|
|
|
42
83
|
}
|
|
43
84
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: SneatAuthWithTelegramService, decorators: [{
|
|
44
85
|
type: Injectable
|
|
45
|
-
}] });
|
|
86
|
+
}], ctorParameters: () => [] });
|
|
46
87
|
//# sourceMappingURL=sneat-auth-with-telegram.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sneat-auth-with-telegram.service.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/sneat-auth-with-telegram.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"sneat-auth-with-telegram.service.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/sneat-auth-with-telegram.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAA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CAAC,IAAI,CAAY,QAAQ,EAAE,IAAI,CAAC;YACjD,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,eAAe,CAAY,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC/D,MAAM,cAAc,GAAG,mBAAmB;YACxC,CAAC,CAAC,OAAO,CAAC,IAAI,CACV,SAAS,CACP,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAC7B,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAChD,CACF,CACF;YACH,CAAC,CAAC,OAAO,CAAC;QACZ,cAAc,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;YACjE,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE;gBACjB,IAAI,mBAAmB,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE;oBAAE,OAAO;gBAChE,IAAI,CAAC,WAAW;qBACb,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC;qBAC/B,KAAK,CACJ,IAAI,CAAC,WAAW,CAAC,eAAe,CAC9B,qCAAqC,CACtC,CACF,CAAC;YACN,CAAC;YACD,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,6BAA6B,CAAC;SACvE,CAAC,CAAC;IACL,CAAC;8GAtHU,4BAA4B;kHAA5B,4BAA4B;;2FAA5B,4BAA4B;kBADxC,UAAU","sourcesContent":["import { DestroyRef, Injectable, inject } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { SneatApiService } from '@sneat/api';\nimport {\n AuthStatuses,\n ISneatAuthState,\n SneatAuthStateService,\n} from '@sneat/auth-core';\nimport { ErrorLogger, IErrorLogger } from '@sneat/core';\nimport { Observable, filter, take, takeUntil } from 'rxjs';\n\nexport interface ITelegramAuthData {\n id: number;\n first_name: string;\n last_name: string;\n username?: string;\n photo_url?: string;\n auth_date: number;\n hash: string;\n}\n\n/** What the server hands the page before it opens Telegram's OpenID popup. */\nexport interface ITelegramOIDCNonce {\n clientID: string;\n nonce: string;\n}\n\ninterface IResponse {\n token: string;\n}\n\n@Injectable()\nexport class SneatAuthWithTelegramService {\n private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);\n private readonly apiService = inject(SneatApiService);\n private readonly authService = inject(SneatAuthStateService);\n private readonly destroyRef = inject(DestroyRef);\n private readonly linkUserID?: string;\n private linkContextInvalidated = false;\n\n constructor() {\n // Auth state replays its current principal synchronously. If it is not\n // ready, authenticated linking fails closed for this control's lifetime.\n let initialState: ISneatAuthState | undefined;\n this.authService.authState\n .pipe(take(1), takeUntilDestroyed(this.destroyRef))\n .subscribe((state) => {\n initialState = state;\n });\n this.linkUserID =\n initialState?.status === AuthStatuses.authenticated\n ? initialState.user?.uid\n : undefined;\n this.authService.authState\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe((state) => {\n if (!this.matchesLinkUser(state)) {\n // Never revive an old popup after an A -> B -> A account transition.\n this.linkContextInvalidated = true;\n }\n });\n }\n\n private matchesLinkUser(state: ISneatAuthState): boolean {\n return (\n !!this.linkUserID &&\n state.status === AuthStatuses.authenticated &&\n state.user?.uid === this.linkUserID\n );\n }\n\n private linkContextIsCurrent(): boolean {\n return !!this.linkUserID && !this.linkContextInvalidated;\n }\n\n /** Legacy Login Widget: posts the widget's signed payload. */\n public loginWithTelegram(\n botID: string,\n tgAuthData: ITelegramAuthData,\n isUserAuthenticated: boolean,\n ): void {\n this.signIn(\n 'auth/login-from-telegram-widget?botID=' + botID,\n tgAuthData,\n isUserAuthenticated,\n );\n }\n\n /**\n * Asks the server for the bot's OpenID Client ID and a fresh nonce. Fails\n * with 400 for a bot that has no OpenID login configured server-side.\n */\n public getTelegramOIDCNonce(botID: string): Observable<ITelegramOIDCNonce> {\n return this.apiService.postAsAnonymous<ITelegramOIDCNonce>(\n 'auth/telegram-oidc-nonce?botID=' + botID,\n {},\n );\n }\n\n /** OpenID login: posts the id_token Telegram's popup returned. */\n public loginWithTelegramOIDC(\n botID: string,\n idToken: string,\n isUserAuthenticated: boolean,\n ): void {\n this.signIn(\n 'auth/login-from-telegram-oidc?botID=' + botID,\n { id_token: idToken },\n isUserAuthenticated,\n );\n }\n\n private signIn(\n endpoint: string,\n body: unknown,\n isUserAuthenticated: boolean,\n ): void {\n if (isUserAuthenticated && !this.linkContextIsCurrent()) {\n this.errorLogger.logErrorHandler('Telegram account linking stopped')(\n new Error(\n 'Your sign-in changed. Reload this page before authorizing Telegram.',\n ),\n );\n return;\n }\n const request = isUserAuthenticated\n ? this.apiService.post<IResponse>(endpoint, body)\n : this.apiService.postAsAnonymous<IResponse>(endpoint, body);\n const guardedRequest = isUserAuthenticated\n ? request.pipe(\n takeUntil(\n this.authService.authState.pipe(\n filter((state) => !this.matchesLinkUser(state)),\n ),\n ),\n )\n : request;\n guardedRequest.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({\n next: (response) => {\n if (isUserAuthenticated && !this.linkContextIsCurrent()) return;\n this.authService\n .signInWithToken(response.token)\n .catch(\n this.errorLogger.logErrorHandler(\n 'Failed to sign-in with custom token',\n ),\n );\n },\n error: this.errorLogger.logErrorHandler('signInWithTelegram() error:'),\n });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/auth/ui/src/provider-buttons/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,kBAAkB,GACnB,MAAM,8BAA8B,CAAC","sourcesContent":["export {\n AuthProviderButtonsComponent,\n OAUTH_PROVIDER_IDS,\n} from './provider-buttons.component';\nexport type {\n OAuthProviderId,\n OAuthProviderLabels,\n} from './provider-buttons.component';\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component, computed, input, output, } from '@angular/core';
|
|
2
|
+
import { IonCol, IonIcon, IonItem, IonLabel, IonList, IonRow, IonSpinner, } from '@ionic/angular';
|
|
3
|
+
import { logoApple, logoFacebook, logoGithub, logoGoogle, logoWindows, } from 'ionicons/icons';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
/** Fixed display order, independent of the caller's visibility allowlist order. */
|
|
6
|
+
export const OAUTH_PROVIDER_IDS = [
|
|
7
|
+
'google.com',
|
|
8
|
+
'apple.com',
|
|
9
|
+
'microsoft.com',
|
|
10
|
+
'facebook.com',
|
|
11
|
+
'github.com',
|
|
12
|
+
];
|
|
13
|
+
const providers = [
|
|
14
|
+
{
|
|
15
|
+
id: 'google.com',
|
|
16
|
+
label: 'Login with Google',
|
|
17
|
+
icon: logoGoogle,
|
|
18
|
+
color: 'danger',
|
|
19
|
+
spinnerColor: undefined,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: 'apple.com',
|
|
23
|
+
label: 'Login with Apple',
|
|
24
|
+
icon: logoApple,
|
|
25
|
+
color: 'dark',
|
|
26
|
+
spinnerColor: undefined,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'microsoft.com',
|
|
30
|
+
label: 'Login with Microsoft',
|
|
31
|
+
icon: logoWindows,
|
|
32
|
+
color: 'secondary',
|
|
33
|
+
spinnerColor: 'secondary',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'facebook.com',
|
|
37
|
+
label: 'Login with Facebook',
|
|
38
|
+
icon: logoFacebook,
|
|
39
|
+
color: 'primary',
|
|
40
|
+
spinnerColor: 'primary',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 'github.com',
|
|
44
|
+
label: 'Login with GitHub',
|
|
45
|
+
icon: logoGithub,
|
|
46
|
+
color: 'tertiary',
|
|
47
|
+
spinnerColor: 'tertiary',
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
/** Presentation only: the host owns authentication, readiness, navigation and errors. */
|
|
51
|
+
export class AuthProviderButtonsComponent {
|
|
52
|
+
constructor() {
|
|
53
|
+
this.providers = input(/* @ts-ignore */
|
|
54
|
+
...(ngDevMode ? [undefined, { debugName: "providers" }] : /* istanbul ignore next */ []));
|
|
55
|
+
this.busy = input(/* @ts-ignore */
|
|
56
|
+
...(ngDevMode ? [undefined, { debugName: "busy" }] : /* istanbul ignore next */ []));
|
|
57
|
+
this.disabled = input(false, /* @ts-ignore */
|
|
58
|
+
...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
|
|
59
|
+
this.labels = input({}, /* @ts-ignore */
|
|
60
|
+
...(ngDevMode ? [{ debugName: "labels" }] : /* istanbul ignore next */ []));
|
|
61
|
+
this.providerSelected = output();
|
|
62
|
+
this.rows = computed(() => [providers.slice(0, 2), providers.slice(2, 4), providers.slice(4)]
|
|
63
|
+
.map((row) => row.filter((provider) => this.providers()?.includes(provider.id) ?? true))
|
|
64
|
+
.filter((row) => row.length), /* @ts-ignore */
|
|
65
|
+
...(ngDevMode ? [{ debugName: "rows" }] : /* istanbul ignore next */ []));
|
|
66
|
+
}
|
|
67
|
+
label(provider) {
|
|
68
|
+
const label = this.labels()[provider.id];
|
|
69
|
+
return typeof label === 'string' &&
|
|
70
|
+
label.trim().length &&
|
|
71
|
+
label.length <= 160
|
|
72
|
+
? label.trim()
|
|
73
|
+
: provider.label;
|
|
74
|
+
}
|
|
75
|
+
select(provider) {
|
|
76
|
+
if (!this.disabled() &&
|
|
77
|
+
!this.busy() &&
|
|
78
|
+
(this.providers()?.includes(provider) ?? true))
|
|
79
|
+
this.providerSelected.emit(provider);
|
|
80
|
+
}
|
|
81
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: AuthProviderButtonsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
82
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.3", type: AuthProviderButtonsComponent, isStandalone: true, selector: "sneat-auth-provider-buttons", inputs: { providers: { classPropertyName: "providers", publicName: "providers", isSignal: true, isRequired: false, transformFunction: null }, busy: { classPropertyName: "busy", publicName: "busy", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, labels: { classPropertyName: "labels", publicName: "labels", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { providerSelected: "providerSelected" }, ngImport: i0, template: "@for (row of rows(); track $index) {\n <ion-row>\n @for (provider of row; track provider.id) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n [button]=\"true\"\n [detail]=\"false\"\n type=\"button\"\n [disabled]=\"disabled() || !!busy()\"\n [attr.aria-busy]=\"busy() === provider.id ? 'true' : null\"\n [attr.data-provider]=\"provider.id\"\n (click)=\"select(provider.id)\"\n >\n @if (busy() === provider.id) {\n <ion-spinner\n slot=\"start\"\n name=\"lines-small\"\n [color]=\"provider.spinnerColor\"\n aria-hidden=\"true\"\n />\n } @else {\n <ion-icon\n slot=\"start\"\n [color]=\"provider.color\"\n [icon]=\"provider.icon\"\n aria-hidden=\"true\"\n />\n }\n <ion-label [color]=\"provider.color\">{{\n label(provider)\n }}</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n }\n </ion-row>\n}\n", styles: [":host{display:block}\n"], dependencies: [{ kind: "component", type: IonCol, selector: "ion-col", inputs: ["offset", "offsetLg", "offsetMd", "offsetSm", "offsetXl", "offsetXs", "pull", "pullLg", "pullMd", "pullSm", "pullXl", "pullXs", "push", "pushLg", "pushMd", "pushSm", "pushXl", "pushXs", "size", "sizeLg", "sizeMd", "sizeSm", "sizeXl", "sizeXs"] }, { kind: "component", type: IonIcon, selector: "ion-icon", inputs: ["color", "flipRtl", "icon", "ios", "lazy", "md", "mode", "name", "sanitize", "size", "src"] }, { kind: "component", type: IonItem, selector: "ion-item", inputs: ["button", "color", "detail", "detailIcon", "disabled", "download", "href", "lines", "mode", "rel", "routerAnimation", "routerDirection", "target", "type"] }, { kind: "component", type: IonLabel, selector: "ion-label", inputs: ["color", "mode", "position"] }, { kind: "component", type: IonList, selector: "ion-list", inputs: ["inset", "lines", "mode"] }, { kind: "component", type: IonRow, selector: "ion-row" }, { kind: "component", type: IonSpinner, selector: "ion-spinner", inputs: ["color", "duration", "name", "paused"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
83
|
+
}
|
|
84
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: AuthProviderButtonsComponent, decorators: [{
|
|
85
|
+
type: Component,
|
|
86
|
+
args: [{ selector: 'sneat-auth-provider-buttons', imports: [IonCol, IonIcon, IonItem, IonLabel, IonList, IonRow, IonSpinner], changeDetection: ChangeDetectionStrategy.OnPush, template: "@for (row of rows(); track $index) {\n <ion-row>\n @for (provider of row; track provider.id) {\n <ion-col size=\"12\" size-md=\"6\">\n <ion-list lines=\"none\">\n <ion-item\n [button]=\"true\"\n [detail]=\"false\"\n type=\"button\"\n [disabled]=\"disabled() || !!busy()\"\n [attr.aria-busy]=\"busy() === provider.id ? 'true' : null\"\n [attr.data-provider]=\"provider.id\"\n (click)=\"select(provider.id)\"\n >\n @if (busy() === provider.id) {\n <ion-spinner\n slot=\"start\"\n name=\"lines-small\"\n [color]=\"provider.spinnerColor\"\n aria-hidden=\"true\"\n />\n } @else {\n <ion-icon\n slot=\"start\"\n [color]=\"provider.color\"\n [icon]=\"provider.icon\"\n aria-hidden=\"true\"\n />\n }\n <ion-label [color]=\"provider.color\">{{\n label(provider)\n }}</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n }\n </ion-row>\n}\n", styles: [":host{display:block}\n"] }]
|
|
87
|
+
}], propDecorators: { providers: [{ type: i0.Input, args: [{ isSignal: true, alias: "providers", required: false }] }], busy: [{ type: i0.Input, args: [{ isSignal: true, alias: "busy", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], labels: [{ type: i0.Input, args: [{ isSignal: true, alias: "labels", required: false }] }], providerSelected: [{ type: i0.Output, args: ["providerSelected"] }] } });
|
|
88
|
+
//# sourceMappingURL=provider-buttons.component.js.map
|