@sneat/auth-ui 0.27.29 → 0.27.31

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 (32) hide show
  1. package/esm2022/index.js +1 -0
  2. package/esm2022/index.js.map +1 -1
  3. package/esm2022/lib/pages/login-page/auth-panel.component.js +147 -0
  4. package/esm2022/lib/pages/login-page/auth-panel.component.js.map +1 -0
  5. package/esm2022/lib/pages/login-page/email-login-form/email-login-form.component.js +11 -5
  6. package/esm2022/lib/pages/login-page/email-login-form/email-login-form.component.js.map +1 -1
  7. package/esm2022/lib/pages/login-page/login-page.component.js +34 -90
  8. package/esm2022/lib/pages/login-page/login-page.component.js.map +1 -1
  9. package/esm2022/lib/pages/login-page/login-with-telegram.component.js +33 -13
  10. package/esm2022/lib/pages/login-page/login-with-telegram.component.js.map +1 -1
  11. package/esm2022/lib/pages/login-page/safe-auth-return-path.js +45 -0
  12. package/esm2022/lib/pages/login-page/safe-auth-return-path.js.map +1 -0
  13. package/esm2022/lib/pages/sign-in-from-email-link/sign-in-from-email-link-page.component.js +5 -1
  14. package/esm2022/lib/pages/sign-in-from-email-link/sign-in-from-email-link-page.component.js.map +1 -1
  15. package/esm2022/lib/sso/sso-callback-page.component.js +10 -4
  16. package/esm2022/lib/sso/sso-callback-page.component.js.map +1 -1
  17. package/esm2022/lib/sso/sso-login-page.component.js +22 -4
  18. package/esm2022/lib/sso/sso-login-page.component.js.map +1 -1
  19. package/esm2022/lib/sso/sso.models.js +1 -0
  20. package/esm2022/lib/sso/sso.models.js.map +1 -1
  21. package/index.d.ts +1 -0
  22. package/lib/pages/login-page/auth-panel.component.d.ts +35 -0
  23. package/lib/pages/login-page/email-login-form/email-login-form.component.d.ts +2 -1
  24. package/lib/pages/login-page/login-page.component.d.ts +3 -12
  25. package/lib/pages/login-page/login-with-telegram.component.d.ts +2 -0
  26. package/lib/pages/login-page/safe-auth-return-path.d.ts +8 -0
  27. package/lib/pages/sign-in-from-email-link/sign-in-from-email-link-page.component.d.ts +2 -0
  28. package/lib/sso/sso-callback-page.component.d.ts +1 -0
  29. package/lib/sso/sso-login-page.component.d.ts +2 -0
  30. package/lib/sso/sso.models.d.ts +1 -0
  31. package/package.json +2 -2
  32. package/tsconfig.lib.prod.tsbuildinfo +1 -1
@@ -1,17 +1,14 @@
1
- import { Component, computed, signal, inject, effect, ChangeDetectionStrategy } from '@angular/core';
1
+ import { Component, computed, inject, ChangeDetectionStrategy } from '@angular/core';
2
2
  import { toSignal } from '@angular/core/rxjs-interop';
3
- import { FormsModule } from '@angular/forms';
4
- import { ActivatedRoute, RouterLink } from '@angular/router';
5
- import { Capacitor } from '@capacitor/core';
6
- import { NavController, IonBackButton, IonButton, IonButtons, IonCard, IonCardContent, IonCol, IonContent, IonGrid, IonHeader, IonIcon, IonItem, IonItemDivider, IonLabel, IonList, IonRow, IonSpinner, IonText, IonTitle, IonToolbar, } from '@ionic/angular';
7
- import { AuthStatuses, LoginEventsHandler, SneatAuthStateService, } from '@sneat/auth-core';
8
- import { SneatUserService } from '@sneat/auth-core';
3
+ import { ActivatedRoute } from '@angular/router';
4
+ import { NavController, IonBackButton, IonButton, IonButtons, IonCard, IonCardContent, IonContent, IonHeader, IonSpinner, IonText, IonTitle, IonToolbar, } from '@ionic/angular';
5
+ import { LoginEventsHandler, SneatAuthStateService, SneatUserService, isSneatAccountReady, } from '@sneat/auth-core';
9
6
  import { AnalyticsService, APP_INFO, clearCurrentSpace, currentSpacePath, readCurrentSpace, SpaceTypeFamily, } from '@sneat/core';
10
7
  import { RandomIdService } from '@sneat/random';
11
8
  import { ClassName, SneatBaseComponent } from '@sneat/ui';
12
- import { Subject, takeUntil } from 'rxjs';
13
- import { EmailLoginFormComponent, } from './email-login-form/email-login-form.component';
14
- import { LoginWithTelegramComponent } from './login-with-telegram.component';
9
+ import { combineLatest, Subject, takeUntil } from 'rxjs';
10
+ import { AuthPanelComponent } from './auth-panel.component';
11
+ import { safeAuthReturnPath } from './safe-auth-return-path';
15
12
  import * as i0 from "@angular/core";
16
13
  export class LoginPageComponent extends SneatBaseComponent {
17
14
  constructor() {
@@ -23,38 +20,38 @@ export class LoginPageComponent extends SneatBaseComponent {
23
20
  this.authStateService = inject(SneatAuthStateService);
24
21
  this.appInfo = inject(APP_INFO);
25
22
  this.loginEventsHandler = inject(LoginEventsHandler, { optional: true });
26
- this.signingWith = signal(undefined, /* @ts-ignore */
27
- ...(ngDevMode ? [{ debugName: "signingWith" }] : /* istanbul ignore next */ []));
28
- this.isNativePlatform = Capacitor.isNativePlatform();
29
23
  // Surfaces the Firebase auth state on the login page itself: if the user is
30
24
  // already signed in (e.g. the app failed to navigate them onward) we show a
31
25
  // "you are already signed in as X" panel instead of the sign-in form, so an
32
26
  // authenticated-but-stuck state is obvious rather than looking like sign-in
33
27
  // is broken.
34
- this.isAuthenticated = computed(() => this.authStatus() === 'authenticated', /* @ts-ignore */
28
+ this.isAuthenticated = computed(() => this.authState()?.status === 'authenticated' &&
29
+ !!this.authState()?.user?.uid &&
30
+ !this.authState()?.user?.isAnonymous, /* @ts-ignore */
35
31
  ...(ngDevMode ? [{ debugName: "isAuthenticated" }] : /* istanbul ignore next */ []));
36
32
  // While Firebase is still resolving the session — the initial state, and the
37
33
  // brief window right after a signInWithRedirect return — show a "signing you
38
34
  // in" spinner instead of flashing the sign-in form before we navigate onward.
39
- this.isAuthenticating = computed(() => this.authStatus() === 'authenticating', /* @ts-ignore */
35
+ this.isAuthenticating = computed(() => this.authState()?.status === 'authenticating' &&
36
+ this.authState()?.loadingPhase !== 'failed', /* @ts-ignore */
40
37
  ...(ngDevMode ? [{ debugName: "isAuthenticating" }] : /* istanbul ignore next */ []));
41
- this.authStatus = toSignal(this.authStateService.authStatus);
42
- this.authUser = toSignal(this.authStateService.authUser);
38
+ this.authState = toSignal(this.authStateService.authState);
43
39
  this.userState = toSignal(this.userService.userState);
40
+ this.isAccountReady = computed(() => {
41
+ const userState = this.userState();
42
+ const authState = this.authState();
43
+ return isSneatAccountReady(authState, userState);
44
+ }, /* @ts-ignore */
45
+ ...(ngDevMode ? [{ debugName: "isAccountReady" }] : /* istanbul ignore next */ []));
44
46
  this.signedInAs = computed(() => {
45
- const u = this.authUser();
47
+ const u = this.authState()?.user;
46
48
  return u?.displayName || u?.email || u?.uid || '';
47
49
  }, /* @ts-ignore */
48
50
  ...(ngDevMode ? [{ debugName: "signedInAs" }] : /* istanbul ignore next */ []));
49
- effect(() => {
50
- if (this.authStatus() === 'notAuthenticated') {
51
- this.signingWith.set(undefined);
52
- }
53
- });
54
51
  const appInfo = this.appInfo;
55
52
  this.appTitle = appInfo.appTitle || 'Sneat.app';
56
53
  if (location.hash.startsWith('#/')) {
57
- this.redirectTo = location.hash.substring(1);
54
+ this.redirectTo = safeAuthReturnPath(location.hash.substring(1));
58
55
  }
59
56
  this.to = this.route.snapshot.queryParams['to']; // should we subscribe? I believe no.
60
57
  this.reason = this.route.snapshot.queryParams['reason'];
@@ -62,26 +59,24 @@ export class LoginPageComponent extends SneatBaseComponent {
62
59
  const action = location.hash.match(/[#&]action=(\w+)/);
63
60
  this.action = action?.[1];
64
61
  const userRecordLoaded = new Subject();
65
- this.userService.userState
62
+ combineLatest([this.authStateService.authState, this.userService.userState])
66
63
  .pipe(takeUntil(userRecordLoaded), this.takeUntilDestroyed())
67
64
  .subscribe({
68
- next: (userState) => {
69
- if (userState.record) {
70
- userRecordLoaded.next();
71
- }
72
- else {
65
+ next: ([authState, userState]) => {
66
+ const userRecord = userState.record;
67
+ if (!userRecord || !isSneatAccountReady(authState, userState))
73
68
  return;
74
- }
69
+ userRecordLoaded.next();
75
70
  // Fall back to the persisted current space so it is restored after login,
76
71
  // but only if the user actually has access to it.
77
72
  const space = readCurrentSpace();
78
- const hasAccess = !!space && (userState.record.spaceIDs?.includes(space.id) ||
79
- (!!userState.record.spaces && space.id in userState.record.spaces));
73
+ const hasAccess = !!space && (userRecord.spaceIDs?.includes(space.id) ||
74
+ (!!userRecord.spaces && space.id in userRecord.spaces));
80
75
  if (space && !hasAccess) {
81
76
  clearCurrentSpace();
82
77
  }
83
78
  const activePath = hasAccess ? currentSpacePath() : undefined;
84
- const family = Object.entries(userState.record.spaces || {}).find(([, brief]) => brief.type === SpaceTypeFamily);
79
+ const family = Object.entries(userRecord.spaces || {}).find(([, brief]) => brief.type === SpaceTypeFamily);
85
80
  const familyPath = family
86
81
  ? `/space/${SpaceTypeFamily}/${family[0]}`
87
82
  : undefined;
@@ -89,21 +84,16 @@ export class LoginPageComponent extends SneatBaseComponent {
89
84
  this.navController
90
85
  .navigateRoot(redirectTo)
91
86
  .catch((err) => {
92
- this.signingWith.set(undefined);
93
87
  this.errorLogger.logError(err, 'Failed to navigate back to ' + redirectTo);
94
88
  });
95
89
  },
96
90
  error: this.errorHandler('Failed to get user state after login'),
97
91
  });
98
92
  }
99
- ionViewDidEnter() {
100
- this.signingWith.set(undefined);
101
- }
102
- onEmailFormStatusChanged(signingWith) {
103
- this.signingWith.set(signingWith);
104
- }
105
93
  // Proceed into the app from the "already signed in" panel.
106
94
  continueToApp() {
95
+ if (!this.isAccountReady())
96
+ return;
107
97
  const space = readCurrentSpace();
108
98
  const userState = this.userState();
109
99
  const hasAccess = !!space && !!userState?.record && (userState.record.spaceIDs?.includes(space.id) ||
@@ -120,7 +110,6 @@ export class LoginPageComponent extends SneatBaseComponent {
120
110
  this.navController
121
111
  .navigateRoot(redirectTo)
122
112
  .catch((err) => {
123
- this.signingWith.set(undefined);
124
113
  this.errorLogger.logError(err, 'Failed to navigate to ' + redirectTo);
125
114
  });
126
115
  }
@@ -131,39 +120,6 @@ export class LoginPageComponent extends SneatBaseComponent {
131
120
  .signOut()
132
121
  .catch(this.errorLogger.logErrorHandler('Failed to sign out for re-login'));
133
122
  }
134
- async loginWith(provider) {
135
- this.signingWith.set(provider);
136
- try {
137
- await this.authStateService.signInWith(provider);
138
- // We do not reset this.signingWith in case of succesful sign in as we should redirect from login page
139
- // and not to allow user to do a double sign-in.
140
- }
141
- catch (e) {
142
- const errMsg = e.errorMessage;
143
- if (errMsg !== 'The user canceled the sign-in flow.' &&
144
- !errMsg?.includes('com.apple.AuthenticationServices.AuthorizationError error 1001.')) {
145
- this.errorLogger.logError(e, `Failed to sign-in with ${provider}`);
146
- }
147
- this.signingWith.set(undefined);
148
- }
149
- }
150
- onLoggedIn(userCredential) {
151
- this.signingWith.set(undefined);
152
- if (!userCredential.user) {
153
- return;
154
- }
155
- if (userCredential.user.email) {
156
- const prevEmail = localStorage.getItem('emailForSignIn') || '';
157
- if (!prevEmail) {
158
- localStorage.setItem('emailForSignIn', userCredential.user.email);
159
- }
160
- }
161
- const authState = {
162
- status: AuthStatuses.authenticated,
163
- user: userCredential.user,
164
- };
165
- this.userService.onUserSignedIn(authState);
166
- }
167
123
  errorHandler(m, eventName, eventParams) {
168
124
  return (err) => this.handleError(err, m, eventName, eventParams);
169
125
  }
@@ -174,7 +130,6 @@ export class LoginPageComponent extends SneatBaseComponent {
174
130
  this.errorLogger.logError(err, m, {
175
131
  report: !err.code,
176
132
  });
177
- this.signingWith.set(undefined);
178
133
  }
179
134
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: LoginPageComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
180
135
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.1.3", type: LoginPageComponent, isStandalone: true, selector: "sneat-login", providers: [
@@ -183,15 +138,12 @@ export class LoginPageComponent extends SneatBaseComponent {
183
138
  useValue: 'LoginPageComponent',
184
139
  },
185
140
  RandomIdService,
186
- ], usesInheritance: true, ngImport: i0, template: "<ion-header>\n <ion-toolbar color=\"light\">\n <ion-buttons slot=\"start\">\n <ion-back-button />\n </ion-buttons>\n <ion-title>Login &#64; {{ appTitle }}</ion-title>\n </ion-toolbar>\n</ion-header>\n\n<ion-content id=\"main-content\">\n @if (reason) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <h2 class=\"reason-title\">{{ reason }}</h2>\n @if (reasonDetail) {\n <p class=\"reason-detail\">{{ reasonDetail }}</p>\n }\n </ion-card-content>\n </ion-card>\n } @else if (to) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <p>Please sign in to join a team</p>\n </ion-card-content>\n </ion-card>\n }\n\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">\n Sign in with your Sneat account.\n </ion-text>\n </p>\n\n @if (isAuthenticating()) {\n <ion-card>\n <ion-card-content class=\"ion-text-center ion-padding\">\n <ion-spinner name=\"lines\" />\n <p class=\"ion-no-margin ion-padding-top\">Signing you in\u2026</p>\n </ion-card-content>\n </ion-card>\n } @else if (isAuthenticated()) {\n <ion-card color=\"success\">\n <ion-card-content>\n <p>\n @if (signedInAs()) {\n You are already signed in as <strong>{{ signedInAs() }}</strong>.\n } @else {\n You are already signed in.\n }\n </p>\n <ion-button expand=\"block\" (click)=\"continueToApp()\">Continue</ion-button>\n <ion-button\n expand=\"block\"\n fill=\"outline\"\n color=\"medium\"\n (click)=\"reLogin()\"\n >\n Re-login as someone else\n </ion-button>\n </ion-card-content>\n </ion-card>\n } @else {\n <sneat-email-login-form\n (signingWithChange)=\"onEmailFormStatusChanged($event)\"\n (loggedIn)=\"onLoggedIn($event)\"\n />\n\n <div class=\"ion-padding-horizontal ion-text-center\">\n <ion-button fill=\"outline\" expand=\"block\" routerLink=\"/sso\">\n <ion-icon name=\"business-outline\" slot=\"start\" />\n Sign in with company SSO\n </ion-button>\n </div>\n\n <ion-card>\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 <ion-grid class=\"ion-grid-layout\">\n @if (!isNativePlatform) {\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 <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 color=\"danger\" name=\"logo-google\" slot=\"start\" />\n }\n <ion-label color=\"danger\"> Login with Google</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\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\n <ion-label color=\"dark\"> Login with Apple</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n </ion-row>\n <ion-row>\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 slot=\"start\" color=\"secondary\" name=\"logo-windows\" />\n }\n <ion-label color=\"secondary\">Login with Microsoft</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\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 slot=\"start\" color=\"primary\" name=\"lines-small\" />\n } @else {\n <ion-icon slot=\"start\" color=\"primary\" name=\"logo-facebook\" />\n }\n <ion-label color=\"primary\">Login with Facebook</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n </ion-row>\n <ion-row>\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 slot=\"start\" color=\"tertiary\" name=\"lines-small\" />\n } @else {\n <ion-icon slot=\"start\" color=\"tertiary\" name=\"logo-github\" />\n }\n <ion-label color=\"tertiary\">Login with GitHub</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n </ion-row>\n </ion-grid>\n </ion-card>\n }\n\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">\n If any issues get\n <a href=\"mailto:help@sneat.app?subject=Problem+with+login+at+Sneat.app\"\n >help&#64;sneat.app</a\n >\n </ion-text>\n </p>\n</ion-content>\n", dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "browserUrl", "routerLink"] }, { kind: "component", type: LoginWithTelegramComponent, selector: "sneat-login-with-telegram", inputs: ["isUserAuthenticated", "botID", "size", "requestAccess", "userPic"] }, { kind: "component", type: EmailLoginFormComponent, selector: "sneat-email-login-form", outputs: ["signingWithChange", "loggedIn"] }, { kind: "component", type: IonHeader, selector: "ion-header", inputs: ["collapse", "mode", "translucent"] }, { kind: "component", type: IonToolbar, selector: "ion-toolbar", inputs: ["color", "mode"] }, { 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: IonButtons, selector: "ion-buttons", inputs: ["collapse"] }, { kind: "component", type: IonBackButton, selector: "ion-back-button" }, { kind: "component", type: IonTitle, selector: "ion-title", inputs: ["color", "size"] }, { kind: "component", type: IonContent, selector: "ion-content", inputs: ["color", "fixedSlotPlacement", "forceOverscroll", "fullscreen", "scrollEvents", "scrollX", "scrollY"], outputs: ["ionScrollStart", "ionScroll", "ionScrollEnd"] }, { kind: "component", type: IonCardContent, selector: "ion-card-content", inputs: ["mode"] }, { kind: "component", type: IonText, selector: "ion-text", inputs: ["color", "mode"] }, { kind: "component", type: IonCard, selector: "ion-card", inputs: ["button", "color", "disabled", "download", "href", "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: IonRow, selector: "ion-row" }, { 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: IonItem, selector: "ion-item", inputs: ["button", "color", "detail", "detailIcon", "disabled", "download", "href", "lines", "mode", "rel", "routerAnimation", "routerDirection", "target", "type"] }, { kind: "component", type: IonSpinner, selector: "ion-spinner", inputs: ["color", "duration", "name", "paused"] }, { kind: "component", type: IonIcon, selector: "ion-icon", inputs: ["color", "flipRtl", "icon", "ios", "lazy", "md", "mode", "name", "sanitize", "size", "src"] }, { kind: "component", type: IonList, selector: "ion-list", inputs: ["inset", "lines", "mode"] }, { kind: "component", type: IonGrid, selector: "ion-grid", inputs: ["fixed"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
141
+ ], usesInheritance: true, ngImport: i0, template: "<ion-header>\n <ion-toolbar color=\"light\">\n <ion-buttons slot=\"start\">\n <ion-back-button />\n </ion-buttons>\n <ion-title>Login &#64; {{ appTitle }}</ion-title>\n </ion-toolbar>\n</ion-header>\n\n<ion-content id=\"main-content\">\n @if (reason) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <h2 class=\"reason-title\">{{ reason }}</h2>\n @if (reasonDetail) {\n <p class=\"reason-detail\">{{ reasonDetail }}</p>\n }\n </ion-card-content>\n </ion-card>\n } @else if (to) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <p>Please sign in to join a team</p>\n </ion-card-content>\n </ion-card>\n }\n\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 @if (isAuthenticating()) {\n <ion-card>\n <ion-card-content class=\"ion-text-center ion-padding\">\n <ion-spinner name=\"lines\" />\n <p class=\"ion-no-margin ion-padding-top\">Signing you in\u2026</p>\n </ion-card-content>\n </ion-card>\n } @else if (isAuthenticated()) {\n <ion-card color=\"success\">\n <ion-card-content>\n <p>\n @if (signedInAs()) {\n You are already signed in as <strong>{{ signedInAs() }}</strong>.\n } @else {\n You are already signed in.\n }\n </p>\n @if (isAccountReady()) {\n <ion-button expand=\"block\" (click)=\"continueToApp()\">Continue</ion-button>\n } @else {\n <sneat-auth-panel\n [returnTo]=\"redirectTo\"\n [showIntro]=\"false\"\n [showCredentials]=\"false\"\n />\n }\n <ion-button\n expand=\"block\"\n fill=\"outline\"\n color=\"medium\"\n (click)=\"reLogin()\"\n >\n Re-login as someone else\n </ion-button>\n </ion-card-content>\n </ion-card>\n } @else {\n <sneat-auth-panel [returnTo]=\"redirectTo\" [showIntro]=\"false\" />\n }\n\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">\n If any issues get\n <a href=\"mailto:help@sneat.app?subject=Problem+with+login+at+Sneat.app\"\n >help&#64;sneat.app</a\n >\n </ion-text>\n </p>\n</ion-content>\n", dependencies: [{ kind: "component", type: AuthPanelComponent, selector: "sneat-auth-panel", inputs: ["returnTo", "showIntro", "showCredentials"], outputs: ["accountReadyChange"] }, { kind: "component", type: IonHeader, selector: "ion-header", inputs: ["collapse", "mode", "translucent"] }, { kind: "component", type: IonToolbar, selector: "ion-toolbar", inputs: ["color", "mode"] }, { 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: IonButtons, selector: "ion-buttons", inputs: ["collapse"] }, { kind: "component", type: IonBackButton, selector: "ion-back-button" }, { kind: "component", type: IonTitle, selector: "ion-title", inputs: ["color", "size"] }, { kind: "component", type: IonContent, selector: "ion-content", inputs: ["color", "fixedSlotPlacement", "forceOverscroll", "fullscreen", "scrollEvents", "scrollX", "scrollY"], outputs: ["ionScrollStart", "ionScroll", "ionScrollEnd"] }, { kind: "component", type: IonCardContent, selector: "ion-card-content", inputs: ["mode"] }, { kind: "component", type: IonText, selector: "ion-text", inputs: ["color", "mode"] }, { kind: "component", type: IonCard, selector: "ion-card", inputs: ["button", "color", "disabled", "download", "href", "mode", "rel", "routerAnimation", "routerDirection", "target", "type"] }, { kind: "component", type: IonSpinner, selector: "ion-spinner", inputs: ["color", "duration", "name", "paused"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
187
142
  }
188
143
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImport: i0, type: LoginPageComponent, decorators: [{
189
144
  type: Component,
190
145
  args: [{ selector: 'sneat-login', imports: [
191
- FormsModule,
192
- RouterLink,
193
- LoginWithTelegramComponent,
194
- EmailLoginFormComponent,
146
+ AuthPanelComponent,
195
147
  IonHeader,
196
148
  IonToolbar,
197
149
  IonButton,
@@ -202,21 +154,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.3", ngImpor
202
154
  IonCardContent,
203
155
  IonText,
204
156
  IonCard,
205
- IonItemDivider,
206
- IonLabel,
207
- IonRow,
208
- IonCol,
209
- IonItem,
210
157
  IonSpinner,
211
- IonIcon,
212
- IonList,
213
- IonGrid,
214
158
  ], changeDetection: ChangeDetectionStrategy.OnPush, providers: [
215
159
  {
216
160
  provide: ClassName,
217
161
  useValue: 'LoginPageComponent',
218
162
  },
219
163
  RandomIdService,
220
- ], template: "<ion-header>\n <ion-toolbar color=\"light\">\n <ion-buttons slot=\"start\">\n <ion-back-button />\n </ion-buttons>\n <ion-title>Login &#64; {{ appTitle }}</ion-title>\n </ion-toolbar>\n</ion-header>\n\n<ion-content id=\"main-content\">\n @if (reason) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <h2 class=\"reason-title\">{{ reason }}</h2>\n @if (reasonDetail) {\n <p class=\"reason-detail\">{{ reasonDetail }}</p>\n }\n </ion-card-content>\n </ion-card>\n } @else if (to) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <p>Please sign in to join a team</p>\n </ion-card-content>\n </ion-card>\n }\n\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">\n Sign in with your Sneat account.\n </ion-text>\n </p>\n\n @if (isAuthenticating()) {\n <ion-card>\n <ion-card-content class=\"ion-text-center ion-padding\">\n <ion-spinner name=\"lines\" />\n <p class=\"ion-no-margin ion-padding-top\">Signing you in\u2026</p>\n </ion-card-content>\n </ion-card>\n } @else if (isAuthenticated()) {\n <ion-card color=\"success\">\n <ion-card-content>\n <p>\n @if (signedInAs()) {\n You are already signed in as <strong>{{ signedInAs() }}</strong>.\n } @else {\n You are already signed in.\n }\n </p>\n <ion-button expand=\"block\" (click)=\"continueToApp()\">Continue</ion-button>\n <ion-button\n expand=\"block\"\n fill=\"outline\"\n color=\"medium\"\n (click)=\"reLogin()\"\n >\n Re-login as someone else\n </ion-button>\n </ion-card-content>\n </ion-card>\n } @else {\n <sneat-email-login-form\n (signingWithChange)=\"onEmailFormStatusChanged($event)\"\n (loggedIn)=\"onLoggedIn($event)\"\n />\n\n <div class=\"ion-padding-horizontal ion-text-center\">\n <ion-button fill=\"outline\" expand=\"block\" routerLink=\"/sso\">\n <ion-icon name=\"business-outline\" slot=\"start\" />\n Sign in with company SSO\n </ion-button>\n </div>\n\n <ion-card>\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 <ion-grid class=\"ion-grid-layout\">\n @if (!isNativePlatform) {\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 <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 color=\"danger\" name=\"logo-google\" slot=\"start\" />\n }\n <ion-label color=\"danger\"> Login with Google</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\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\n <ion-label color=\"dark\"> Login with Apple</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n </ion-row>\n <ion-row>\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 slot=\"start\" color=\"secondary\" name=\"logo-windows\" />\n }\n <ion-label color=\"secondary\">Login with Microsoft</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\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 slot=\"start\" color=\"primary\" name=\"lines-small\" />\n } @else {\n <ion-icon slot=\"start\" color=\"primary\" name=\"logo-facebook\" />\n }\n <ion-label color=\"primary\">Login with Facebook</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n </ion-row>\n <ion-row>\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 slot=\"start\" color=\"tertiary\" name=\"lines-small\" />\n } @else {\n <ion-icon slot=\"start\" color=\"tertiary\" name=\"logo-github\" />\n }\n <ion-label color=\"tertiary\">Login with GitHub</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n </ion-row>\n </ion-grid>\n </ion-card>\n }\n\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">\n If any issues get\n <a href=\"mailto:help@sneat.app?subject=Problem+with+login+at+Sneat.app\"\n >help&#64;sneat.app</a\n >\n </ion-text>\n </p>\n</ion-content>\n" }]
164
+ ], template: "<ion-header>\n <ion-toolbar color=\"light\">\n <ion-buttons slot=\"start\">\n <ion-back-button />\n </ion-buttons>\n <ion-title>Login &#64; {{ appTitle }}</ion-title>\n </ion-toolbar>\n</ion-header>\n\n<ion-content id=\"main-content\">\n @if (reason) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <h2 class=\"reason-title\">{{ reason }}</h2>\n @if (reasonDetail) {\n <p class=\"reason-detail\">{{ reasonDetail }}</p>\n }\n </ion-card-content>\n </ion-card>\n } @else if (to) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <p>Please sign in to join a team</p>\n </ion-card-content>\n </ion-card>\n }\n\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 @if (isAuthenticating()) {\n <ion-card>\n <ion-card-content class=\"ion-text-center ion-padding\">\n <ion-spinner name=\"lines\" />\n <p class=\"ion-no-margin ion-padding-top\">Signing you in\u2026</p>\n </ion-card-content>\n </ion-card>\n } @else if (isAuthenticated()) {\n <ion-card color=\"success\">\n <ion-card-content>\n <p>\n @if (signedInAs()) {\n You are already signed in as <strong>{{ signedInAs() }}</strong>.\n } @else {\n You are already signed in.\n }\n </p>\n @if (isAccountReady()) {\n <ion-button expand=\"block\" (click)=\"continueToApp()\">Continue</ion-button>\n } @else {\n <sneat-auth-panel\n [returnTo]=\"redirectTo\"\n [showIntro]=\"false\"\n [showCredentials]=\"false\"\n />\n }\n <ion-button\n expand=\"block\"\n fill=\"outline\"\n color=\"medium\"\n (click)=\"reLogin()\"\n >\n Re-login as someone else\n </ion-button>\n </ion-card-content>\n </ion-card>\n } @else {\n <sneat-auth-panel [returnTo]=\"redirectTo\" [showIntro]=\"false\" />\n }\n\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">\n If any issues get\n <a href=\"mailto:help@sneat.app?subject=Problem+with+login+at+Sneat.app\"\n >help&#64;sneat.app</a\n >\n </ion-text>\n </p>\n</ion-content>\n" }]
221
165
  }], ctorParameters: () => [] });
222
166
  //# sourceMappingURL=login-page.component.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"login-page.component.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/login-page.component.ts","../../../../../../../../libs/auth/ui/src/lib/pages/login-page/login-page.component.html"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACrG,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,iBAAiB,CA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,0NACP,UAAU,yGACV,OAAO,2JACP,OAAO,yFACP,OAAO;;2FAWE,kBAAkB;kBArC9B,SAAS;+BACE,aAAa,WAEd;wBACP,WAAW;wBACX,UAAU;wBACV,0BAA0B;wBAC1B,uBAAuB;wBACvB,SAAS;wBACT,UAAU;wBACV,SAAS;wBACT,UAAU;wBACV,aAAa;wBACb,QAAQ;wBACR,UAAU;wBACV,cAAc;wBACd,OAAO;wBACP,OAAO;wBACP,cAAc;wBACd,QAAQ;wBACR,MAAM;wBACN,MAAM;wBACN,OAAO;wBACP,UAAU;wBACV,OAAO;wBACP,OAAO;wBACP,OAAO;qBACR,mBACgB,uBAAuB,CAAC,MAAM,aACpC;wBACT;4BACE,OAAO,EAAE,SAAS;4BAClB,QAAQ,EAAE,oBAAoB;yBAC/B;wBACD,eAAe;qBAChB","sourcesContent":["import { Component, computed, signal, inject, effect, ChangeDetectionStrategy } from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { FormsModule } from '@angular/forms';\nimport { ActivatedRoute, RouterLink } from '@angular/router';\nimport { Capacitor } from '@capacitor/core';\nimport {\n NavController,\n IonBackButton,\n IonButton,\n IonButtons,\n IonCard,\n IonCardContent,\n IonCol,\n IonContent,\n IonGrid,\n IonHeader,\n IonIcon,\n IonItem,\n IonItemDivider,\n IonLabel,\n IonList,\n IonRow,\n IonSpinner,\n IonText,\n IonTitle,\n IonToolbar,\n} from '@ionic/angular';\nimport {\n AuthProviderID,\n AuthStatuses,\n ILoginEventsHandler,\n ISneatAuthState,\n LoginEventsHandler,\n SneatAuthStateService,\n} from '@sneat/auth-core';\nimport { SneatUserService } from '@sneat/auth-core';\nimport {\n AnalyticsService,\n APP_INFO,\n clearCurrentSpace,\n currentSpacePath,\n IAnalyticsService,\n IAppInfo,\n readCurrentSpace,\n SpaceTypeFamily,\n} from '@sneat/core';\nimport { RandomIdService } from '@sneat/random';\nimport { ClassName, SneatBaseComponent } from '@sneat/ui';\nimport { Subject, takeUntil } from 'rxjs';\nimport {\n EmailFormSigningWith,\n EmailLoginFormComponent,\n} from './email-login-form/email-login-form.component';\nimport { UserCredential } from 'firebase/auth';\nimport { LoginWithTelegramComponent } from './login-with-telegram.component';\n\ntype Action = 'join' | 'refuse'; // TODO: inject provider for action descriptions/messages.\n\n@Component({\n selector: 'sneat-login',\n templateUrl: './login-page.component.html',\n imports: [\n FormsModule,\n RouterLink,\n LoginWithTelegramComponent,\n EmailLoginFormComponent,\n IonHeader,\n IonToolbar,\n IonButton,\n IonButtons,\n IonBackButton,\n IonTitle,\n IonContent,\n IonCardContent,\n IonText,\n IonCard,\n IonItemDivider,\n IonLabel,\n IonRow,\n IonCol,\n IonItem,\n IonSpinner,\n IonIcon,\n IonList,\n IonGrid,\n ],\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [\n {\n provide: ClassName,\n useValue: 'LoginPageComponent',\n },\n RandomIdService,\n ],\n})\nexport class LoginPageComponent extends SneatBaseComponent {\n private readonly analyticsService =\n inject<IAnalyticsService>(AnalyticsService);\n private readonly route = inject(ActivatedRoute);\n private readonly navController = inject(NavController);\n private readonly userService = inject(SneatUserService);\n private readonly authStateService = inject(SneatAuthStateService);\n private appInfo = inject<IAppInfo>(APP_INFO);\n private readonly loginEventsHandler = inject<ILoginEventsHandler>(\n LoginEventsHandler,\n { optional: true },\n );\n\n protected readonly signingWith = signal<AuthProviderID | undefined>(\n undefined,\n );\n private readonly redirectTo?: string;\n protected readonly to?: string;\n // Free-text explanation of WHY sign-in is needed, passed by the calling page\n // as query params (rendered as escaped text — never as HTML):\n // reason — short heading, e.g. \"Sign in to create a new game\"\n // reasonDetail — optional sub-heading / one-line elaboration\n protected readonly reason?: string;\n protected readonly reasonDetail?: string;\n protected readonly action?: Action; // TODO: document possible values?\n\n protected readonly isNativePlatform = Capacitor.isNativePlatform();\n\n protected readonly appTitle: string;\n\n // Surfaces the Firebase auth state on the login page itself: if the user is\n // already signed in (e.g. the app failed to navigate them onward) we show a\n // \"you are already signed in as X\" panel instead of the sign-in form, so an\n // authenticated-but-stuck state is obvious rather than looking like sign-in\n // is broken.\n protected readonly isAuthenticated = computed(\n () => this.authStatus() === 'authenticated',\n );\n // While Firebase is still resolving the session — the initial state, and the\n // brief window right after a signInWithRedirect return — show a \"signing you\n // in\" spinner instead of flashing the sign-in form before we navigate onward.\n protected readonly isAuthenticating = computed(\n () => this.authStatus() === 'authenticating',\n );\n private readonly authStatus = toSignal(this.authStateService.authStatus);\n private readonly authUser = toSignal(this.authStateService.authUser);\n private readonly userState = toSignal(this.userService.userState);\n protected readonly signedInAs = computed(() => {\n const u = this.authUser();\n return u?.displayName || u?.email || u?.uid || '';\n });\n\n constructor() {\n super();\n effect(() => {\n if (this.authStatus() === 'notAuthenticated') {\n this.signingWith.set(undefined);\n }\n });\n\n const appInfo = this.appInfo;\n this.appTitle = appInfo.appTitle || 'Sneat.app';\n if (location.hash.startsWith('#/')) {\n this.redirectTo = location.hash.substring(1);\n }\n this.to = this.route.snapshot.queryParams['to']; // should we subscribe? I believe no.\n this.reason = this.route.snapshot.queryParams['reason'];\n this.reasonDetail = this.route.snapshot.queryParams['reasonDetail'];\n const action = location.hash.match(/[#&]action=(\\w+)/);\n this.action = action?.[1] as Action;\n\n const userRecordLoaded = new Subject<void>();\n this.userService.userState\n .pipe(takeUntil(userRecordLoaded), this.takeUntilDestroyed())\n .subscribe({\n next: (userState) => {\n if (userState.record) {\n userRecordLoaded.next();\n } else {\n return;\n }\n // Fall back to the persisted current space so it is restored after login,\n // but only if the user actually has access to it.\n const space = readCurrentSpace();\n const hasAccess = !!space && (\n userState.record.spaceIDs?.includes(space.id) ||\n (!!userState.record.spaces && space.id in userState.record.spaces)\n );\n if (space && !hasAccess) {\n clearCurrentSpace();\n }\n const activePath = hasAccess ? currentSpacePath() : undefined;\n const family = Object.entries(userState.record.spaces || {}).find(\n ([, brief]) => brief.type === SpaceTypeFamily,\n );\n const familyPath = family\n ? `/space/${SpaceTypeFamily}/${family[0]}`\n : undefined;\n const redirectTo = this.redirectTo || activePath || familyPath || '/';\n this.navController\n .navigateRoot(redirectTo)\n .catch((err) => {\n this.signingWith.set(undefined);\n this.errorLogger.logError(\n err,\n 'Failed to navigate back to ' + redirectTo,\n );\n });\n },\n error: this.errorHandler('Failed to get user state after login'),\n });\n }\n\n ionViewDidEnter(): void {\n this.signingWith.set(undefined);\n }\n\n protected onEmailFormStatusChanged(signingWith?: EmailFormSigningWith): void {\n this.signingWith.set(signingWith as AuthProviderID);\n }\n\n // Proceed into the app from the \"already signed in\" panel.\n protected continueToApp(): void {\n const space = readCurrentSpace();\n const userState = this.userState();\n const hasAccess = !!space && !!userState?.record && (\n userState.record.spaceIDs?.includes(space.id) ||\n (!!userState.record.spaces && space.id in userState.record.spaces)\n );\n if (space && !hasAccess) {\n clearCurrentSpace();\n }\n const activePath = hasAccess ? currentSpacePath() : undefined;\n const family = Object.entries(userState?.record?.spaces || {}).find(\n ([, brief]) => brief.type === SpaceTypeFamily,\n );\n const familyPath = family\n ? `/space/${SpaceTypeFamily}/${family[0]}`\n : undefined;\n const redirectTo = this.redirectTo || activePath || familyPath || '/';\n this.navController\n .navigateRoot(redirectTo)\n .catch((err) => {\n this.signingWith.set(undefined);\n this.errorLogger.logError(\n err,\n 'Failed to navigate to ' + redirectTo,\n );\n });\n }\n\n // Sign out so the sign-in form is shown again (e.g. to log in as someone else).\n protected reLogin(): void {\n clearCurrentSpace();\n this.authStateService\n .signOut()\n .catch(this.errorLogger.logErrorHandler('Failed to sign out for re-login'));\n }\n\n protected async loginWith(provider: AuthProviderID) {\n this.signingWith.set(provider);\n try {\n await this.authStateService.signInWith(provider);\n // We do not reset this.signingWith in case of succesful sign in as we should redirect from login page\n // and not to allow user to do a double sign-in.\n } catch (e) {\n const errMsg = (e as { errorMessage?: string }).errorMessage;\n if (\n errMsg !== 'The user canceled the sign-in flow.' &&\n !errMsg?.includes(\n 'com.apple.AuthenticationServices.AuthorizationError error 1001.',\n )\n ) {\n this.errorLogger.logError(e, `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) {\n return;\n }\n if (userCredential.user.email) {\n const prevEmail = localStorage.getItem('emailForSignIn') || '';\n if (!prevEmail) {\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 private errorHandler(\n m: string,\n eventName?: string,\n eventParams?: Record<string, string>,\n ): (err: unknown) => void {\n return (err) => this.handleError(err, m, eventName, eventParams);\n }\n\n private handleError(\n err: unknown,\n m: string,\n eventName?: string,\n eventParams?: Record<string, string>,\n ): void {\n if (eventName) {\n this.analyticsService.logEvent(eventName, eventParams);\n }\n this.errorLogger.logError(err, m, {\n report: !(err as { code: unknown }).code,\n });\n this.signingWith.set(undefined);\n }\n}\n","<ion-header>\n <ion-toolbar color=\"light\">\n <ion-buttons slot=\"start\">\n <ion-back-button />\n </ion-buttons>\n <ion-title>Login &#64; {{ appTitle }}</ion-title>\n </ion-toolbar>\n</ion-header>\n\n<ion-content id=\"main-content\">\n @if (reason) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <h2 class=\"reason-title\">{{ reason }}</h2>\n @if (reasonDetail) {\n <p class=\"reason-detail\">{{ reasonDetail }}</p>\n }\n </ion-card-content>\n </ion-card>\n } @else if (to) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <p>Please sign in to join a team</p>\n </ion-card-content>\n </ion-card>\n }\n\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">\n Sign in with your Sneat account.\n </ion-text>\n </p>\n\n @if (isAuthenticating()) {\n <ion-card>\n <ion-card-content class=\"ion-text-center ion-padding\">\n <ion-spinner name=\"lines\" />\n <p class=\"ion-no-margin ion-padding-top\">Signing you in…</p>\n </ion-card-content>\n </ion-card>\n } @else if (isAuthenticated()) {\n <ion-card color=\"success\">\n <ion-card-content>\n <p>\n @if (signedInAs()) {\n You are already signed in as <strong>{{ signedInAs() }}</strong>.\n } @else {\n You are already signed in.\n }\n </p>\n <ion-button expand=\"block\" (click)=\"continueToApp()\">Continue</ion-button>\n <ion-button\n expand=\"block\"\n fill=\"outline\"\n color=\"medium\"\n (click)=\"reLogin()\"\n >\n Re-login as someone else\n </ion-button>\n </ion-card-content>\n </ion-card>\n } @else {\n <sneat-email-login-form\n (signingWithChange)=\"onEmailFormStatusChanged($event)\"\n (loggedIn)=\"onLoggedIn($event)\"\n />\n\n <div class=\"ion-padding-horizontal ion-text-center\">\n <ion-button fill=\"outline\" expand=\"block\" routerLink=\"/sso\">\n <ion-icon name=\"business-outline\" slot=\"start\" />\n Sign in with company SSO\n </ion-button>\n </div>\n\n <ion-card>\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 <ion-grid class=\"ion-grid-layout\">\n @if (!isNativePlatform) {\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 <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 color=\"danger\" name=\"logo-google\" slot=\"start\" />\n }\n <ion-label color=\"danger\"> Login with Google</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\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\n <ion-label color=\"dark\"> Login with Apple</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n </ion-row>\n <ion-row>\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 slot=\"start\" color=\"secondary\" name=\"logo-windows\" />\n }\n <ion-label color=\"secondary\">Login with Microsoft</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\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 slot=\"start\" color=\"primary\" name=\"lines-small\" />\n } @else {\n <ion-icon slot=\"start\" color=\"primary\" name=\"logo-facebook\" />\n }\n <ion-label color=\"primary\">Login with Facebook</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n </ion-row>\n <ion-row>\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 slot=\"start\" color=\"tertiary\" name=\"lines-small\" />\n } @else {\n <ion-icon slot=\"start\" color=\"tertiary\" name=\"logo-github\" />\n }\n <ion-label color=\"tertiary\">Login with GitHub</ion-label>\n </ion-item>\n </ion-list>\n </ion-col>\n </ion-row>\n </ion-grid>\n </ion-card>\n }\n\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">\n If any issues get\n <a href=\"mailto:help@sneat.app?subject=Problem+with+login+at+Sneat.app\"\n >help&#64;sneat.app</a\n >\n </ion-text>\n </p>\n</ion-content>\n"]}
1
+ {"version":3,"file":"login-page.component.js","sourceRoot":"","sources":["../../../../../../../../libs/auth/ui/src/lib/pages/login-page/login-page.component.ts","../../../../../../../../libs/auth/ui/src/lib/pages/login-page/login-page.component.html"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,aAAa,EACb,aAAa,EACb,SAAS,EACT,UAAU,EACV,OAAO,EACP,cAAc,EACd,UAAU,EACV,SAAS,EACT,UAAU,EACV,OAAO,EACP,QAAQ,EACR,UAAU,GACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAGhB,gBAAgB,EAChB,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;;AA8B7D,MAAM,OAAO,kBAAmB,SAAQ,kBAAkB;IAwDxD;QACE,KAAK,EAAE,CAAC;QAxDO,qBAAgB,GAC/B,MAAM,CAAoB,gBAAgB,CAAC,CAAC;QAC7B,UAAK,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QAC/B,kBAAa,GAA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UAAU;;2FAWD,kBAAkB;kBA1B9B,SAAS;+BACE,aAAa,WAEd;wBACP,kBAAkB;wBAClB,SAAS;wBACT,UAAU;wBACV,SAAS;wBACT,UAAU;wBACV,aAAa;wBACb,QAAQ;wBACR,UAAU;wBACV,cAAc;wBACd,OAAO;wBACP,OAAO;wBACP,UAAU;qBACX,mBACgB,uBAAuB,CAAC,MAAM,aACpC;wBACT;4BACE,OAAO,EAAE,SAAS;4BAClB,QAAQ,EAAE,oBAAoB;yBAC/B;wBACD,eAAe;qBAChB","sourcesContent":["import { Component, computed, inject, ChangeDetectionStrategy } from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { ActivatedRoute } from '@angular/router';\nimport {\n NavController,\n IonBackButton,\n IonButton,\n IonButtons,\n IonCard,\n IonCardContent,\n IonContent,\n IonHeader,\n IonSpinner,\n IonText,\n IonTitle,\n IonToolbar,\n} from '@ionic/angular';\nimport {\n ILoginEventsHandler,\n LoginEventsHandler,\n SneatAuthStateService,\n SneatUserService,\n isSneatAccountReady,\n} from '@sneat/auth-core';\nimport {\n AnalyticsService,\n APP_INFO,\n clearCurrentSpace,\n currentSpacePath,\n IAnalyticsService,\n IAppInfo,\n readCurrentSpace,\n SpaceTypeFamily,\n} from '@sneat/core';\nimport { RandomIdService } from '@sneat/random';\nimport { ClassName, SneatBaseComponent } from '@sneat/ui';\nimport { combineLatest, Subject, takeUntil } from 'rxjs';\nimport { AuthPanelComponent } from './auth-panel.component';\nimport { safeAuthReturnPath } from './safe-auth-return-path';\n\ntype Action = 'join' | 'refuse'; // TODO: inject provider for action descriptions/messages.\n\n@Component({\n selector: 'sneat-login',\n templateUrl: './login-page.component.html',\n imports: [\n AuthPanelComponent,\n IonHeader,\n IonToolbar,\n IonButton,\n IonButtons,\n IonBackButton,\n IonTitle,\n IonContent,\n IonCardContent,\n IonText,\n IonCard,\n IonSpinner,\n ],\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [\n {\n provide: ClassName,\n useValue: 'LoginPageComponent',\n },\n RandomIdService,\n ],\n})\nexport class LoginPageComponent extends SneatBaseComponent {\n private readonly analyticsService =\n inject<IAnalyticsService>(AnalyticsService);\n private readonly route = inject(ActivatedRoute);\n private readonly navController = inject(NavController);\n private readonly userService = inject(SneatUserService);\n private readonly authStateService = inject(SneatAuthStateService);\n private appInfo = inject<IAppInfo>(APP_INFO);\n private readonly loginEventsHandler = inject<ILoginEventsHandler>(\n LoginEventsHandler,\n { optional: true },\n );\n\n protected readonly redirectTo?: string;\n protected readonly to?: string;\n // Free-text explanation of WHY sign-in is needed, passed by the calling page\n // as query params (rendered as escaped text — never as HTML):\n // reason — short heading, e.g. \"Sign in to create a new game\"\n // reasonDetail — optional sub-heading / one-line elaboration\n protected readonly reason?: string;\n protected readonly reasonDetail?: string;\n protected readonly action?: Action; // TODO: document possible values?\n\n protected readonly appTitle: string;\n\n // Surfaces the Firebase auth state on the login page itself: if the user is\n // already signed in (e.g. the app failed to navigate them onward) we show a\n // \"you are already signed in as X\" panel instead of the sign-in form, so an\n // authenticated-but-stuck state is obvious rather than looking like sign-in\n // is broken.\n protected readonly isAuthenticated = computed(\n () =>\n this.authState()?.status === 'authenticated' &&\n !!this.authState()?.user?.uid &&\n !this.authState()?.user?.isAnonymous,\n );\n // While Firebase is still resolving the session — the initial state, and the\n // brief window right after a signInWithRedirect return — show a \"signing you\n // in\" spinner instead of flashing the sign-in form before we navigate onward.\n protected readonly isAuthenticating = computed(\n () =>\n this.authState()?.status === 'authenticating' &&\n this.authState()?.loadingPhase !== 'failed',\n );\n private readonly authState = toSignal(this.authStateService.authState);\n private readonly userState = toSignal(this.userService.userState);\n protected readonly isAccountReady = computed(() => {\n const userState = this.userState();\n const authState = this.authState();\n return isSneatAccountReady(authState, userState);\n });\n protected readonly signedInAs = computed(() => {\n const u = this.authState()?.user;\n return u?.displayName || u?.email || u?.uid || '';\n });\n\n constructor() {\n super();\n const appInfo = this.appInfo;\n this.appTitle = appInfo.appTitle || 'Sneat.app';\n if (location.hash.startsWith('#/')) {\n this.redirectTo = safeAuthReturnPath(location.hash.substring(1));\n }\n this.to = this.route.snapshot.queryParams['to']; // should we subscribe? I believe no.\n this.reason = this.route.snapshot.queryParams['reason'];\n this.reasonDetail = this.route.snapshot.queryParams['reasonDetail'];\n const action = location.hash.match(/[#&]action=(\\w+)/);\n this.action = action?.[1] as Action;\n\n const userRecordLoaded = new Subject<void>();\n combineLatest([this.authStateService.authState, this.userService.userState])\n .pipe(takeUntil(userRecordLoaded), this.takeUntilDestroyed())\n .subscribe({\n next: ([authState, userState]) => {\n const userRecord = userState.record;\n if (!userRecord || !isSneatAccountReady(authState, userState)) return;\n userRecordLoaded.next();\n // Fall back to the persisted current space so it is restored after login,\n // but only if the user actually has access to it.\n const space = readCurrentSpace();\n const hasAccess = !!space && (\n userRecord.spaceIDs?.includes(space.id) ||\n (!!userRecord.spaces && space.id in userRecord.spaces)\n );\n if (space && !hasAccess) {\n clearCurrentSpace();\n }\n const activePath = hasAccess ? currentSpacePath() : undefined;\n const family = Object.entries(userRecord.spaces || {}).find(\n ([, brief]) => brief.type === SpaceTypeFamily,\n );\n const familyPath = family\n ? `/space/${SpaceTypeFamily}/${family[0]}`\n : undefined;\n const redirectTo = this.redirectTo || activePath || familyPath || '/';\n this.navController\n .navigateRoot(redirectTo)\n .catch((err) => {\n this.errorLogger.logError(\n err,\n 'Failed to navigate back to ' + redirectTo,\n );\n });\n },\n error: this.errorHandler('Failed to get user state after login'),\n });\n }\n\n // Proceed into the app from the \"already signed in\" panel.\n protected continueToApp(): void {\n if (!this.isAccountReady()) return;\n const space = readCurrentSpace();\n const userState = this.userState();\n const hasAccess = !!space && !!userState?.record && (\n userState.record.spaceIDs?.includes(space.id) ||\n (!!userState.record.spaces && space.id in userState.record.spaces)\n );\n if (space && !hasAccess) {\n clearCurrentSpace();\n }\n const activePath = hasAccess ? currentSpacePath() : undefined;\n const family = Object.entries(userState?.record?.spaces || {}).find(\n ([, brief]) => brief.type === SpaceTypeFamily,\n );\n const familyPath = family\n ? `/space/${SpaceTypeFamily}/${family[0]}`\n : undefined;\n const redirectTo = this.redirectTo || activePath || familyPath || '/';\n this.navController\n .navigateRoot(redirectTo)\n .catch((err) => {\n this.errorLogger.logError(\n err,\n 'Failed to navigate to ' + redirectTo,\n );\n });\n }\n\n // Sign out so the sign-in form is shown again (e.g. to log in as someone else).\n protected reLogin(): void {\n clearCurrentSpace();\n this.authStateService\n .signOut()\n .catch(this.errorLogger.logErrorHandler('Failed to sign out for re-login'));\n }\n\n private errorHandler(\n m: string,\n eventName?: string,\n eventParams?: Record<string, string>,\n ): (err: unknown) => void {\n return (err) => this.handleError(err, m, eventName, eventParams);\n }\n\n private handleError(\n err: unknown,\n m: string,\n eventName?: string,\n eventParams?: Record<string, string>,\n ): void {\n if (eventName) {\n this.analyticsService.logEvent(eventName, eventParams);\n }\n this.errorLogger.logError(err, m, {\n report: !(err as { code: unknown }).code,\n });\n }\n}\n","<ion-header>\n <ion-toolbar color=\"light\">\n <ion-buttons slot=\"start\">\n <ion-back-button />\n </ion-buttons>\n <ion-title>Login &#64; {{ appTitle }}</ion-title>\n </ion-toolbar>\n</ion-header>\n\n<ion-content id=\"main-content\">\n @if (reason) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <h2 class=\"reason-title\">{{ reason }}</h2>\n @if (reasonDetail) {\n <p class=\"reason-detail\">{{ reasonDetail }}</p>\n }\n </ion-card-content>\n </ion-card>\n } @else if (to) {\n <ion-card color=\"tertiary\">\n <ion-card-content>\n <p>Please sign in to join a team</p>\n </ion-card-content>\n </ion-card>\n }\n\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 @if (isAuthenticating()) {\n <ion-card>\n <ion-card-content class=\"ion-text-center ion-padding\">\n <ion-spinner name=\"lines\" />\n <p class=\"ion-no-margin ion-padding-top\">Signing you in…</p>\n </ion-card-content>\n </ion-card>\n } @else if (isAuthenticated()) {\n <ion-card color=\"success\">\n <ion-card-content>\n <p>\n @if (signedInAs()) {\n You are already signed in as <strong>{{ signedInAs() }}</strong>.\n } @else {\n You are already signed in.\n }\n </p>\n @if (isAccountReady()) {\n <ion-button expand=\"block\" (click)=\"continueToApp()\">Continue</ion-button>\n } @else {\n <sneat-auth-panel\n [returnTo]=\"redirectTo\"\n [showIntro]=\"false\"\n [showCredentials]=\"false\"\n />\n }\n <ion-button\n expand=\"block\"\n fill=\"outline\"\n color=\"medium\"\n (click)=\"reLogin()\"\n >\n Re-login as someone else\n </ion-button>\n </ion-card-content>\n </ion-card>\n } @else {\n <sneat-auth-panel [returnTo]=\"redirectTo\" [showIntro]=\"false\" />\n }\n\n <p style=\"text-align: center; font-size: smaller\">\n <ion-text color=\"medium\">\n If any issues get\n <a href=\"mailto:help@sneat.app?subject=Problem+with+login+at+Sneat.app\"\n >help&#64;sneat.app</a\n >\n </ion-text>\n </p>\n</ion-content>\n"]}
@@ -1,11 +1,11 @@
1
1
  import { DOCUMENT } from '@angular/common';
2
2
  import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, inject, input, signal, } from '@angular/core';
3
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
3
4
  import { ErrorLogger } from '@sneat/core';
4
5
  import { SneatAuthWithTelegramService, } from './sneat-auth-with-telegram.service';
5
6
  import { TelegramLoginConfig, resolveTelegramBotID, } from './telegram-login-config';
6
7
  import { loadTelegramLoginScript, telegramLoginApi, } from './telegram-login-js';
7
8
  import * as i0 from "@angular/core";
8
- let authWithTelegramService;
9
9
  /** Server nonces live 10 minutes; refresh well inside that. */
10
10
  const OIDC_NONCE_REFRESH_MS = 8 * 60 * 1000;
11
11
  /**
@@ -14,7 +14,6 @@ const OIDC_NONCE_REFRESH_MS = 8 * 60 * 1000;
14
14
  * Widget (telegram-widget.js), e.g. the local dev bot.
15
15
  */
16
16
  export class LoginWithTelegramComponent {
17
- // TODO: Article about Telegram login
18
17
  constructor() {
19
18
  this.el = inject(ElementRef);
20
19
  this.document = inject(DOCUMENT);
@@ -37,21 +36,31 @@ export class LoginWithTelegramComponent {
37
36
  /** Set once the OpenID popup can be offered: Client ID plus a live nonce. */
38
37
  this.oidc = signal(undefined, /* @ts-ignore */
39
38
  ...(ngDevMode ? [{ debugName: "oidc" }] : /* istanbul ignore next */ []));
40
- const authWithTelegram = this.authWithTelegram;
41
- authWithTelegramService = authWithTelegram;
39
+ // Register while the view is alive, never from a late loader continuation.
40
+ this.destroyRef.onDestroy(() => {
41
+ clearInterval(this.nonceTimer);
42
+ const host = this.document.defaultView;
43
+ if (host && host.onTelegramAuth === this.legacyCallback)
44
+ delete host.onTelegramAuth;
45
+ });
42
46
  }
43
47
  ngOnInit() {
44
48
  const botID = this.botID();
45
49
  if (!botID) {
46
50
  return;
47
51
  }
48
- this.authWithTelegram.getTelegramOIDCNonce(botID).subscribe({
52
+ this.authWithTelegram
53
+ .getTelegramOIDCNonce(botID)
54
+ .pipe(takeUntilDestroyed(this.destroyRef))
55
+ .subscribe({
49
56
  next: (cfg) => this.startOIDC(botID, cfg),
50
57
  // The server answers 400 for a bot without OpenID login configured.
51
58
  error: () => this.startLegacyWidget(botID),
52
59
  });
53
60
  }
54
61
  loginWithOIDC(cfg) {
62
+ if (this.destroyRef.destroyed)
63
+ return;
55
64
  const api = telegramLoginApi(this.document.defaultView ?? window);
56
65
  if (!api) {
57
66
  this.errorLogger.logErrorHandler('Telegram login library not loaded')(new Error('window.Telegram.Login is undefined'));
@@ -65,7 +74,7 @@ export class LoginWithTelegramComponent {
65
74
  nonce: cfg.nonce,
66
75
  request_access: this.requestAccess() === 'write' ? ['write'] : [],
67
76
  }, (result) => {
68
- if (result.id_token) {
77
+ if (result.id_token && !this.destroyRef.destroyed) {
69
78
  this.authWithTelegram.loginWithTelegramOIDC(botID, result.id_token, this.isUserAuthenticated());
70
79
  this.refreshNonce(botID);
71
80
  }
@@ -75,27 +84,38 @@ export class LoginWithTelegramComponent {
75
84
  }
76
85
  startOIDC(botID, cfg) {
77
86
  loadTelegramLoginScript(this.document).then(() => {
87
+ if (this.destroyRef.destroyed)
88
+ return;
78
89
  this.oidc.set(cfg);
79
- const timer = setInterval(() => this.refreshNonce(botID), OIDC_NONCE_REFRESH_MS);
80
- this.destroyRef.onDestroy(() => clearInterval(timer));
90
+ clearInterval(this.nonceTimer);
91
+ this.nonceTimer = setInterval(() => this.refreshNonce(botID), OIDC_NONCE_REFRESH_MS);
81
92
  }, this.errorLogger.logErrorHandler('Failed to load Telegram login library'));
82
93
  }
83
94
  refreshNonce(botID) {
84
- this.authWithTelegram.getTelegramOIDCNonce(botID).subscribe({
95
+ this.authWithTelegram
96
+ .getTelegramOIDCNonce(botID)
97
+ .pipe(takeUntilDestroyed(this.destroyRef))
98
+ .subscribe({
85
99
  next: (cfg) => this.oidc.set(cfg),
86
100
  error: this.errorLogger.logErrorHandler('Failed to refresh Telegram login nonce'),
87
101
  });
88
102
  }
89
103
  startLegacyWidget(botID) {
90
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
91
- // @ts-ignore
92
- window.onTelegramAuth = (tgAuthData) => {
104
+ if (this.destroyRef.destroyed)
105
+ return;
106
+ this.legacyCallback = (tgAuthData) => {
107
+ if (this.destroyRef.destroyed)
108
+ return;
93
109
  // https://core.telegram.org/widgets/login-legacy
94
110
  // After a successful authorization, the widget returns data
95
111
  // by calling the callback function data-onauth with the JSON-object containing
96
112
  // id, first_name, last_name, username, photo_url, auth_date and hash fields.
97
- authWithTelegramService.loginWithTelegram(botID, tgAuthData, this.isUserAuthenticated());
113
+ this.authWithTelegram.loginWithTelegram(botID, tgAuthData, this.isUserAuthenticated());
98
114
  };
115
+ const host = this.document.defaultView;
116
+ if (!host)
117
+ return;
118
+ host.onTelegramAuth = this.legacyCallback;
99
119
  const script = this.document.createElement('script');
100
120
  script.src = 'https://telegram.org/js/telegram-widget.js?22';
101
121
  script.setAttribute('data-telegram-login', botID);
@@ -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,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,IAAI,uBAAqD,CAAC;AAE1D,+DAA+D;AAC/D,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE5C;;;;GAIG;AAwCH,MAAM,OAAO,0BAA0B;IAUrC,qCAAqC;IACrC;QAViB,OAAE,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACxB,aAAQ,GAAG,MAAM,CAAW,QAAQ,CAAC,CAAC;QACtC,eAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QAChC,gBAAW,GAAG,MAAM,CAAe,WAAW,CAAC,CAAC;QACxD,qBAAgB,GAAG,MAAM,CAAC,4BAA4B,CAAC,CAAC;QAChD,wBAAmB,GAAG,MAAM,CAAC,mBAAmB,EAAE;YACjE,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QASa,wBAAmB,GAAG,KAAK,CAAC,KAAK;gGAAC,CAAC;QAEnC,UAAK,GAAG,KAAK,CAAS,oBAAoB,CAAC,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,QAAQ,CAAC;kFAAC,CAAC;QAEzF,SAAI,GAAG,KAAK,CAA+B,OAAO;iFAAC,CAAC;QACpD,kBAAa,GA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,UAA6B,EAAE,EAAE;YACxD,iDAAiD;YACjD,4DAA4D;YAC5D,+EAA+E;YAC/E,6EAA6E;YAC7E,uBAAuB,CAAC,iBAAiB,CACvC,KAAK,EACL,UAAU,EACV,IAAI,CAAC,mBAAmB,EAAE,CAC3B,CAAC;QACJ,CAAC,CAAC;QAEF,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;8GAtHU,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 { 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\nlet authWithTelegramService: SneatAuthWithTelegramService;\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 // TODO: Article about Telegram login\n constructor() {\n const authWithTelegram = this.authWithTelegram;\n\n authWithTelegramService = authWithTelegram;\n }\n\n public readonly isUserAuthenticated = input(false);\n\n public readonly botID = input<string>(resolveTelegramBotID(this.telegramLoginConfig, location.hostname));\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.getTelegramOIDCNonce(botID).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 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) {\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 this.oidc.set(cfg);\n const timer = setInterval(\n () => this.refreshNonce(botID),\n OIDC_NONCE_REFRESH_MS,\n );\n this.destroyRef.onDestroy(() => clearInterval(timer));\n }, this.errorLogger.logErrorHandler('Failed to load Telegram login library'));\n }\n\n private refreshNonce(botID: string): void {\n this.authWithTelegram.getTelegramOIDCNonce(botID).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 // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n window.onTelegramAuth = (tgAuthData: ITelegramAuthData) => {\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 authWithTelegramService.loginWithTelegram(\n botID,\n tgAuthData,\n this.isUserAuthenticated(),\n );\n };\n\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,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,0BAA0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,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"]}