@frontegg/ionic-capacitor 0.0.5 → 1.0.0-alpha.0

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.
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
14
  s.ios.deployment_target = '14.0'
15
15
  s.dependency 'Capacitor'
16
- s.dependency "FronteggSwift", "1.0.5"
16
+ s.dependency "FronteggSwift", "1.1.0"
17
17
  s.swift_version = '5.1'
18
18
  s.pod_target_xcconfig = {
19
19
  'CODE_SIGNING_ALLOWED' => 'YES'
package/README.md CHANGED
@@ -1,42 +1,45 @@
1
1
  # @frontegg/ionic-capacitor
2
2
 
3
- Frontegg is a first-of-its-kind full-stack user management platform, empowering software teams with user infrastructure features for the product-led era.
4
-
3
+ Frontegg is a first-of-its-kind full-stack user management platform, empowering software teams with user infrastructure
4
+ features for the product-led era.
5
5
 
6
6
  ## Table of Contents
7
7
 
8
8
  - [Project Requirements](#project-requirements)
9
9
  - [Getting Started](#getting-started)
10
- - [Prepare Frontegg workspace](#prepare-frontegg-workspace)
11
- - [Setup Hosted Login](#setup-hosted-login)
12
- - [Add frontegg package to the project](#add-frontegg-package-to-the-project)
13
- - [Configure your application](#configure-your-application)
10
+ - [Prepare Frontegg workspace](#prepare-frontegg-workspace)
11
+ - [Setup Hosted Login](#setup-hosted-login)
12
+ - [Add frontegg package to the project](#add-frontegg-package-to-the-project)
13
+ - [Configure your application](#configure-your-application)
14
14
  - [Setup iOS Project](#setup-ios-project)
15
- - [Create Frontegg plist file](#create-frontegg-plist-file)
16
- - [Config iOS associated domain](#config-ios-associated-domain)
15
+ - [Create Frontegg plist file](#create-frontegg-plist-file)
16
+ - [Config iOS associated domain](#config-ios-associated-domain)
17
17
  - [Setup Android Project](#setup-android-project)
18
- - [Set minimum SDK version](#set-minimum-sdk-version)
19
- - [Configure build config fields](#configure-build-config-fields)
20
- - [Config Android AssetLinks](#config-ios-associated-domain)
21
- - [Usages](#usages)
22
- - [Ionic with Angular](#ionic-with-angular)
23
- - [Login with frontegg](#login-with-frontegg)
24
- - [Check if user is authenticated](#check-if-user-is-authenticated)
25
-
18
+ - [Set minimum SDK version](#set-minimum-sdk-version)
19
+ - [Configure build config fields](#configure-build-config-fields)
20
+ - [Config Android AssetLinks](#config-ios-associated-domain)
21
+ - [Angular Usages](#angular-usages)
22
+ - [Integrate Frontegg](#integrate-frontegg)
23
+ - [Protect Routes](#protect-routes)
24
+ - [Get Logged In User](#get-logged-in-user)
25
+ - [Switch Tenant](#switch-tenant)
26
+ - [Embedded Webview vs Hosted](#embedded-webview-vs-hosted)
27
+ - [Enable hosted webview in iOS Platform](#enable-hosted-webview-in-ios-platform)
28
+ - [Enable hosted webview in Android Platform](#enable-hosted-webview-in-android-platform)
26
29
 
27
30
  ## Project Requirements
28
31
 
29
32
  - Minimum iOS deployment version **=> 14**
30
33
  - Min Android SDK **=> 26**
31
34
 
32
-
33
35
  ## Getting Started
34
36
 
35
37
  ### Prepare Frontegg workspace
36
38
 
37
39
  Navigate to [Frontegg Portal Settings](https://portal.frontegg.com/development/settings), If you don't have application
38
40
  follow integration steps after signing up.
39
- Copy FronteggDomain to future steps from [Frontegg Portal Domain](https://portal.frontegg.com/development/settings/domains)
41
+ Copy FronteggDomain to future steps
42
+ from [Frontegg Portal Domain](https://portal.frontegg.com/development/settings/domains)
40
43
 
41
44
  ### Setup Hosted Login
42
45
 
@@ -47,7 +50,7 @@ Copy FronteggDomain to future steps from [Frontegg Portal Domain](https://portal
47
50
  - Replace `IOS_BUNDLE_IDENTIFIER` with your application identifier
48
51
  - Replace `FRONTEGG_BASE_URL` with your frontegg base url
49
52
  - Replace `ANDROID_PACKAGE_NAME` with your android package name
50
- -
53
+ -
51
54
 
52
55
  ### Add frontegg package to the project
53
56
 
@@ -60,11 +63,13 @@ ionic integrations enable capacitor
60
63
  Use a package manager npm/yarn to install frontegg React Native library.
61
64
 
62
65
  **NPM:**
66
+
63
67
  ```bash
64
68
  npm install -s @frontegg/react-native
65
69
  ```
66
70
 
67
71
  **Yarn:**
72
+
68
73
  ```bash
69
74
  yarn add @frontegg/react-native
70
75
  ```
@@ -93,17 +98,16 @@ yarn add @frontegg/react-native
93
98
 
94
99
  export default config;
95
100
  ```
96
-
101
+
97
102
  2. Add the iOS and Android projects to your ionic app by running the following commands:
98
103
 
99
- **NOTE: skip the command if you already have the project added.**
104
+ **NOTE: skip the command if you already have the project added.**
100
105
 
101
106
  ```bash
102
107
  ionic capacitor add android
103
108
  ionic capacitor add ios
104
109
  ```
105
110
 
106
-
107
111
  ## Setup iOS Project
108
112
 
109
113
  ### Create Frontegg plist file
@@ -115,7 +119,8 @@ To setup your SwiftUI application to communicate with Frontegg.
115
119
  ionic capacitor open ios
116
120
  ```
117
121
  or open the Xcode manually.
118
- 2. Create a new file named `Frontegg.plist` under your root project directory, this file will store values to be used variables by Frontegg SDK:
122
+ 2. Create a new file named `Frontegg.plist` under your root project directory, this file will store values to be used
123
+ variables by Frontegg SDK:
119
124
 
120
125
  ```xml
121
126
  <?xml version="1.0" encoding="UTF-8"?>
@@ -132,19 +137,66 @@ To setup your SwiftUI application to communicate with Frontegg.
132
137
 
133
138
  3. Enable `CODE_SIGNING_ALLOWED` in the Podfile under `/ios/App` folder.
134
139
 
140
+ ### Handle Open App with URL
141
+
142
+ To handle Login with magic link and other authentication methods that require to open the app with a URL, you have to
143
+ add the following code to the `AppDelegate.swift` file.
144
+
145
+ ```swift
146
+
147
+ import UIKit
148
+ import Capacitor
149
+ import FronteggSwift
150
+
151
+ @UIApplicationMain
152
+ class AppDelegate: UIResponder, UIApplicationDelegate {
153
+
154
+ /*
155
+ * Called when the app was launched with a url. Feel free to add additional processing here,
156
+ * but if you want the App API to support tracking app url opens, make sure to keep this call
157
+ */
158
+ func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
159
+
160
+ if(FronteggAuth.shared.handleOpenUrl(url)){
161
+ return true
162
+ }
163
+
164
+ return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
165
+ }
166
+
167
+ /*
168
+ * Called when the app was launched with an activity, including Universal Links.
169
+ * Feel free to add additional processing here, but if you want the App API to support
170
+ * tracking app url opens, make sure to keep this call
171
+ */
172
+ func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
173
+
174
+ if let url = userActivity.webpageURL {
175
+ if(FronteggAuth.shared.handleOpenUrl(url)){
176
+ return true
177
+ }
178
+ }
179
+ return ApplicationDelegateProxy.shared.application(application, continue: userActivity, restorationHandler: restorationHandler)
180
+ }
181
+ }
182
+ ```
183
+
135
184
  ### Config iOS associated domain
136
185
 
137
186
  Configuring your iOS associated domain is required for Magic Link authentication / Reset Password / Activate Account.
138
187
 
139
- In order to add your iOS associated domain to your Frontegg application, you will need to update in each of your integrated Frontegg Environments the iOS associated domain that you would like to use with that Environment. Send a POST request to `https://api.frontegg.com/vendors/resources/associated-domains/v1/ios` with the following payload:
188
+ In order to add your iOS associated domain to your Frontegg application, you will need to update in each of your
189
+ integrated Frontegg Environments the iOS associated domain that you would like to use with that Environment. Send a POST
190
+ request to `https://api.frontegg.com/vendors/resources/associated-domains/v1/ios` with the following payload:
191
+
140
192
  ```
141
193
  {
142
194
  “appId”:[YOUR_ASSOCIATED_DOMAIN]
143
195
  }
144
196
  ```
145
- In order to use our API’s, follow [this guide](‘https://docs.frontegg.com/reference/getting-started-with-your-api’) to generate a vendor token.
146
-
147
197
 
198
+ In order to use our API’s, follow [this guide](‘https://docs.frontegg.com/reference/getting-started-with-your-api’) to
199
+ generate a vendor token.
148
200
 
149
201
  ### Setup Android Project
150
202
 
@@ -155,6 +207,7 @@ In order to use our API’s, follow [this guide](‘https://docs.frontegg.com/re
155
207
  To set up your Android minimum sdk version, open root gradle file at`android/variables.gradle`,
156
208
 
157
209
  Modify the minSdkVersion to 26:
210
+
158
211
  ```groovy
159
212
  ext {
160
213
  minSdkVersion = 26
@@ -164,7 +217,8 @@ ext {
164
217
 
165
218
  ### Configure build config fields
166
219
 
167
- To set up your Android application on to communicate with Frontegg, you have to add `buildConfigField` property the gradle `android/app/build.gradle`.
220
+ To set up your Android application on to communicate with Frontegg, you have to add `buildConfigField` property the
221
+ gradle `android/app/build.gradle`.
168
222
  This property will store frontegg hostname (without https) and client id from previous step:
169
223
 
170
224
  ```groovy
@@ -199,7 +253,6 @@ android {
199
253
  }
200
254
  ```
201
255
 
202
-
203
256
  ### Add permissions to AndroidManifest.xml
204
257
 
205
258
  Add `INTERNET` permission to the app's manifest file.
@@ -207,10 +260,9 @@ Add `INTERNET` permission to the app's manifest file.
207
260
  ```xml
208
261
 
209
262
  <uses-permission android:name="android.permission.INTERNET"/>
210
- <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
263
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
211
264
  ```
212
265
 
213
-
214
266
  ### Config Android AssetLinks
215
267
 
216
268
  Configuring your Android `AssetLinks` is required for Magic Link authentication / Reset Password / Activate Account /
@@ -261,23 +313,243 @@ keytool -list -v -keystore /PATH/file.jks -alias YourAlias -storepass *** -keypa
261
313
  In order to use our API’s, follow [this guide](https://docs.frontegg.com/reference/getting-started-with-your-api) to
262
314
  generate a vendor token.
263
315
 
316
+ ## Angular Usages
264
317
 
318
+ ### Integrate Frontegg:
265
319
 
266
- ## Usages
320
+ Open the `src/app/app.module.ts` file and add the following line to the before `@NgModule` section:
267
321
 
268
- ### Ionic with Angular:
322
+ ```typescript
323
+ import { FronteggService } from '@frontegg/ionic-capacitor';
269
324
 
270
- 1. Open the `src/app/app.module.ts` file and add the following line to the before `@NgModule` section:
271
- ```typescript
272
- import { FronteggService } from '@frontegg/ionic-capacitor';
273
-
274
- @NgModule({
275
- // ...
276
- providers: [ {
277
- provide: 'Frontegg',
278
- useValue: new FronteggService(),
279
- }]
280
- // ...
281
- })
282
- ```
283
- 2. Find full example under `example/src/app/tab1` and `example/src/app/tab2` files.
325
+ @NgModule({
326
+ // ...
327
+ providers: [ {
328
+ provide: 'Frontegg',
329
+ useValue: new FronteggService(),
330
+ } ]
331
+ // ...
332
+ })
333
+ ```
334
+
335
+ ### Protect Routes:
336
+
337
+ 1. Create AuthGuard file `src/app/auth.guard.ts`:
338
+
339
+ ```typescript
340
+ import { CanActivateFn } from '@angular/router';
341
+ import { Inject, Injectable } from '@angular/core';
342
+ import { FronteggService } from '@frontegg/ionic-capacitor';
343
+
344
+
345
+ @Injectable({
346
+ providedIn: 'root'
347
+ })
348
+ export class AuthGuard {
349
+
350
+ constructor(@Inject('Frontegg') private fronteggService: FronteggService) {
351
+
352
+ /**
353
+ * Listens to $isAuthenticated changes
354
+ * Reload the page to trigger canActivate function again
355
+ */
356
+ this.fronteggService.$isAuthenticated.subscribe(async () => {
357
+ window.location.reload()
358
+ });
359
+ }
360
+
361
+ /**
362
+ * Wait for loader to finish
363
+ * @private
364
+ */
365
+ private waitForLoader() {
366
+ return new Promise((resolve) => {
367
+ const unsubscribe = this.fronteggService.$isLoading
368
+ .subscribe((isLoading) => {
369
+ if (!isLoading) {
370
+ resolve(true);
371
+ unsubscribe();
372
+ }
373
+ });
374
+ })
375
+ }
376
+
377
+ /**
378
+ * Navigate to login page if user is not authenticated
379
+ * @private
380
+ */
381
+ private async navigateToLoginIfNeeded(): Promise<boolean> {
382
+ const { isAuthenticated } = this.fronteggService.getState();
383
+ if (!isAuthenticated) {
384
+ await this.fronteggService.login()
385
+ return false /** prevent navigation */
386
+ }
387
+ return true /** activate navigation */
388
+ }
389
+
390
+
391
+ canActivate: CanActivateFn = () => {
392
+ const { showLoader } = this.fronteggService.getState();
393
+
394
+ if (!showLoader) {
395
+ /**
396
+ * if showLoader false
397
+ * check if user is authenticated
398
+ */
399
+ return this.navigateToLoginIfNeeded()
400
+ }
401
+
402
+ /**
403
+ * if showLoader true
404
+ * wait for loader to finish and then
405
+ * check if user is authenticated
406
+ */
407
+ return new Promise<boolean>(async (resolve) => {
408
+ await this.waitForLoader()
409
+ const activated = await this.navigateToLoginIfNeeded()
410
+ resolve(activated)
411
+ })
412
+ }
413
+ }
414
+
415
+
416
+ ```
417
+
418
+ 2. Open the `src/app-routing.module.ts` file and add wrap the app routes with loadChildren and apply CanActivate guard:
419
+
420
+ ```typescript
421
+ import { AuthGuard } from './auth.gaurd';
422
+
423
+ const routes: Routes = [
424
+ {
425
+ path: '',
426
+ canActivate: [ AuthGuard ],
427
+ loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule)
428
+ },
429
+ ];
430
+ ```
431
+
432
+ ### Get Logged In User
433
+
434
+ Find full example under `example/src/app/tab1` files.
435
+
436
+ ```typescript
437
+ import { Inject } from '@angular/core';
438
+ import { FronteggService, FronteggState } from '@frontegg/ionic-capacitor';
439
+
440
+ @Component({
441
+ /** .... */
442
+ })
443
+ export class MyPage implements OnInit {
444
+
445
+ constructor(private ngZone: NgZone, @Inject('Frontegg') private fronteggService: FronteggService) {
446
+ }
447
+
448
+ user: FronteggState['user'] = null
449
+ accessToken: string | null = null
450
+
451
+ ngOnInit() {
452
+ const { user, accessToken } = this.fronteggService.getState();
453
+ this.user = user;
454
+ this.user = accessToken;
455
+
456
+ this.fronteggService.$user.subscribe((user) => {
457
+ console.log('change user', user)
458
+ this.ngZone.run(() => this.user = user)
459
+ })
460
+ this.fronteggService.$accessToken.subscribe((accessToken) => {
461
+ console.log('change accessToken', accessToken)
462
+ this.ngZone.run(() => this.accessToken = accessToken)
463
+ })
464
+ }
465
+ }
466
+ ```
467
+
468
+ ### Switch Tenant
469
+
470
+ Find full example under `example/src/app/tab2` files.
471
+
472
+ ```typescript
473
+ import { Inject } from '@angular/core';
474
+ import { FronteggService, FronteggState } from '@frontegg/ionic-capacitor';
475
+
476
+ @Component({
477
+ /** .... */
478
+ })
479
+ export class MyPage implements OnInit {
480
+
481
+ constructor(private ngZone: NgZone, @Inject('Frontegg') private fronteggService: FronteggService) {
482
+ }
483
+
484
+ user: FronteggState['user'] = null
485
+ accessToken: string | null = null
486
+
487
+ ngOnInit() {
488
+ const { user } = this.fronteggService.getState();
489
+ this.user = user;
490
+ this.fronteggService.$user.subscribe((user) => {
491
+ this.ngZone.run(() => this.user = user)
492
+ })
493
+ }
494
+
495
+
496
+ switchTenant(tenantId: string) {
497
+ this.fronteggService.switchTenant(tenantId)
498
+ }
499
+ }
500
+ ```
501
+
502
+ ## Embedded Webview vs Hosted
503
+
504
+ Frontegg SDK supports two authentication methods:
505
+
506
+ - Embedded Webview
507
+ - Hosted Webview
508
+ - `iOS`: ASWebAuthenticationSession
509
+ - `Android`: Custom Chrome Tab
510
+
511
+ By default, Frontegg SDK will use Embedded Webview.
512
+
513
+ ### Enable hosted webview in iOS Platform
514
+
515
+ To use ASWebAuthenticationSession you have to set `embeddedMode` to `NO` in `Frontegg.plist` file:
516
+
517
+ ```xml
518
+ <?xml version="1.0" encoding="UTF-8"?>
519
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN">
520
+ <plist version="1.0">
521
+ <dict>
522
+ <key>baseUrl</key>
523
+ <string>https://[DOMAIN_HOST_FROM_PREVIOUS_STEP]</string>
524
+ <key>clientId</key>
525
+ <string>[CLIENT_ID_FROM_PREVIOUS_STEP]</string>
526
+
527
+ <!-- START -->
528
+ <key>embeddedMode</key>
529
+ <true/>
530
+ <!-- END -->
531
+ </dict>
532
+ </plist>
533
+ ```
534
+
535
+ ### Enable hosted webview in Android Platform
536
+
537
+ to use Custom Chrome Tab you have to set disable embedded activity by adding below code to
538
+ the application manifest:
539
+
540
+ ```xml
541
+
542
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
543
+ xmlns:tools="http://schemas.android.com/tools">
544
+ <application>
545
+ <!-- ... -->
546
+
547
+ <activity android:name="com.frontegg.android.EmbeddedAuthActivity" tools:replace="android:enabled"
548
+ android:enabled="false"/>
549
+ <activity android:name="com.frontegg.android.HostedAuthActivity" tools:replace="android:enabled"
550
+ android:enabled="true"/>
551
+
552
+ <!-- ... -->
553
+ </application>
554
+ </manifest>
555
+ ```
@@ -55,7 +55,7 @@ dependencies {
55
55
  implementation "androidx.browser:browser:1.5.0"
56
56
  implementation 'io.reactivex.rxjava3:rxkotlin:3.0.1'
57
57
  implementation 'com.google.code.gson:gson:2.8.9'
58
- implementation 'com.frontegg.sdk:android:1.0.6'
58
+ implementation 'com.frontegg.sdk:android:1.1.2'
59
59
 
60
60
  testImplementation "junit:junit:$junitVersion"
61
61
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
@@ -1,6 +1,9 @@
1
1
  package com.frontegg.ionic;
2
2
 
3
3
 
4
+ import android.os.Handler;
5
+ import android.os.Looper;
6
+
4
7
  import com.frontegg.android.FronteggApp;
5
8
  import com.frontegg.android.FronteggAuth;
6
9
  import com.frontegg.android.models.User;
@@ -10,12 +13,12 @@ import com.getcapacitor.PluginCall;
10
13
  import com.getcapacitor.PluginMethod;
11
14
  import com.getcapacitor.annotation.CapacitorPlugin;
12
15
 
13
- import org.json.JSONObject;
14
-
15
16
  import java.lang.reflect.Field;
16
17
  import java.util.HashMap;
17
18
  import java.util.Map;
18
19
  import java.util.Objects;
20
+ import java.util.concurrent.ExecutorService;
21
+ import java.util.concurrent.Executors;
19
22
 
20
23
  import io.reactivex.rxjava3.core.Observable;
21
24
  import io.reactivex.rxjava3.disposables.Disposable;
@@ -111,6 +114,16 @@ public class FronteggNativePlugin extends Plugin {
111
114
  });
112
115
  }
113
116
 
117
+ @PluginMethod
118
+ public void refreshToken(PluginCall call) {
119
+ ExecutorService executor = Executors.newSingleThreadExecutor();
120
+ executor.submit(() -> {
121
+ FronteggApp.Companion.getInstance().getAuth().refreshTokenIfNeeded();
122
+ Handler handler = new Handler(Looper.getMainLooper());
123
+ handler.post(call::resolve);
124
+ });
125
+ }
126
+
114
127
  @PluginMethod
115
128
  public void getAuthState(PluginCall call) {
116
129
  call.resolve(getData());
@@ -16,12 +16,13 @@ export declare type SubscribeMap<T> = {
16
16
  [K in keyof T]: Set<SubscribeFunc<T, K>>;
17
17
  };
18
18
  export interface FronteggNativePlugin {
19
- login(): void;
19
+ addListener(eventName: string, listenerFunc: ListenerCallback): Promise<PluginListenerHandle> & PluginListenerHandle;
20
+ getConstants(): Promise<Record<string, string>>;
21
+ getAuthState(): Promise<FronteggState>;
22
+ login(): Promise<void>;
20
23
  logout(): void;
21
24
  switchTenant(payload: {
22
25
  tenantId: string;
23
26
  }): Promise<void>;
24
- addListener(eventName: string, listenerFunc: ListenerCallback): Promise<PluginListenerHandle> & PluginListenerHandle;
25
- getConstants(): Promise<Record<string, string>>;
26
- getAuthState(): Promise<FronteggState>;
27
+ refreshToken(): Promise<void>;
27
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { ListenerCallback, PluginListenerHandle } from '@capacitor/core';\nimport type { ITenantsResponse, IUserProfile } from '@frontegg/rest-api';\n\nexport type User = IUserProfile & {\n tenants: ITenantsResponse[];\n activeTenant: ITenantsResponse\n}\n\nexport interface FronteggState {\n accessToken: string | null;\n refreshToken: string | null;\n isAuthenticated: boolean;\n user: User | null;\n showLoader: boolean;\n}\n\n\nexport type SubscribeFunc<T, K extends keyof T> = (value: T[K]) => void\nexport type SubscribeMap<T> = {\n [K in keyof T]: Set<SubscribeFunc<T, K>>\n}\n\n\nexport interface FronteggNativePlugin {\n login(): void;\n\n logout(): void;\n\n switchTenant(payload:{tenantId: string}): Promise<void>;\n\n addListener(eventName: string, listenerFunc: ListenerCallback): Promise<PluginListenerHandle> & PluginListenerHandle\n\n getConstants(): Promise<Record<string, string>>;\n\n getAuthState(): Promise<FronteggState>;\n\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { ListenerCallback, PluginListenerHandle } from '@capacitor/core';\nimport type { ITenantsResponse, IUserProfile } from '@frontegg/rest-api';\n\nexport type User = IUserProfile & {\n tenants: ITenantsResponse[];\n activeTenant: ITenantsResponse\n}\n\nexport interface FronteggState {\n accessToken: string | null;\n refreshToken: string | null;\n isAuthenticated: boolean;\n user: User | null;\n showLoader: boolean;\n}\n\n\nexport type SubscribeFunc<T, K extends keyof T> = (value: T[K]) => void\nexport type SubscribeMap<T> = {\n [K in keyof T]: Set<SubscribeFunc<T, K>>\n}\n\n\nexport interface FronteggNativePlugin {\n addListener(eventName: string, listenerFunc: ListenerCallback): Promise<PluginListenerHandle> & PluginListenerHandle\n\n getConstants(): Promise<Record<string, string>>;\n\n getAuthState(): Promise<FronteggState>;\n\n login(): Promise<void>;\n\n logout(): void;\n\n switchTenant(payload:{tenantId: string}): Promise<void>;\n\n refreshToken(): Promise<void>;\n\n}\n"]}
@@ -1,7 +1,8 @@
1
- import { FronteggState } from './definitions';
1
+ import type { FronteggState } from './definitions';
2
2
  export declare class FronteggService {
3
3
  private state;
4
4
  private mapListeners;
5
+ private readonly orderedListenerKeys;
5
6
  constructor();
6
7
  getState(): FronteggState;
7
8
  get $isLoading(): {
@@ -23,7 +24,8 @@ export declare class FronteggService {
23
24
  /**
24
25
  * Call frontegg native login method
25
26
  */
26
- login(): void;
27
+ login(): Promise<void>;
27
28
  logout(): void;
28
29
  switchTenant(tenantId: string): Promise<void>;
30
+ refreshToken(): Promise<void>;
29
31
  }
@@ -1,10 +1,17 @@
1
- import { createObservable } from './observables';
2
1
  import { registerPlugin } from '@capacitor/core';
2
+ import { createObservable } from './observables';
3
3
  const FronteggNative = registerPlugin('FronteggNative', {
4
4
  web: () => import('./web').then(m => new m.FronteggNativeWeb()),
5
5
  });
6
6
  export class FronteggService {
7
7
  constructor() {
8
+ this.orderedListenerKeys = [
9
+ 'refreshToken',
10
+ 'accessToken',
11
+ 'user',
12
+ 'isAuthenticated',
13
+ 'showLoader',
14
+ ];
8
15
  this.state = {
9
16
  isAuthenticated: false,
10
17
  showLoader: true,
@@ -20,27 +27,33 @@ export class FronteggService {
20
27
  'refreshToken': new Set(),
21
28
  };
22
29
  FronteggNative.addListener('onFronteggAuthEvent', (state) => {
23
- console.log('onFronteggAuthEvent', state);
24
- const keys = Object.keys(this.mapListeners);
25
- for (let i = 0; i < keys.length; i++) {
26
- const key = keys[i];
30
+ console.log('onFronteggAuthEvent', {
31
+ isAuthenticated: state.isAuthenticated,
32
+ showLoader: state.showLoader,
33
+ user: `${state.user}`,
34
+ accessToken: state.accessToken && state.accessToken.length > 50 ? `${state.accessToken.slice(0, 50)}...` : state.accessToken,
35
+ refreshToken: state.refreshToken,
36
+ });
37
+ const keys = this.orderedListenerKeys;
38
+ keys.forEach(key => {
27
39
  if (this.state[key] !== state[key]) {
28
- console.log('onFronteggAuthEvent key: ', key, 'from:', this.state[key], 'to:', state[key]);
40
+ console.log('onFronteggAuthEvent key: ', key);
41
+ this.state[key] = state[key];
29
42
  this.mapListeners[key].forEach((listener) => listener(state[key]));
30
43
  }
31
- }
44
+ });
32
45
  this.state = state;
33
46
  });
34
47
  FronteggNative.getAuthState().then((state) => {
35
48
  console.log('getAuthState()', state);
36
49
  const keys = Object.keys(this.mapListeners);
37
- for (let i = 0; i < keys.length; i++) {
38
- const key = keys[i];
50
+ for (const item of keys) {
51
+ const key = item;
39
52
  if (this.state[key] !== state[key]) {
53
+ this.state[key] = state[key];
40
54
  this.mapListeners[key].forEach((listener) => listener(state[key]));
41
55
  }
42
56
  }
43
- this.state = state;
44
57
  });
45
58
  }
46
59
  getState() {
@@ -62,14 +75,16 @@ export class FronteggService {
62
75
  * Call frontegg native login method
63
76
  */
64
77
  login() {
65
- FronteggNative.login();
78
+ return FronteggNative.login();
66
79
  }
67
80
  logout() {
68
81
  FronteggNative.logout();
69
82
  }
70
83
  switchTenant(tenantId) {
71
- console.log("test");
72
84
  return FronteggNative.switchTenant({ tenantId });
73
85
  }
86
+ refreshToken() {
87
+ return FronteggNative.refreshToken();
88
+ }
74
89
  }
75
90
  //# sourceMappingURL=frontegg.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"frontegg.service.js","sourceRoot":"","sources":["../../src/frontegg.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,cAAc,GAAG,cAAc,CAAuB,gBAAgB,EAAE;IAC5E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;CAChE,CAAC,CAAC;AAGH,MAAM,OAAO,eAAe;IAI1B;QACE,IAAI,CAAC,KAAK,GAAG;YACX,eAAe,EAAE,KAAK;YACtB,UAAU,EAAE,IAAI;YAChB,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,IAAI;YACjB,YAAY,EAAE,IAAI;SACnB,CAAA;QACD,IAAI,CAAC,YAAY,GAAG;YAClB,iBAAiB,EAAE,IAAI,GAAG,EAAE;YAC5B,YAAY,EAAE,IAAI,GAAG,EAAE;YACvB,MAAM,EAAE,IAAI,GAAG,EAAE;YACjB,aAAa,EAAE,IAAI,GAAG,EAAE;YACxB,cAAc,EAAE,IAAI,GAAG,EAAE;SAC1B,CAAA;QACD,cAAc,CAAC,WAAW,CAAC,qBAAqB,EAAE,CAAC,KAAoB,EAAE,EAAE;YACzE,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAA;YAEzC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;YAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACpC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAwB,CAAA;gBAC1C,IAAI,IAAI,C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gBAAgB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IACtE,CAAC;IAED,IAAW,gBAAgB;QACzB,OAAO,gBAAgB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAA;IAC3E,CAAC;IAED,IAAW,KAAK;QACd,OAAO,gBAAgB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IAChE,CAAC;IAED,IAAW,YAAY;QACrB,OAAO,gBAAgB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;IACvE,CAAC;IAED;;OAEG;IACI,KAAK;QACV,cAAc,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAEM,MAAM;QACX,cAAc,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;IAEM,YAAY,CAAC,QAAgB;QAClC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACnB,OAAO,cAAc,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;IAClD,CAAC;CACF","sourcesContent":["import { FronteggNativePlugin, FronteggState, SubscribeMap } from './definitions';\nimport { createObservable } from './observables';\nimport { registerPlugin } from '@capacitor/core';\n\nconst FronteggNative = registerPlugin<FronteggNativePlugin>('FronteggNative', {\n web: () => import('./web').then(m => new m.FronteggNativeWeb()),\n});\n\n\nexport class FronteggService {\n private state: FronteggState;\n private mapListeners: SubscribeMap<FronteggState>;\n\n constructor() {\n this.state = {\n isAuthenticated: false,\n showLoader: true,\n user: null,\n accessToken: null,\n refreshToken: null,\n }\n this.mapListeners = {\n 'isAuthenticated': new Set(),\n 'showLoader': new Set(),\n 'user': new Set(),\n 'accessToken': new Set(),\n 'refreshToken': new Set(),\n }\n FronteggNative.addListener('onFronteggAuthEvent', (state: FronteggState) => {\n console.log('onFronteggAuthEvent', state)\n\n const keys = Object.keys(this.mapListeners)\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i] as keyof FronteggState\n if (this.state[key] !== state[key]) {\n console.log('onFronteggAuthEvent key: ', key, 'from:', this.state[key], 'to:', state[key])\n this.mapListeners[key].forEach((listener: any) => listener(state[key]))\n }\n }\n this.state = state;\n })\n\n FronteggNative.getAuthState().then((state: FronteggState) => {\n console.log('getAuthState()', state)\n\n const keys = Object.keys(this.mapListeners)\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i] as keyof FronteggState\n if (this.state[key] !== state[key]) {\n this.mapListeners[key].forEach((listener: any) => listener(state[key]))\n }\n }\n this.state = state\n })\n }\n\n public getState() {\n return this.state;\n }\n\n public get $isLoading() {\n return createObservable(this.mapListeners, this.state, 'showLoader')\n }\n\n public get $isAuthenticated() {\n return createObservable(this.mapListeners, this.state, 'isAuthenticated')\n }\n\n public get $user() {\n return createObservable(this.mapListeners, this.state, 'user')\n }\n\n public get $accessToken() {\n return createObservable(this.mapListeners, this.state, 'accessToken')\n }\n\n /**\n * Call frontegg native login method\n */\n public login(): void {\n FronteggNative.login();\n }\n\n public logout(): void {\n FronteggNative.logout();\n }\n\n public switchTenant(tenantId: string): Promise<void> {\n console.log(\"test\")\n return FronteggNative.switchTenant({ tenantId })\n }\n}\n"]}
1
+ {"version":3,"file":"frontegg.service.js","sourceRoot":"","sources":["../../src/frontegg.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjD,MAAM,cAAc,GAAG,cAAc,CAAuB,gBAAgB,EAAE;IAC5E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;CAChE,CAAC,CAAC;AAGH,MAAM,OAAO,eAAe;I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EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAA;IAC3E,CAAC;IAED,IAAW,KAAK;QACd,OAAO,gBAAgB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IAChE,CAAC;IAED,IAAW,YAAY;QACrB,OAAO,gBAAgB,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC,CAAA;IACvE,CAAC;IAED;;OAEG;IACI,KAAK;QACV,OAAO,cAAc,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;IAEM,MAAM;QACX,cAAc,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;IAEM,YAAY,CAAC,QAAgB;QAClC,OAAO,cAAc,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;IAClD,CAAC;IAGM,YAAY;QACjB,OAAO,cAAc,CAAC,YAAY,EAAE,CAAA;IACtC,CAAC;CACF","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { FronteggNativePlugin, FronteggState, SubscribeMap } from './definitions';\nimport { createObservable } from './observables';\n\n\nconst FronteggNative = registerPlugin<FronteggNativePlugin>('FronteggNative', {\n web: () => import('./web').then(m => new m.FronteggNativeWeb()),\n});\n\n\nexport class FronteggService {\n private state: FronteggState;\n private mapListeners: SubscribeMap<FronteggState>;\n private readonly orderedListenerKeys: (keyof FronteggState)[] = [\n 'refreshToken',\n 'accessToken',\n 'user',\n 'isAuthenticated',\n 'showLoader',\n ]\n\n constructor() {\n this.state = {\n isAuthenticated: false,\n showLoader: true,\n user: null,\n accessToken: null,\n refreshToken: null,\n }\n\n this.mapListeners = {\n 'isAuthenticated': new Set(),\n 'showLoader': new Set(),\n 'user': new Set(),\n 'accessToken': new Set(),\n 'refreshToken': new Set(),\n }\n FronteggNative.addListener('onFronteggAuthEvent', (state: FronteggState) => {\n console.log('onFronteggAuthEvent', {\n isAuthenticated: state.isAuthenticated,\n showLoader: state.showLoader,\n user: `${state.user}`, // prevent log full user object // null | undefined | [object Object]\n accessToken: state.accessToken && state.accessToken.length > 50 ? `${state.accessToken.slice(0, 50)}...` : state.accessToken,\n refreshToken: state.refreshToken,\n })\n\n const keys = this.orderedListenerKeys;\n keys.forEach(key => {\n if (this.state[key] !== state[key]) {\n console.log('onFronteggAuthEvent key: ', key);\n (this.state as any)[key] = state[key];\n this.mapListeners[key].forEach((listener: any) => listener(state[key]))\n }\n });\n this.state = state;\n })\n\n FronteggNative.getAuthState().then((state: FronteggState) => {\n console.log('getAuthState()', state)\n\n const keys = Object.keys(this.mapListeners)\n for (const item of keys) {\n const key = item as keyof FronteggState\n if (this.state[key] !== state[key]) {\n (this.state as any)[key] = state[key]\n this.mapListeners[key].forEach((listener: any) => listener(state[key]))\n }\n }\n })\n }\n\n public getState() {\n return this.state;\n }\n\n public get $isLoading() {\n return createObservable(this.mapListeners, this.state, 'showLoader')\n }\n\n public get $isAuthenticated() {\n return createObservable(this.mapListeners, this.state, 'isAuthenticated')\n }\n\n public get $user() {\n return createObservable(this.mapListeners, this.state, 'user')\n }\n\n public get $accessToken() {\n return createObservable(this.mapListeners, this.state, 'accessToken')\n }\n\n /**\n * Call frontegg native login method\n */\n public login(): Promise<void> {\n return FronteggNative.login();\n }\n\n public logout(): void {\n FronteggNative.logout();\n }\n\n public switchTenant(tenantId: string): Promise<void> {\n return FronteggNative.switchTenant({ tenantId })\n }\n\n\n public refreshToken(): Promise<void> {\n return FronteggNative.refreshToken()\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { FronteggState, SubscribeFunc, SubscribeMap } from './definitions';
1
+ import type { FronteggState, SubscribeFunc, SubscribeMap } from './definitions';
2
2
  export declare const createObservable: <T extends "user" | "accessToken" | "refreshToken" | "isAuthenticated" | "showLoader">(map: SubscribeMap<FronteggState>, state: FronteggState, key: T) => {
3
3
  value: FronteggState[T];
4
4
  subscribe(listener: SubscribeFunc<FronteggState, T>): () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"observables.js","sourceRoot":"","sources":["../../src/observables.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAgC,GAAgC,EAAE,KAAoB,EAAE,GAAM,EAAE,EAAE;IAChI,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC;QACjB,SAAS,CAAC,QAAyC;YACjD,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAyC,CAAA;YAC/D,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACpB,OAAO,GAAG,EAAE;gBACV,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YACzB,CAAC,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { FronteggState, SubscribeFunc, SubscribeMap } from './definitions';\n\n\nexport const createObservable = <T extends keyof FronteggState>(map: SubscribeMap<FronteggState>, state: FronteggState, key: T) => {\n return {\n value: state[key],\n subscribe(listener: SubscribeFunc<FronteggState, T>) {\n const mapKey = map[key] as Set<SubscribeFunc<FronteggState, T>>\n mapKey.add(listener)\n return () => {\n mapKey.delete(listener)\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"observables.js","sourceRoot":"","sources":["../../src/observables.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAgC,GAAgC,EAAE,KAAoB,EAAE,GAAM,EAAE,EAAE;IAChI,OAAO;QACL,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC;QACjB,SAAS,CAAC,QAAyC;YACjD,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAyC,CAAA;YAC/D,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACpB,OAAO,GAAG,EAAE;gBACV,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YACzB,CAAC,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA","sourcesContent":["import type { FronteggState, SubscribeFunc, SubscribeMap } from './definitions';\n\n\nexport const createObservable = <T extends keyof FronteggState>(map: SubscribeMap<FronteggState>, state: FronteggState, key: T) => {\n return {\n value: state[key],\n subscribe(listener: SubscribeFunc<FronteggState, T>) {\n const mapKey = map[key] as Set<SubscribeFunc<FronteggState, T>>\n mapKey.add(listener)\n return () => {\n mapKey.delete(listener)\n }\n }\n }\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  import type { FronteggNativePlugin, FronteggState } from './definitions';
3
3
  export declare class FronteggNativeWeb extends WebPlugin implements FronteggNativePlugin {
4
+ getConstants(): Promise<Record<string, string>>;
5
+ getAuthState(): Promise<FronteggState>;
4
6
  login(): Promise<void>;
5
7
  logout(): Promise<void>;
6
8
  switchTenant(payload: {
7
9
  tenantId: string;
8
10
  }): Promise<void>;
9
- getConstants(): Promise<Record<string, string>>;
10
- getAuthState(): Promise<FronteggState>;
11
+ refreshToken(): Promise<void>;
11
12
  }
package/dist/esm/web.js CHANGED
@@ -1,5 +1,11 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  export class FronteggNativeWeb extends WebPlugin {
3
+ async getConstants() {
4
+ throw Error('FronteggNative.getConstants not implemented in web');
5
+ }
6
+ async getAuthState() {
7
+ throw Error('FronteggNative.getAuthState not implemented in web');
8
+ }
3
9
  async login() {
4
10
  throw Error('FronteggNative.login not implemented in web');
5
11
  }
@@ -7,13 +13,10 @@ export class FronteggNativeWeb extends WebPlugin {
7
13
  throw Error('FronteggNative.logout not implemented in web');
8
14
  }
9
15
  async switchTenant(payload) {
10
- throw Error(`FronteggNative.switchTenant ${payload} not implemented in web, `);
16
+ throw Error(`FronteggNative.switchTenant ${payload} not implemented in web`);
11
17
  }
12
- async getConstants() {
13
- throw Error('FronteggNative.getConstants not implemented in web');
14
- }
15
- async getAuthState() {
16
- throw Error('FronteggNative.getAuthState not implemented in web');
18
+ async refreshToken() {
19
+ throw Error(`FronteggNative.refreshToken not implemented in web`);
17
20
  }
18
21
  }
19
22
  //# sourceMappingURL=web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,iBACX,SAAQ,SAAS;IAGjB,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAC5D,CAAC;IAED,KAAK,CAAC,MAAM;QACV,MAAM,KAAK,CAAC,8CAA8C,CAAC,CAAA;IAC7D,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAA6B;QAC9C,MAAM,KAAK,CAAC,+BAA+B,OAAO,2BAA2B,CAAC,CAAA;IAChF,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACnE,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACnE,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { FronteggNativePlugin, FronteggState } from './definitions';\n\nexport class FronteggNativeWeb\n extends WebPlugin\n implements FronteggNativePlugin {\n\n async login(): Promise<void> {\n throw Error('FronteggNative.login not implemented in web')\n }\n\n async logout(): Promise<void> {\n throw Error('FronteggNative.logout not implemented in web')\n }\n\n async switchTenant(payload: { tenantId: string }): Promise<void> {\n throw Error(`FronteggNative.switchTenant ${payload} not implemented in web, `)\n }\n\n async getConstants(): Promise<Record<string, string>> {\n throw Error('FronteggNative.getConstants not implemented in web')\n }\n\n async getAuthState(): Promise<FronteggState> {\n throw Error('FronteggNative.getAuthState not implemented in web')\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,iBACX,SAAQ,SAAS;IAGjB,KAAK,CAAC,YAAY;QAChB,MAAM,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACnE,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACnE,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAC5D,CAAC;IAED,KAAK,CAAC,MAAM;QACV,MAAM,KAAK,CAAC,8CAA8C,CAAC,CAAA;IAC7D,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAA6B;QAC9C,MAAM,KAAK,CAAC,+BAA+B,OAAO,yBAAyB,CAAC,CAAA;IAC9E,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACnE,CAAC;CAEF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { FronteggNativePlugin, FronteggState } from './definitions';\n\nexport class FronteggNativeWeb\n extends WebPlugin\n implements FronteggNativePlugin {\n\n async getConstants(): Promise<Record<string, string>> {\n throw Error('FronteggNative.getConstants not implemented in web')\n }\n\n async getAuthState(): Promise<FronteggState> {\n throw Error('FronteggNative.getAuthState not implemented in web')\n }\n\n async login(): Promise<void> {\n throw Error('FronteggNative.login not implemented in web')\n }\n\n async logout(): Promise<void> {\n throw Error('FronteggNative.logout not implemented in web')\n }\n\n async switchTenant(payload: { tenantId: string }): Promise<void> {\n throw Error(`FronteggNative.switchTenant ${payload} not implemented in web`)\n }\n\n async refreshToken(): Promise<void> {\n throw Error(`FronteggNative.refreshToken not implemented in web`)\n }\n\n}\n"]}
@@ -22,6 +22,13 @@ const FronteggNative = core.registerPlugin('FronteggNative', {
22
22
  });
23
23
  class FronteggService {
24
24
  constructor() {
25
+ this.orderedListenerKeys = [
26
+ 'refreshToken',
27
+ 'accessToken',
28
+ 'user',
29
+ 'isAuthenticated',
30
+ 'showLoader',
31
+ ];
25
32
  this.state = {
26
33
  isAuthenticated: false,
27
34
  showLoader: true,
@@ -37,27 +44,33 @@ class FronteggService {
37
44
  'refreshToken': new Set(),
38
45
  };
39
46
  FronteggNative.addListener('onFronteggAuthEvent', (state) => {
40
- console.log('onFronteggAuthEvent', state);
41
- const keys = Object.keys(this.mapListeners);
42
- for (let i = 0; i < keys.length; i++) {
43
- const key = keys[i];
47
+ console.log('onFronteggAuthEvent', {
48
+ isAuthenticated: state.isAuthenticated,
49
+ showLoader: state.showLoader,
50
+ user: `${state.user}`,
51
+ accessToken: state.accessToken && state.accessToken.length > 50 ? `${state.accessToken.slice(0, 50)}...` : state.accessToken,
52
+ refreshToken: state.refreshToken,
53
+ });
54
+ const keys = this.orderedListenerKeys;
55
+ keys.forEach(key => {
44
56
  if (this.state[key] !== state[key]) {
45
- console.log('onFronteggAuthEvent key: ', key, 'from:', this.state[key], 'to:', state[key]);
57
+ console.log('onFronteggAuthEvent key: ', key);
58
+ this.state[key] = state[key];
46
59
  this.mapListeners[key].forEach((listener) => listener(state[key]));
47
60
  }
48
- }
61
+ });
49
62
  this.state = state;
50
63
  });
51
64
  FronteggNative.getAuthState().then((state) => {
52
65
  console.log('getAuthState()', state);
53
66
  const keys = Object.keys(this.mapListeners);
54
- for (let i = 0; i < keys.length; i++) {
55
- const key = keys[i];
67
+ for (const item of keys) {
68
+ const key = item;
56
69
  if (this.state[key] !== state[key]) {
70
+ this.state[key] = state[key];
57
71
  this.mapListeners[key].forEach((listener) => listener(state[key]));
58
72
  }
59
73
  }
60
- this.state = state;
61
74
  });
62
75
  }
63
76
  getState() {
@@ -79,18 +92,26 @@ class FronteggService {
79
92
  * Call frontegg native login method
80
93
  */
81
94
  login() {
82
- FronteggNative.login();
95
+ return FronteggNative.login();
83
96
  }
84
97
  logout() {
85
98
  FronteggNative.logout();
86
99
  }
87
100
  switchTenant(tenantId) {
88
- console.log("test");
89
101
  return FronteggNative.switchTenant({ tenantId });
90
102
  }
103
+ refreshToken() {
104
+ return FronteggNative.refreshToken();
105
+ }
91
106
  }
92
107
 
93
108
  class FronteggNativeWeb extends core.WebPlugin {
109
+ async getConstants() {
110
+ throw Error('FronteggNative.getConstants not implemented in web');
111
+ }
112
+ async getAuthState() {
113
+ throw Error('FronteggNative.getAuthState not implemented in web');
114
+ }
94
115
  async login() {
95
116
  throw Error('FronteggNative.login not implemented in web');
96
117
  }
@@ -98,13 +119,10 @@ class FronteggNativeWeb extends core.WebPlugin {
98
119
  throw Error('FronteggNative.logout not implemented in web');
99
120
  }
100
121
  async switchTenant(payload) {
101
- throw Error(`FronteggNative.switchTenant ${payload} not implemented in web, `);
122
+ throw Error(`FronteggNative.switchTenant ${payload} not implemented in web`);
102
123
  }
103
- async getConstants() {
104
- throw Error('FronteggNative.getConstants not implemented in web');
105
- }
106
- async getAuthState() {
107
- throw Error('FronteggNative.getAuthState not implemented in web');
124
+ async refreshToken() {
125
+ throw Error(`FronteggNative.refreshToken not implemented in web`);
108
126
  }
109
127
  }
110
128
 
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/observables.js","esm/frontegg.service.js","esm/web.js"],"sourcesContent":["export const createObservable = (map, state, key) => {\n return {\n value: state[key],\n subscribe(listener) {\n const mapKey = map[key];\n mapKey.add(listener);\n return () => {\n mapKey.delete(listener);\n };\n }\n };\n};\n//# sourceMappingURL=observables.js.map","import { createObservable } from './observables';\nimport { registerPlugin } from '@capacitor/core';\nconst FronteggNative = registerPlugin('FronteggNative', {\n web: () => import('./web').then(m => new m.FronteggNativeWeb()),\n});\nexport class FronteggService {\n constructor() {\n this.state = {\n isAuthenticated: false,\n showLoader: true,\n user: null,\n accessToken: null,\n refreshToken: null,\n };\n this.mapListeners = {\n 'isAuthenticated': new Set(),\n 'showLoader': new Set(),\n 'user': new Set(),\n 'accessToken': new Set(),\n 'refreshToken': new Set(),\n };\n FronteggNative.addListener('onFronteggAuthEvent', (state) => {\n console.log('onFronteggAuthEvent', state);\n const keys = Object.keys(this.mapListeners);\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (this.state[key] !== state[key]) {\n console.log('onFronteggAuthEvent key: ', key, 'from:', this.state[key], 'to:', state[key]);\n this.mapListeners[key].forEach((listener) => listener(state[key]));\n }\n }\n this.state = state;\n });\n FronteggNative.getAuthState().then((state) => {\n console.log('getAuthState()', state);\n const keys = Object.keys(this.mapListeners);\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (this.state[key] !== state[key]) {\n this.mapListeners[key].forEach((listener) => listener(state[key]));\n }\n }\n this.state = state;\n });\n }\n getState() {\n return this.state;\n }\n get $isLoading() {\n return createObservable(this.mapListeners, this.state, 'showLoader');\n }\n get $isAuthenticated() {\n return createObservable(this.mapListeners, this.state, 'isAuthenticated');\n }\n get $user() {\n return createObservable(this.mapListeners, this.state, 'user');\n }\n get $accessToken() {\n return createObservable(this.mapListeners, this.state, 'accessToken');\n }\n /**\n * Call frontegg native login method\n */\n login() {\n FronteggNative.login();\n }\n logout() {\n FronteggNative.logout();\n }\n switchTenant(tenantId) {\n console.log(\"test\");\n return FronteggNative.switchTenant({ tenantId });\n }\n}\n//# sourceMappingURL=frontegg.service.js.map","import { WebPlugin } from '@capacitor/core';\nexport class FronteggNativeWeb extends WebPlugin {\n async login() {\n throw Error('FronteggNative.login not implemented in web');\n }\n async logout() {\n throw Error('FronteggNative.logout not implemented in web');\n }\n async switchTenant(payload) {\n throw Error(`FronteggNative.switchTenant ${payload} not implemented in web, `);\n }\n async getConstants() {\n throw Error('FronteggNative.getConstants not implemented in web');\n }\n async getAuthState() {\n throw Error('FronteggNative.getAuthState not implemented in web');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AAAO,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,KAAK;AACrD,IAAI,OAAO;AACX,QAAQ,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC;AACzB,QAAQ,SAAS,C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Q,MAAM,KAAK,CAAC,6CAA6C,CAAC,CAAC;AACnE,KAAK;AACL,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,MAAM,KAAK,CAAC,8CAA8C,CAAC,CAAC;AACpE,KAAK;AACL,IAAI,MAAM,YAAY,CAAC,OAAO,EAAE;AAChC,QAAQ,MAAM,KAAK,CAAC,CAAC,4BAA4B,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC;AACvF,KAAK;AACL,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,MAAM,KAAK,CAAC,oDAAoD,CAAC,CAAC;AAC1E,KAAK;AACL,IAAI,MAAM,YAAY,GAAG;AACzB,QAAQ,MAAM,KAAK,CAAC,oDAAoD,CAAC,CAAC;AAC1E,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/observables.js","esm/frontegg.service.js","esm/web.js"],"sourcesContent":["export const createObservable = (map, state, key) => {\n return {\n value: state[key],\n subscribe(listener) {\n const mapKey = map[key];\n mapKey.add(listener);\n return () => {\n mapKey.delete(listener);\n };\n }\n };\n};\n//# sourceMappingURL=observables.js.map","import { registerPlugin } from '@capacitor/core';\nimport { createObservable } from './observables';\nconst FronteggNative = registerPlugin('FronteggNative', {\n web: () => import('./web').then(m => new m.FronteggNativeWeb()),\n});\nexport class FronteggService {\n constructor() {\n this.orderedListenerKeys = [\n 'refreshToken',\n 'accessToken',\n 'user',\n 'isAuthenticated',\n 'showLoader',\n ];\n this.state = {\n isAuthenticated: false,\n showLoader: true,\n user: null,\n accessToken: null,\n refreshToken: null,\n };\n this.mapListeners = {\n 'isAuthenticated': new Set(),\n 'showLoader': new Set(),\n 'user': new Set(),\n 'accessToken': new Set(),\n 'refreshToken': new Set(),\n };\n FronteggNative.addListener('onFronteggAuthEvent', (state) => {\n console.log('onFronteggAuthEvent', {\n isAuthenticated: state.isAuthenticated,\n showLoader: state.showLoader,\n user: `${state.user}`,\n accessToken: state.accessToken && state.accessToken.length > 50 ? `${state.accessToken.slice(0, 50)}...` : state.accessToken,\n refreshToken: state.refreshToken,\n });\n const keys = this.orderedListenerKeys;\n keys.forEach(key => {\n if (this.state[key] !== state[key]) {\n console.log('onFronteggAuthEvent key: ', key);\n this.state[key] = state[key];\n this.mapListeners[key].forEach((listener) => listener(state[key]));\n }\n });\n this.state = state;\n });\n FronteggNative.getAuthState().then((state) => {\n console.log('getAuthState()', state);\n const keys = Object.keys(this.mapListeners);\n for (const item of keys) {\n const key = item;\n if (this.state[key] !== state[key]) {\n this.state[key] = state[key];\n this.mapListeners[key].forEach((listener) => listener(state[key]));\n }\n }\n });\n }\n getState() {\n return this.state;\n }\n get $isLoading() {\n return createObservable(this.mapListeners, this.state, 'showLoader');\n }\n get $isAuthenticated() {\n return createObservable(this.mapListeners, this.state, 'isAuthenticated');\n }\n get $user() {\n return createObservable(this.mapListeners, this.state, 'user');\n }\n get $accessToken() {\n return createObservable(this.mapListeners, this.state, 'accessToken');\n }\n /**\n * Call frontegg native login method\n */\n login() {\n return FronteggNative.login();\n }\n logout() {\n FronteggNative.logout();\n }\n switchTenant(tenantId) {\n return FronteggNative.switchTenant({ tenantId });\n }\n refreshToken() {\n return FronteggNative.refreshToken();\n }\n}\n//# sourceMappingURL=frontegg.service.js.map","import { WebPlugin } from '@capacitor/core';\nexport class FronteggNativeWeb extends WebPlugin {\n async getConstants() {\n throw Error('FronteggNative.getConstants not implemented in web');\n }\n async getAuthState() {\n throw Error('FronteggNative.getAuthState not implemented in web');\n }\n async login() {\n throw Error('FronteggNative.login not implemented in web');\n }\n async logout() {\n throw Error('FronteggNative.logout not implemented in web');\n }\n async switchTenant(payload) {\n throw Error(`FronteggNative.switchTenant ${payload} not implemented in web`);\n }\n async refreshToken() {\n throw Error(`FronteggNative.refreshToken not implemented in web`);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AAAO,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,KAA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
  constructor() {
22
+ this.orderedListenerKeys = [
23
+ 'refreshToken',
24
+ 'accessToken',
25
+ 'user',
26
+ 'isAuthenticated',
27
+ 'showLoader',
28
+ ];
22
29
  this.state = {
23
30
  isAuthenticated: false,
24
31
  showLoader: true,
@@ -34,27 +41,33 @@ var capacitorFronteggNative = (function (exports, core) {
34
41
  'refreshToken': new Set(),
35
42
  };
36
43
  FronteggNative.addListener('onFronteggAuthEvent', (state) => {
37
- console.log('onFronteggAuthEvent', state);
38
- const keys = Object.keys(this.mapListeners);
39
- for (let i = 0; i < keys.length; i++) {
40
- const key = keys[i];
44
+ console.log('onFronteggAuthEvent', {
45
+ isAuthenticated: state.isAuthenticated,
46
+ showLoader: state.showLoader,
47
+ user: `${state.user}`,
48
+ accessToken: state.accessToken && state.accessToken.length > 50 ? `${state.accessToken.slice(0, 50)}...` : state.accessToken,
49
+ refreshToken: state.refreshToken,
50
+ });
51
+ const keys = this.orderedListenerKeys;
52
+ keys.forEach(key => {
41
53
  if (this.state[key] !== state[key]) {
42
- console.log('onFronteggAuthEvent key: ', key, 'from:', this.state[key], 'to:', state[key]);
54
+ console.log('onFronteggAuthEvent key: ', key);
55
+ this.state[key] = state[key];
43
56
  this.mapListeners[key].forEach((listener) => listener(state[key]));
44
57
  }
45
- }
58
+ });
46
59
  this.state = state;
47
60
  });
48
61
  FronteggNative.getAuthState().then((state) => {
49
62
  console.log('getAuthState()', state);
50
63
  const keys = Object.keys(this.mapListeners);
51
- for (let i = 0; i < keys.length; i++) {
52
- const key = keys[i];
64
+ for (const item of keys) {
65
+ const key = item;
53
66
  if (this.state[key] !== state[key]) {
67
+ this.state[key] = state[key];
54
68
  this.mapListeners[key].forEach((listener) => listener(state[key]));
55
69
  }
56
70
  }
57
- this.state = state;
58
71
  });
59
72
  }
60
73
  getState() {
@@ -76,18 +89,26 @@ var capacitorFronteggNative = (function (exports, core) {
76
89
  * Call frontegg native login method
77
90
  */
78
91
  login() {
79
- FronteggNative.login();
92
+ return FronteggNative.login();
80
93
  }
81
94
  logout() {
82
95
  FronteggNative.logout();
83
96
  }
84
97
  switchTenant(tenantId) {
85
- console.log("test");
86
98
  return FronteggNative.switchTenant({ tenantId });
87
99
  }
100
+ refreshToken() {
101
+ return FronteggNative.refreshToken();
102
+ }
88
103
  }
89
104
 
90
105
  class FronteggNativeWeb extends core.WebPlugin {
106
+ async getConstants() {
107
+ throw Error('FronteggNative.getConstants not implemented in web');
108
+ }
109
+ async getAuthState() {
110
+ throw Error('FronteggNative.getAuthState not implemented in web');
111
+ }
91
112
  async login() {
92
113
  throw Error('FronteggNative.login not implemented in web');
93
114
  }
@@ -95,13 +116,10 @@ var capacitorFronteggNative = (function (exports, core) {
95
116
  throw Error('FronteggNative.logout not implemented in web');
96
117
  }
97
118
  async switchTenant(payload) {
98
- throw Error(`FronteggNative.switchTenant ${payload} not implemented in web, `);
119
+ throw Error(`FronteggNative.switchTenant ${payload} not implemented in web`);
99
120
  }
100
- async getConstants() {
101
- throw Error('FronteggNative.getConstants not implemented in web');
102
- }
103
- async getAuthState() {
104
- throw Error('FronteggNative.getAuthState not implemented in web');
121
+ async refreshToken() {
122
+ throw Error(`FronteggNative.refreshToken not implemented in web`);
105
123
  }
106
124
  }
107
125
 
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/observables.js","esm/frontegg.service.js","esm/web.js"],"sourcesContent":["export const createObservable = (map, state, key) => {\n return {\n value: state[key],\n subscribe(listener) {\n const mapKey = map[key];\n mapKey.add(listener);\n return () => {\n mapKey.delete(listener);\n };\n }\n };\n};\n//# sourceMappingURL=observables.js.map","import { createObservable } from './observables';\nimport { registerPlugin } from '@capacitor/core';\nconst FronteggNative = registerPlugin('FronteggNative', {\n web: () => import('./web').then(m => new m.FronteggNativeWeb()),\n});\nexport class FronteggService {\n constructor() {\n this.state = {\n isAuthenticated: false,\n showLoader: true,\n user: null,\n accessToken: null,\n refreshToken: null,\n };\n this.mapListeners = {\n 'isAuthenticated': new Set(),\n 'showLoader': new Set(),\n 'user': new Set(),\n 'accessToken': new Set(),\n 'refreshToken': new Set(),\n };\n FronteggNative.addListener('onFronteggAuthEvent', (state) => {\n console.log('onFronteggAuthEvent', state);\n const keys = Object.keys(this.mapListeners);\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (this.state[key] !== state[key]) {\n console.log('onFronteggAuthEvent key: ', key, 'from:', this.state[key], 'to:', state[key]);\n this.mapListeners[key].forEach((listener) => listener(state[key]));\n }\n }\n this.state = state;\n });\n FronteggNative.getAuthState().then((state) => {\n console.log('getAuthState()', state);\n const keys = Object.keys(this.mapListeners);\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n if (this.state[key] !== state[key]) {\n this.mapListeners[key].forEach((listener) => listener(state[key]));\n }\n }\n this.state = state;\n });\n }\n getState() {\n return this.state;\n }\n get $isLoading() {\n return createObservable(this.mapListeners, this.state, 'showLoader');\n }\n get $isAuthenticated() {\n return createObservable(this.mapListeners, this.state, 'isAuthenticated');\n }\n get $user() {\n return createObservable(this.mapListeners, this.state, 'user');\n }\n get $accessToken() {\n return createObservable(this.mapListeners, this.state, 'accessToken');\n }\n /**\n * Call frontegg native login method\n */\n login() {\n FronteggNative.login();\n }\n logout() {\n FronteggNative.logout();\n }\n switchTenant(tenantId) {\n console.log(\"test\");\n return FronteggNative.switchTenant({ tenantId });\n }\n}\n//# sourceMappingURL=frontegg.service.js.map","import { WebPlugin } from '@capacitor/core';\nexport class FronteggNativeWeb extends WebPlugin {\n async login() {\n throw Error('FronteggNative.login not implemented in web');\n }\n async logout() {\n throw Error('FronteggNative.logout not implemented in web');\n }\n async switchTenant(payload) {\n throw Error(`FronteggNative.switchTenant ${payload} not implemented in web, `);\n }\n async getConstants() {\n throw Error('FronteggNative.getConstants not implemented in web');\n }\n async getAuthState() {\n throw Error('FronteggNative.getAuthState not implemented in web');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;IAAO,MAAM,gBAAgB,G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AAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IACzD,KAAK;IACL;;ICxEO,MAAM,iBAAiB,SAASC,cAAS,CAAC;IACjD,IAAI,MAAM,KAAK,GAAG;IAClB,QAAQ,MAAM,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACnE,KAAK;IACL,IAAI,MAAM,MAAM,GAAG;IACnB,QAAQ,MAAM,KAAK,CAAC,8CAA8C,CAAC,CAAC;IACpE,KAAK;IACL,IAAI,MAAM,YAAY,CAAC,OAAO,EAAE;IAChC,QAAQ,MAAM,KAAK,CAAC,CAAC,4BAA4B,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC;IACvF,KAAK;IACL,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,MAAM,KAAK,CAAC,oDAAoD,CAAC,CAAC;IAC1E,KAAK;IACL,IAAI,MAAM,YAAY,GAAG;IACzB,QAAQ,MAAM,KAAK,CAAC,oDAAoD,CAAC,CAAC;IAC1E,KAAK;IACL;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/observables.js","esm/frontegg.service.js","esm/web.js"],"sourcesContent":["export const createObservable = (map, state, key) => {\n return {\n value: state[key],\n subscribe(listener) {\n const mapKey = map[key];\n mapKey.add(listener);\n return () => {\n mapKey.delete(listener);\n };\n }\n };\n};\n//# sourceMappingURL=observables.js.map","import { registerPlugin } from '@capacitor/core';\nimport { createObservable } from './observables';\nconst FronteggNative = registerPlugin('FronteggNative', {\n web: () => import('./web').then(m => new m.FronteggNativeWeb()),\n});\nexport class FronteggService {\n constructor() {\n this.orderedListenerKeys = [\n 'refreshToken',\n 'accessToken',\n 'user',\n 'isAuthenticated',\n 'showLoader',\n ];\n this.state = {\n isAuthenticated: false,\n showLoader: true,\n user: null,\n accessToken: null,\n refreshToken: null,\n };\n this.mapListeners = {\n 'isAuthenticated': new Set(),\n 'showLoader': new Set(),\n 'user': new Set(),\n 'accessToken': new Set(),\n 'refreshToken': new Set(),\n };\n FronteggNative.addListener('onFronteggAuthEvent', (state) => {\n console.log('onFronteggAuthEvent', {\n isAuthenticated: state.isAuthenticated,\n showLoader: state.showLoader,\n user: `${state.user}`,\n accessToken: state.accessToken && state.accessToken.length > 50 ? `${state.accessToken.slice(0, 50)}...` : state.accessToken,\n refreshToken: state.refreshToken,\n });\n const keys = this.orderedListenerKeys;\n keys.forEach(key => {\n if (this.state[key] !== state[key]) {\n console.log('onFronteggAuthEvent key: ', key);\n this.state[key] = state[key];\n this.mapListeners[key].forEach((listener) => listener(state[key]));\n }\n });\n this.state = state;\n });\n FronteggNative.getAuthState().then((state) => {\n console.log('getAuthState()', state);\n const keys = Object.keys(this.mapListeners);\n for (const item of keys) {\n const key = item;\n if (this.state[key] !== state[key]) {\n this.state[key] = state[key];\n this.mapListeners[key].forEach((listener) => listener(state[key]));\n }\n }\n });\n }\n getState() {\n return this.state;\n }\n get $isLoading() {\n return createObservable(this.mapListeners, this.state, 'showLoader');\n }\n get $isAuthenticated() {\n return createObservable(this.mapListeners, this.state, 'isAuthenticated');\n }\n get $user() {\n return createObservable(this.mapListeners, this.state, 'user');\n }\n get $accessToken() {\n return createObservable(this.mapListeners, this.state, 'accessToken');\n }\n /**\n * Call frontegg native login method\n */\n login() {\n return FronteggNative.login();\n }\n logout() {\n FronteggNative.logout();\n }\n switchTenant(tenantId) {\n return FronteggNative.switchTenant({ tenantId });\n }\n refreshToken() {\n return FronteggNative.refreshToken();\n }\n}\n//# sourceMappingURL=frontegg.service.js.map","import { WebPlugin } from '@capacitor/core';\nexport class FronteggNativeWeb extends WebPlugin {\n async getConstants() {\n throw Error('FronteggNative.getConstants not implemented in web');\n }\n async getAuthState() {\n throw Error('FronteggNative.getAuthState not implemented in web');\n }\n async login() {\n throw Error('FronteggNative.login not implemented in web');\n }\n async logout() {\n throw Error('FronteggNative.logout not implemented in web');\n }\n async switchTenant(payload) {\n throw Error(`FronteggNative.switchTenant ${payload} not implemented in web`);\n }\n async refreshToken() {\n throw Error(`F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AAC,CAAC;IAC1E,KAAK;IACL;;;;;;;;;;;;;;;;;"}
@@ -4,11 +4,12 @@
4
4
  // Define the plugin using the CAP_PLUGIN Macro, and
5
5
  // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
6
  CAP_PLUGIN(FronteggNativePlugin, "FronteggNative",
7
+ CAP_PLUGIN_METHOD(getAuthState, CAPPluginReturnPromise);
8
+ CAP_PLUGIN_METHOD(getConstants, CAPPluginReturnPromise);
7
9
  CAP_PLUGIN_METHOD(login, CAPPluginReturnPromise);
8
10
  CAP_PLUGIN_METHOD(logout, CAPPluginReturnPromise);
9
11
  CAP_PLUGIN_METHOD(switchTenant, CAPPluginReturnPromise);
10
- CAP_PLUGIN_METHOD(getAuthState, CAPPluginReturnPromise);
11
- CAP_PLUGIN_METHOD(getConstants, CAPPluginReturnPromise);
12
+ CAP_PLUGIN_METHOD(refreshToken, CAPPluginReturnPromise);
12
13
  )
13
14
 
14
15
 
@@ -68,12 +68,16 @@ public class FronteggNativePlugin: CAPPlugin {
68
68
  }
69
69
 
70
70
  @objc func login(_ call: CAPPluginCall) {
71
- fronteggApp.auth.login()
71
+ DispatchQueue.main.sync {
72
+ fronteggApp.auth.login()
73
+ }
72
74
  call.resolve()
73
75
  }
74
76
 
75
77
  @objc func logout(_ call: CAPPluginCall) {
76
- fronteggApp.auth.logout()
78
+ DispatchQueue.main.sync {
79
+ fronteggApp.auth.logout()
80
+ }
77
81
  call.resolve()
78
82
  }
79
83
 
@@ -88,6 +92,16 @@ public class FronteggNativePlugin: CAPPlugin {
88
92
  }
89
93
  }
90
94
 
95
+ @objc func refreshToken(_ call: CAPPluginCall) {
96
+
97
+ DispatchQueue.global(qos: .background).async {
98
+ Task {
99
+ await self.fronteggApp.auth.refreshTokenIfNeeded()
100
+ call.resolve()
101
+ }
102
+ }
103
+ }
104
+
91
105
  @objc func getAuthState(_ call: CAPPluginCall) {
92
106
  let auth = fronteggApp.auth
93
107
  var jsonUser: [String: Any]? = nil
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontegg/ionic-capacitor",
3
- "version": "0.0.5",
3
+ "version": "1.0.0-alpha.0",
4
4
  "description": "Frontegg Ionic Capacitor SDK",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",