@sneat/auth-ui 0.27.45 → 0.27.46

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.
Files changed (22) hide show
  1. package/esm2022/index.js +1 -0
  2. package/esm2022/index.js.map +1 -1
  3. package/esm2022/lib/components/user-auth-providers/telegram-auth-account.component.js +243 -0
  4. package/esm2022/lib/components/user-auth-providers/telegram-auth-account.component.js.map +1 -0
  5. package/esm2022/lib/components/user-auth-providers/user-auth-accounts.component.js +10 -57
  6. package/esm2022/lib/components/user-auth-providers/user-auth-accounts.component.js.map +1 -1
  7. package/esm2022/lib/pages/login-page/auth-panel.component.js +1 -1
  8. package/esm2022/lib/pages/login-page/auth-panel.component.js.map +1 -1
  9. package/esm2022/lib/pages/login-page/login-with-telegram.component.js +21 -5
  10. package/esm2022/lib/pages/login-page/login-with-telegram.component.js.map +1 -1
  11. package/esm2022/lib/pages/login-page/sneat-auth-with-telegram.service.js +20 -7
  12. package/esm2022/lib/pages/login-page/sneat-auth-with-telegram.service.js.map +1 -1
  13. package/esm2022/lib/pages/login-page/telegram-login-config.js +17 -1
  14. package/esm2022/lib/pages/login-page/telegram-login-config.js.map +1 -1
  15. package/index.d.ts +1 -0
  16. package/lib/components/user-auth-providers/telegram-auth-account.component.d.ts +28 -0
  17. package/lib/components/user-auth-providers/user-auth-accounts.component.d.ts +1 -10
  18. package/lib/pages/login-page/login-with-telegram.component.d.ts +3 -1
  19. package/lib/pages/login-page/sneat-auth-with-telegram.service.d.ts +2 -0
  20. package/lib/pages/login-page/telegram-login-config.d.ts +6 -0
  21. package/package.json +1 -1
  22. package/tsconfig.lib.prod.tsbuildinfo +1 -1
@@ -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,4BAA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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;8GA3KU,kBAAkB;kGAAlB,kBAAkB,uqBAFlB,CAAC,eAAe,CAAC,0BCpF9B,grGAoGA,4CD/BI,UAAU,kPACV,4BAA4B,4JAC5B,uBAAuB,oJACvB,0BAA0B,oJAC1B,SAAS,sRACT,OAAO,yLACP,MAAM,kTACN,OAAO,wEACP,OAAO,2JACP,cAAc,kGACd,QAAQ,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"]}
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,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAC;AAExD,OAAO,EACL,SAAS,EACT,OAAO,EACP,MAAM,EACN,OAAO,EACP,OAAO,EACP,cAAc,EACd,QAAQ,EACR,MAAM,EACN,UAAU,EACV,OAAO,GACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGL,uBAAuB,GACxB,MAA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c;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"]}
@@ -1,10 +1,10 @@
1
1
  import { DOCUMENT } from '@angular/common';
2
- import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, inject, input, signal, } from '@angular/core';
2
+ import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, inject, input, output, signal, } from '@angular/core';
3
3
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
4
4
  import { ErrorLogger } from '@sneat/core';
5
5
  import { newRandomId } from '@sneat/random';
6
6
  import { SneatAuthWithTelegramService, } from './sneat-auth-with-telegram.service';
7
- import { TelegramLoginConfig, resolveTelegramBotID, } from './telegram-login-config';
7
+ import { TelegramLoginConfig, TelegramAuthApi, telegramAuthApiFactory, resolveTelegramBotID, } from './telegram-login-config';
8
8
  import { loadTelegramLoginScript, telegramLoginApi, } from './telegram-login-js';
9
9
  import * as i0 from "@angular/core";
10
10
  /** Server nonces live 10 minutes; refresh well inside that. */
@@ -30,6 +30,8 @@ export class LoginWithTelegramComponent {
30
30
  lowerCaseLetters: true,
31
31
  upperCaseLetters: true,
32
32
  })}`;
33
+ this.authenticated = output();
34
+ this.authenticationFailed = output();
33
35
  this.isUserAuthenticated = input(false, /* @ts-ignore */
34
36
  ...(ngDevMode ? [{ debugName: "isUserAuthenticated" }] : /* istanbul ignore next */ []));
35
37
  this.botID = input(resolveTelegramBotID(this.telegramLoginConfig, location.hostname), /* @ts-ignore */
@@ -52,6 +54,14 @@ export class LoginWithTelegramComponent {
52
54
  });
53
55
  }
54
56
  ngOnInit() {
57
+ this.authWithTelegram.authenticationResult
58
+ .pipe(takeUntilDestroyed(this.destroyRef))
59
+ .subscribe((success) => {
60
+ if (success)
61
+ this.authenticated.emit();
62
+ else
63
+ this.authenticationFailed.emit();
64
+ });
55
65
  const botID = this.botID();
56
66
  if (!botID) {
57
67
  return;
@@ -135,7 +145,10 @@ export class LoginWithTelegramComponent {
135
145
  this.el.nativeElement.appendChild(script);
136
146
  }
137
147
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: LoginWithTelegramComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
138
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.3", type: LoginWithTelegramComponent, isStandalone: true, selector: "sneat-login-with-telegram", inputs: { isUserAuthenticated: { classPropertyName: "isUserAuthenticated", publicName: "isUserAuthenticated", isSignal: true, isRequired: false, transformFunction: null }, botID: { classPropertyName: "botID", publicName: "botID", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, requestAccess: { classPropertyName: "requestAccess", publicName: "requestAccess", isSignal: true, isRequired: false, transformFunction: null }, userPic: { classPropertyName: "userPic", publicName: "userPic", isSignal: true, isRequired: false, transformFunction: null } }, providers: [SneatAuthWithTelegramService], ngImport: i0, template: `
148
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.3", type: LoginWithTelegramComponent, isStandalone: true, selector: "sneat-login-with-telegram", inputs: { isUserAuthenticated: { classPropertyName: "isUserAuthenticated", publicName: "isUserAuthenticated", isSignal: true, isRequired: false, transformFunction: null }, botID: { classPropertyName: "botID", publicName: "botID", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, requestAccess: { classPropertyName: "requestAccess", publicName: "requestAccess", isSignal: true, isRequired: false, transformFunction: null }, userPic: { classPropertyName: "userPic", publicName: "userPic", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { authenticated: "authenticated", authenticationFailed: "authenticationFailed" }, providers: [
149
+ SneatAuthWithTelegramService,
150
+ { provide: TelegramAuthApi, useFactory: telegramAuthApiFactory },
151
+ ], ngImport: i0, template: `
139
152
  @if (oidc(); as cfg) {
140
153
  <button
141
154
  type="button"
@@ -150,7 +163,10 @@ export class LoginWithTelegramComponent {
150
163
  }
151
164
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: LoginWithTelegramComponent, decorators: [{
152
165
  type: Component,
153
- args: [{ providers: [SneatAuthWithTelegramService], selector: 'sneat-login-with-telegram', changeDetection: ChangeDetectionStrategy.OnPush, template: `
166
+ args: [{ providers: [
167
+ SneatAuthWithTelegramService,
168
+ { provide: TelegramAuthApi, useFactory: telegramAuthApiFactory },
169
+ ], selector: 'sneat-login-with-telegram', changeDetection: ChangeDetectionStrategy.OnPush, template: `
154
170
  @if (oidc(); as cfg) {
155
171
  <button
156
172
  type="button"
@@ -162,5 +178,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImpor
162
178
  </button>
163
179
  }
164
180
  `, styles: [".tg-oidc-login{background:#54a9eb;color:#fff;border:0;border-radius:20px;font-weight:500;cursor:pointer;font-size:16px;padding:10px 21px}.tg-oidc-login[data-size=medium]{font-size:14px;padding:8px 16px}.tg-oidc-login[data-size=small]{font-size:13px;padding:6px 12px}\n"] }]
165
- }], ctorParameters: () => [], propDecorators: { isUserAuthenticated: [{ type: i0.Input, args: [{ isSignal: true, alias: "isUserAuthenticated", required: false }] }], botID: [{ type: i0.Input, args: [{ isSignal: true, alias: "botID", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], requestAccess: [{ type: i0.Input, args: [{ isSignal: true, alias: "requestAccess", required: false }] }], userPic: [{ type: i0.Input, args: [{ isSignal: true, alias: "userPic", required: false }] }] } });
181
+ }], ctorParameters: () => [], propDecorators: { authenticated: [{ type: i0.Output, args: ["authenticated"] }], authenticationFailed: [{ type: i0.Output, args: ["authenticationFailed"] }], isUserAuthenticated: [{ type: i0.Input, args: [{ isSignal: true, alias: "isUserAuthenticated", required: false }] }], botID: [{ type: i0.Input, args: [{ isSignal: true, alias: "botID", required: false }] }], size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], requestAccess: [{ type: i0.Input, args: [{ isSignal: true, alias: "requestAccess", required: false }] }], userPic: [{ type: i0.Input, args: [{ isSignal: true, alias: "userPic", required: false }] }] } });
166
182
  //# sourceMappingURL=login-with-telegram.component.js.map
@@ -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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AAI,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
+ {"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,EACN,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAGL,4BAA4B,GAC7B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL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,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,GAAG,IAAI,CAAC,kBAAkB,QAAQ,CAAC,CAAC;QACvE,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;8GAxJU,0BAA0B;kGAA1B,0BAA0B,40BAzC1B;YACT,4BAA4B;YAC5B,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,sBAAsB,EAAE;SACjE,0BAGS;;;;;;;;;;;GAWT;;2FAwBU,0BAA0B;kBA1CtC,SAAS;gCACG;wBACT,4BAA4B;wBAC5B,EAAE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,sBAAsB,EAAE;qBACjE,YACS,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 output,\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 TelegramAuthApi,\n telegramAuthApiFactory,\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: [\n SneatAuthWithTelegramService,\n { provide: TelegramAuthApi, useFactory: telegramAuthApiFactory },\n ],\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 authenticated = output<void>();\n public readonly authenticationFailed = output<void>();\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 this.authWithTelegram.authenticationResult\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe((success) => {\n if (success) this.authenticated.emit();\n else this.authenticationFailed.emit();\n });\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,14 +1,16 @@
1
1
  import { DestroyRef, Injectable, inject } from '@angular/core';
2
2
  import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
3
- import { SneatApiService } from '@sneat/api';
3
+ import { TelegramAuthApi } from './telegram-login-config';
4
4
  import { AuthStatuses, SneatAuthStateService, } from '@sneat/auth-core';
5
5
  import { ErrorLogger } from '@sneat/core';
6
- import { filter, take, takeUntil } from 'rxjs';
6
+ import { Subject, filter, take, takeUntil } from 'rxjs';
7
7
  import * as i0 from "@angular/core";
8
8
  export class SneatAuthWithTelegramService {
9
9
  constructor() {
10
+ this.result = new Subject();
11
+ this.authenticationResult = this.result.asObservable();
10
12
  this.errorLogger = inject(ErrorLogger);
11
- this.apiService = inject(SneatApiService);
13
+ this.apiService = inject(TelegramAuthApi);
12
14
  this.authService = inject(SneatAuthStateService);
13
15
  this.destroyRef = inject(DestroyRef);
14
16
  this.linkContextInvalidated = false;
@@ -77,6 +79,7 @@ export class SneatAuthWithTelegramService {
77
79
  this.errorLogger.logErrorHandler('Telegram account linking stopped')(new Error(this.linkContextInvalidated
78
80
  ? 'Your sign-in changed. Reload this page before authorizing Telegram.'
79
81
  : 'Your sign-in is refreshing. Try again after your account is ready.'));
82
+ this.result.next(false);
80
83
  return;
81
84
  }
82
85
  const request = isUserAuthenticated
@@ -89,11 +92,21 @@ export class SneatAuthWithTelegramService {
89
92
  next: (response) => {
90
93
  if (isUserAuthenticated && !this.linkContextIsReady())
91
94
  return;
92
- this.authService
93
- .signInWithToken(response.token)
94
- .catch(this.errorLogger.logErrorHandler('Failed to sign-in with custom token'));
95
+ this.authService.signInWithToken(response.token).then(() => {
96
+ if (!this.destroyRef.destroyed &&
97
+ (!isUserAuthenticated || this.linkContextIsReady())) {
98
+ this.result.next(true);
99
+ }
100
+ }, (error) => {
101
+ this.errorLogger.logErrorHandler('Failed to sign-in with custom token')(error);
102
+ if (!this.destroyRef.destroyed)
103
+ this.result.next(false);
104
+ });
105
+ },
106
+ error: (error) => {
107
+ this.errorLogger.logErrorHandler('signInWithTelegram() error:')(error);
108
+ this.result.next(false);
95
109
  },
96
- error: this.errorLogger.logErrorHandler('signInWithTelegram() error:'),
97
110
  });
98
111
  }
99
112
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: SneatAuthWithTelegramService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
@@ -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,UAAU,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,YAAY,EAEZ,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,WAAW,EAAgB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAc,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;;AAuB3D,MAAM,OAAO,4BAA4B;IASvC;QARiB,gBAAW,GAAG,MAAM,CAAe,WAAW,CAAC,CAAC;QAChD,eAAU,GAAG,MAAM,CAAC,eAAe,CAAC,CAAC;QACrC,gBAAW,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;QAC5C,eAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QAEzC,2BAAsB,GAAG,KAAK,CAAC;QAIrC,uEAAuE;QACvE,yEAAyE;QACzE,IAAI,YAAyC,CAAC;QAC9C,IAAI,CAAC,WAAW,CAAC,SAAS;aACvB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;aAClD,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;YACnB,YAAY,GAA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Ae,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,sBAAsB,CAAC,KAAK,CAAC,CAAC,CACvD,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,kBAAkB,EAAE;oBAAE,OAAO;gBAC9D,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;8GA9IU,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 private linkState?: ISneatAuthState;\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 && this.isAuthenticatedReady(initialState)\n ? initialState.user?.uid\n : undefined;\n this.authService.authState\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe((state) => {\n this.linkState = state;\n if (!this.preservesLinkPrincipal(state)) {\n // Never revive an old popup after an A -> B -> A account transition.\n this.linkContextInvalidated = true;\n }\n });\n }\n\n private isAuthenticatedReady(state: ISneatAuthState): boolean {\n return (\n state.status === AuthStatuses.authenticated &&\n !!state.user?.uid &&\n !state.err &&\n // Older public callers omit loadingPhase. An explicit pending phase is\n // never ready, and the real auth service's ready state needs its token.\n (state.loadingPhase === undefined ||\n (state.loadingPhase === 'ready' && !!state.token))\n );\n }\n\n private preservesLinkPrincipal(state: ISneatAuthState): boolean {\n return (\n !!this.linkUserID &&\n state.user?.uid === this.linkUserID &&\n !state.err &&\n (this.isAuthenticatedReady(state) ||\n (state.status === AuthStatuses.authenticating &&\n state.loadingPhase === 'getting-token'))\n );\n }\n\n private linkContextIsReady(): boolean {\n return (\n !this.linkContextInvalidated &&\n !!this.linkState &&\n this.preservesLinkPrincipal(this.linkState) &&\n this.isAuthenticatedReady(this.linkState)\n );\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.linkContextIsReady()) {\n this.errorLogger.logErrorHandler('Telegram account linking stopped')(\n new Error(\n this.linkContextInvalidated\n ? 'Your sign-in changed. Reload this page before authorizing Telegram.'\n : 'Your sign-in is refreshing. Try again after your account is ready.',\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.preservesLinkPrincipal(state)),\n ),\n ),\n )\n : request;\n guardedRequest.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({\n next: (response) => {\n if (isUserAuthenticated && !this.linkContextIsReady()) 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"]}
1
+ {"version":3,"file":"sneat-auth-with-telegram.service.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/s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C,UAAU","sourcesContent":["import { DestroyRef, Injectable, inject } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { TelegramAuthApi } from './telegram-login-config';\nimport {\n AuthStatuses,\n ISneatAuthState,\n SneatAuthStateService,\n} from '@sneat/auth-core';\nimport { ErrorLogger, IErrorLogger } from '@sneat/core';\nimport { Observable, Subject, 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 result = new Subject<boolean>();\n readonly authenticationResult = this.result.asObservable();\n\n private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);\n private readonly apiService = inject(TelegramAuthApi);\n private readonly authService = inject(SneatAuthStateService);\n private readonly destroyRef = inject(DestroyRef);\n private readonly linkUserID?: string;\n private linkContextInvalidated = false;\n private linkState?: ISneatAuthState;\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 && this.isAuthenticatedReady(initialState)\n ? initialState.user?.uid\n : undefined;\n this.authService.authState\n .pipe(takeUntilDestroyed(this.destroyRef))\n .subscribe((state) => {\n this.linkState = state;\n if (!this.preservesLinkPrincipal(state)) {\n // Never revive an old popup after an A -> B -> A account transition.\n this.linkContextInvalidated = true;\n }\n });\n }\n\n private isAuthenticatedReady(state: ISneatAuthState): boolean {\n return (\n state.status === AuthStatuses.authenticated &&\n !!state.user?.uid &&\n !state.err &&\n // Older public callers omit loadingPhase. An explicit pending phase is\n // never ready, and the real auth service's ready state needs its token.\n (state.loadingPhase === undefined ||\n (state.loadingPhase === 'ready' && !!state.token))\n );\n }\n\n private preservesLinkPrincipal(state: ISneatAuthState): boolean {\n return (\n !!this.linkUserID &&\n state.user?.uid === this.linkUserID &&\n !state.err &&\n (this.isAuthenticatedReady(state) ||\n (state.status === AuthStatuses.authenticating &&\n state.loadingPhase === 'getting-token'))\n );\n }\n\n private linkContextIsReady(): boolean {\n return (\n !this.linkContextInvalidated &&\n !!this.linkState &&\n this.preservesLinkPrincipal(this.linkState) &&\n this.isAuthenticatedReady(this.linkState)\n );\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.linkContextIsReady()) {\n this.errorLogger.logErrorHandler('Telegram account linking stopped')(\n new Error(\n this.linkContextInvalidated\n ? 'Your sign-in changed. Reload this page before authorizing Telegram.'\n : 'Your sign-in is refreshing. Try again after your account is ready.',\n ),\n );\n this.result.next(false);\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.preservesLinkPrincipal(state)),\n ),\n ),\n )\n : request;\n guardedRequest.pipe(takeUntilDestroyed(this.destroyRef)).subscribe({\n next: (response) => {\n if (isUserAuthenticated && !this.linkContextIsReady()) return;\n this.authService.signInWithToken(response.token).then(\n () => {\n if (\n !this.destroyRef.destroyed &&\n (!isUserAuthenticated || this.linkContextIsReady())\n ) {\n this.result.next(true);\n }\n },\n (error) => {\n this.errorLogger.logErrorHandler(\n 'Failed to sign-in with custom token',\n )(error);\n if (!this.destroyRef.destroyed) this.result.next(false);\n },\n );\n },\n error: (error) => {\n this.errorLogger.logErrorHandler('signInWithTelegram() error:')(error);\n this.result.next(false);\n },\n });\n }\n}\n"]}
@@ -1,4 +1,7 @@
1
- import { InjectionToken } from '@angular/core';
1
+ import { InjectionToken, inject } from '@angular/core';
2
+ import { HttpClient } from '@angular/common/http';
3
+ import { SneatApiService, SneatApiAuthTokenBridge } from '@sneat/api';
4
+ import { SneatUrlOperationBlocker } from '@sneat/core';
2
5
  export const TelegramLoginConfig = new InjectionToken('TelegramLoginConfig');
3
6
  /**
4
7
  * Resolves the Telegram bot username for the login widget.
@@ -11,4 +14,17 @@ export function resolveTelegramBotID(config, hostname) {
11
14
  }
12
15
  return isLocal ? 'AlextDevBot' : 'SneatBot';
13
16
  }
17
+ /** Telegram can use an app backend while other auth providers retain their API. */
18
+ export function telegramAuthApiFactory() {
19
+ const config = inject(TelegramLoginConfig, { optional: true });
20
+ if (!config?.apiBaseUrl)
21
+ return inject(SneatApiService);
22
+ return new SneatApiService(inject(HttpClient), inject(SneatApiAuthTokenBridge), config.apiBaseUrl.endsWith('/')
23
+ ? config.apiBaseUrl
24
+ : config.apiBaseUrl + '/', inject(SneatUrlOperationBlocker));
25
+ }
26
+ export const TelegramAuthApi = new InjectionToken('TelegramAuthApi', {
27
+ providedIn: 'root',
28
+ factory: telegramAuthApiFactory,
29
+ });
14
30
  //# sourceMappingURL=telegram-login-config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"telegram-login-config.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/telegram-login-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAS/C,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,cAAc,CACnD,qBAAqB,CACtB,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAmC,EACnC,QAAgB;IAEhB,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC7C,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,OAAO,IAAI,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IACzE,CAAC;IACD,OAAO,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC;AAC9C,CAAC","sourcesContent":["import { InjectionToken } from '@angular/core';\n\nexport interface ITelegramLoginConfig {\n /** Telegram bot username (without leading @) used for the login widget. */\n readonly botID: string;\n /** Optional bot username used when the hostname starts with \"local\". */\n readonly localBotID?: string;\n}\n\nexport const TelegramLoginConfig = new InjectionToken<ITelegramLoginConfig>(\n 'TelegramLoginConfig',\n);\n\n/**\n * Resolves the Telegram bot username for the login widget.\n * Falls back to the historical Sneat defaults when no config is provided.\n */\nexport function resolveTelegramBotID(\n config: ITelegramLoginConfig | null,\n hostname: string,\n): string {\n const isLocal = hostname.startsWith('local');\n if (config) {\n return isLocal && config.localBotID ? config.localBotID : config.botID;\n }\n return isLocal ? 'AlextDevBot' : 'SneatBot';\n}\n"]}
1
+ {"version":3,"file":"telegram-login-config.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/teleg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AAe,GAAG,IAAI,cAAc,CAC/C,iBAAiB,EACjB;IACE,UAAU,EAAE,MAAM;IAClB,OAAO,EAAE,sBAAsB;CAChC,CACF,CAAC","sourcesContent":["import { InjectionToken, inject } from '@angular/core';\nimport { HttpClient } from '@angular/common/http';\nimport { SneatApiService, SneatApiAuthTokenBridge } from '@sneat/api';\nimport { SneatUrlOperationBlocker } from '@sneat/core';\n\nexport interface ITelegramLoginConfig {\n /** Telegram bot username (without leading @) used for the login widget. */\n readonly botID: string;\n /** Optional backend base URL, including /v0/, for all Telegram auth calls. */\n readonly apiBaseUrl?: string;\n /** Optional bot username used when the hostname starts with \"local\". */\n readonly localBotID?: string;\n}\n\nexport const TelegramLoginConfig = new InjectionToken<ITelegramLoginConfig>(\n 'TelegramLoginConfig',\n);\n\n/**\n * Resolves the Telegram bot username for the login widget.\n * Falls back to the historical Sneat defaults when no config is provided.\n */\nexport function resolveTelegramBotID(\n config: ITelegramLoginConfig | null,\n hostname: string,\n): string {\n const isLocal = hostname.startsWith('local');\n if (config) {\n return isLocal && config.localBotID ? config.localBotID : config.botID;\n }\n return isLocal ? 'AlextDevBot' : 'SneatBot';\n}\n\n/** Telegram can use an app backend while other auth providers retain their API. */\nexport function telegramAuthApiFactory(): SneatApiService {\n const config = inject(TelegramLoginConfig, { optional: true });\n if (!config?.apiBaseUrl) return inject(SneatApiService);\n return new SneatApiService(\n inject(HttpClient),\n inject(SneatApiAuthTokenBridge),\n config.apiBaseUrl.endsWith('/')\n ? config.apiBaseUrl\n : config.apiBaseUrl + '/',\n inject(SneatUrlOperationBlocker),\n );\n}\n\nexport const TelegramAuthApi = new InjectionToken<SneatApiService>(\n 'TelegramAuthApi',\n {\n providedIn: 'root',\n factory: telegramAuthApiFactory,\n },\n);\n"]}
package/index.d.ts CHANGED
@@ -7,3 +7,4 @@ export * from './lib/components';
7
7
  export * from './lib/pipes/person-names.pipe';
8
8
  export * from './lib/sso';
9
9
  export * from './lib/pages/login-page/auth-panel-ui-config';
10
+ export { TelegramAuthAccountComponent } from './lib/components/user-auth-providers/telegram-auth-account.component';
@@ -0,0 +1,28 @@
1
+ import * as i0 from "@angular/core";
2
+ interface TelegramLink {
3
+ connected: boolean;
4
+ username?: string;
5
+ }
6
+ /** Shared Quick logins row. The authenticated API owns the Telegram identity. */
7
+ export declare class TelegramAuthAccountComponent {
8
+ private readonly api;
9
+ private readonly auth;
10
+ private readonly destroyRef;
11
+ private uid?;
12
+ protected readonly userID: import("@angular/core").WritableSignal<string | undefined>;
13
+ private generation;
14
+ private request?;
15
+ protected readonly ready: import("@angular/core").WritableSignal<boolean>;
16
+ protected readonly link: import("@angular/core").WritableSignal<TelegramLink | undefined>;
17
+ protected readonly loading: import("@angular/core").WritableSignal<boolean>;
18
+ protected readonly disconnecting: import("@angular/core").WritableSignal<boolean>;
19
+ protected readonly error: import("@angular/core").WritableSignal<string>;
20
+ constructor();
21
+ protected refresh(): void;
22
+ protected linked(uid: string | undefined): void;
23
+ protected linkFailed(uid: string | undefined): void;
24
+ protected disconnect(): void;
25
+ static ɵfac: i0.ɵɵFactoryDeclaration<TelegramAuthAccountComponent, never>;
26
+ static ɵcmp: i0.ɵɵComponentDeclaration<TelegramAuthAccountComponent, "sneat-telegram-auth-account", never, {}, {}, never, never, true, never>;
27
+ }
28
+ export {};
@@ -1,22 +1,13 @@
1
1
  import { AuthProviderID } from '@sneat/auth-core';
2
- import { IUserRecord } from '@sneat/auth-models';
3
2
  import { SneatBaseComponent } from '@sneat/ui';
4
3
  import * as i0 from "@angular/core";
5
4
  export declare class UserAuthAccountsComponent extends SneatBaseComponent {
6
- private readonly sneatUserService;
7
- private readonly sneatApiService;
8
5
  /**
9
- * The messaging-apps section (Telegram, WhatsApp, Viber) and its Sneat.app
6
+ * The messaging-apps section (WhatsApp, Viber) and its Sneat.app
10
7
  * copy. Apps that only need sign-in methods turn it off.
11
8
  */
12
9
  readonly showMessagingApps: import("@angular/core").InputSignal<boolean>;
13
- protected readonly $userRecord: import("@angular/core").WritableSignal<IUserRecord | undefined>;
14
10
  protected readonly signingInWith: import("@angular/core").WritableSignal<AuthProviderID | undefined>;
15
- constructor();
16
- protected hasAccount(provider: 'telegram' | 'viber' | 'whatsapp'): boolean;
17
- protected getAccountID(provider: 'telegram'): string;
18
- protected readonly disconnecting: import("@angular/core").WritableSignal<"telegram" | "viber" | "whatsapp" | undefined>;
19
- protected disconnect(provider: 'telegram'): void;
20
11
  static ɵfac: i0.ɵɵFactoryDeclaration<UserAuthAccountsComponent, never>;
21
12
  static ɵcmp: i0.ɵɵComponentDeclaration<UserAuthAccountsComponent, "sneat-user-auth-accounts", never, { "showMessagingApps": { "alias": "showMessagingApps"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
22
13
  }
@@ -17,6 +17,8 @@ export declare class LoginWithTelegramComponent implements OnInit {
17
17
  private legacyCallback?;
18
18
  private readonly legacyCallbackName;
19
19
  constructor();
20
+ readonly authenticated: import("@angular/core").OutputEmitterRef<void>;
21
+ readonly authenticationFailed: import("@angular/core").OutputEmitterRef<void>;
20
22
  readonly isUserAuthenticated: import("@angular/core").InputSignal<boolean>;
21
23
  readonly botID: import("@angular/core").InputSignal<string>;
22
24
  readonly size: import("@angular/core").InputSignal<"medium" | "small" | "large">;
@@ -30,5 +32,5 @@ export declare class LoginWithTelegramComponent implements OnInit {
30
32
  private refreshNonce;
31
33
  private startLegacyWidget;
32
34
  static ɵfac: i0.ɵɵFactoryDeclaration<LoginWithTelegramComponent, never>;
33
- static ɵcmp: i0.ɵɵComponentDeclaration<LoginWithTelegramComponent, "sneat-login-with-telegram", never, { "isUserAuthenticated": { "alias": "isUserAuthenticated"; "required": false; "isSignal": true; }; "botID": { "alias": "botID"; "required": false; "isSignal": true; }; "size": { "alias": "size"; "required": false; "isSignal": true; }; "requestAccess": { "alias": "requestAccess"; "required": false; "isSignal": true; }; "userPic": { "alias": "userPic"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
35
+ static ɵcmp: i0.ɵɵComponentDeclaration<LoginWithTelegramComponent, "sneat-login-with-telegram", never, { "isUserAuthenticated": { "alias": "isUserAuthenticated"; "required": false; "isSignal": true; }; "botID": { "alias": "botID"; "required": false; "isSignal": true; }; "size": { "alias": "size"; "required": false; "isSignal": true; }; "requestAccess": { "alias": "requestAccess"; "required": false; "isSignal": true; }; "userPic": { "alias": "userPic"; "required": false; "isSignal": true; }; }, { "authenticated": "authenticated"; "authenticationFailed": "authenticationFailed"; }, never, never, true, never>;
34
36
  }
@@ -15,6 +15,8 @@ export interface ITelegramOIDCNonce {
15
15
  nonce: string;
16
16
  }
17
17
  export declare class SneatAuthWithTelegramService {
18
+ private readonly result;
19
+ readonly authenticationResult: Observable<boolean>;
18
20
  private readonly errorLogger;
19
21
  private readonly apiService;
20
22
  private readonly authService;
@@ -1,7 +1,10 @@
1
1
  import { InjectionToken } from '@angular/core';
2
+ import { SneatApiService } from '@sneat/api';
2
3
  export interface ITelegramLoginConfig {
3
4
  /** Telegram bot username (without leading @) used for the login widget. */
4
5
  readonly botID: string;
6
+ /** Optional backend base URL, including /v0/, for all Telegram auth calls. */
7
+ readonly apiBaseUrl?: string;
5
8
  /** Optional bot username used when the hostname starts with "local". */
6
9
  readonly localBotID?: string;
7
10
  }
@@ -11,3 +14,6 @@ export declare const TelegramLoginConfig: InjectionToken<ITelegramLoginConfig>;
11
14
  * Falls back to the historical Sneat defaults when no config is provided.
12
15
  */
13
16
  export declare function resolveTelegramBotID(config: ITelegramLoginConfig | null, hostname: string): string;
17
+ /** Telegram can use an app backend while other auth providers retain their API. */
18
+ export declare function telegramAuthApiFactory(): SneatApiService;
19
+ export declare const TelegramAuthApi: InjectionToken<SneatApiService>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sneat/auth-ui",
3
- "version": "0.27.45",
3
+ "version": "0.27.46",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },