@frontegg/angular 5.5.3-alpha.3224668504 → 5.5.3-alpha.3288072955

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 (2) hide show
  1. package/README.md +67 -31
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,24 +1,29 @@
1
1
  # Frontegg Angular
2
2
 
3
+ ## BREAKING CHANGES SINCE VERSION 3.0.1
4
+ If you are migrating from `@frontegg/angular` version 2 or earlier, you can find a [migration guide here](https://docs.frontegg.com/docs/migration-guide-fronteggangular-v2-v3)
3
5
  ## How to use
4
6
 
5
- ### 1. Install Frontegg Libraries Run the following command to Install Frontegg Angular library.
7
+ ### 1. Install Frontegg Libraries
8
+
9
+ Run the following command to Install Frontegg Angular library:
6
10
 
7
11
  ```
8
12
  npm install @frontegg/angular
9
13
  ```
10
14
 
11
15
  ### 2. Configuration
12
- 1. Add `FronteggAppModule` to `AppModule.imports[]`
13
- 2. Add `FronteggComponent` to `AppModule.entryComponents[]`
16
+ 1. Add `FronteggAppModule` to `AppModule.imports[]`
17
+ 2. Add `FronteggComponent` to `AppModule.entryComponents[]`
14
18
 
15
19
  ```
20
+ /app.module.ts
16
21
  import { BrowserModule } from '@angular/platform-browser';
17
22
  import { NgModule } from '@angular/core';
18
23
  import { AppRoutingModule } from './app-routing.module';
19
24
  import { AppComponent } from './app.component';
20
25
  import { CommonModule } from '@angular/common';
21
- import { FronteggAppModule } from '@frontegg/angular';
26
+ import { FronteggAppModule, FronteggComponent } from '@frontegg/angular';
22
27
 
23
28
  @NgModule({
24
29
  declarations: [AppComponent],
@@ -49,22 +54,24 @@ export class AppModule { }
49
54
 
50
55
  #### Connect your application bootstrap component with `fronteggService` to listen for frontegg loading state
51
56
 
52
- ```
53
- /app.component.ts
57
+ ```ts
58
+ //app.component.ts
59
+
60
+ import { Component, OnInit, OnDestroy } from '@angular/core';
61
+ import { FronteggAuthService, FronteggAppService } from '@frontegg/angular';
62
+ import { Subscription } from 'rxjs';
54
63
 
55
64
  @Component({
56
65
  selector: 'app-root',
57
66
  templateUrl: './app.component.html',
58
67
  })
59
- export class AppComponent implements OnDistory {
68
+ export class AppComponent implements OnDestory {
60
69
  isLoading = true;
61
70
  loadingSubscription: Subscription;
62
-
63
71
  constructor(private fronteggAppService: FronteggAppService) {
64
- this.loadingSubscription = fronteggAppService.isLoading$.subscribe((isLoading) => this.isLoading = isLoading);
72
+ this.loadingSubscription = fronteggAppService.isLoading$.subscribe((isLoading) => this.isLoading = isLoading)
65
73
  }
66
-
67
- ngOnDistory(): void {
74
+ ngOnDestory(): void {
68
75
  this.loadingSubscription.unsubscribe()
69
76
  }
70
77
  }
@@ -72,56 +79,85 @@ export class AppComponent implements OnDistory {
72
79
 
73
80
  #### And wrap your application with `*ngIf="!isLoading"` selector to make sure you have the right context
74
81
 
75
- ```
76
- /app.component.html
82
+ ```html
83
+ <!-- app.component.html -->
77
84
 
78
85
  <div *ngIf="!isLoading">
79
86
  <router-outlet></router-outlet>
80
87
  </div>
81
88
  ```
82
89
 
83
- ### 3. Getting the user context Frontegg exposes the user context and the authentication state via a `FronteggAppService`. You can access the whole authentication state via the `FronteggAppService`. To have an access to memoized
84
- authentication substates like user state, SSO state, MFA state, etc. use `FronteggAppAuthService` as in the following
85
- sample:
90
+ ### 3. Getting the user context
86
91
 
87
- ```
88
- import { Component, OnInit } from '@angular/core';
89
- import { FronteggAuthService, AuthState } from '@frontegg/angular';
92
+ Frontegg exposes the user context and the authentication state via a `FronteggAppService`. You can access the whole authentication state via the `FronteggAppService`. To have an access to memoized
93
+ authentication substates like user state, SSO state, MFA state, etc. use `FronteggAuthService` as in the following
94
+ sample:
95
+
96
+ ```ts
97
+ // app.component.ts
98
+ import { Component, OnInit, OnDestroy } from '@angular/core';
99
+ import { FronteggAuthService, FronteggAppService } from '@frontegg/angular';
100
+ import { Subscription } from 'rxjs';
90
101
 
91
102
  @Component({
92
103
  selector: 'app-root',
93
- template: `<div *ngIf="authenticated">
94
- <img src={{user?.profilePictureUrl}} alt={{user?.name}} />
95
- <div>User name: {{user?.name}}</div>
96
- </div>`,
104
+ templateUrl: './app.component.html',
97
105
  styleUrls: ['./app.component.scss'],
98
106
  })
99
- export class AppComponent implements OnInit {
100
- user?: AuthState['user'] | null;
107
+ export class AppComponent implements OnInit, OnDestroy {
108
+ isLoading = true;
109
+ loadingSubscription: Subscription;
110
+ user?: any;
101
111
 
102
- constructor(private fronteggAuthService: FronteggAuthService) {
112
+ constructor(
113
+ private fronteggAuthService: FronteggAuthService,
114
+ private fronteggAppService: FronteggAppService) {
115
+ this.loadingSubscription =
116
+ fronteggAppService.isLoading$.subscribe((isLoading) => this.isLoading = isLoading)
103
117
  }
104
118
 
105
119
  ngOnInit(): void {
106
- this.fronteggAppAuthService?.userState$.subscribe((user) => {
120
+ this.fronteggAuthService?.user$.subscribe((user) => {
107
121
  this.user = user
108
122
  })
109
123
  }
124
+
125
+ ngOnDestory(): void {
126
+ this.loadingSubscription.unsubscribe()
127
+ }
110
128
  }
111
129
  ```
112
130
 
113
- ### 4. Tou can add FronteggAuthGuard to your routing module to redirect the user to the login page if the user not authenticated and trying to reach a private route.
131
+ Update `app.component.html` to display the user's name and avatar:
132
+
133
+ ```html
134
+ <!-- app.component.html-->
135
+
136
+ <div *ngIf="!isLoading">
137
+ <img src={{user?.profilePictureUrl}} alt={{user?.name}} />
138
+ <div>User name: {{user?.name}}</div>
139
+ </div>
114
140
 
115
141
  ```
142
+
143
+ ### 4. Add FronteggAuthGuard to your routing module
144
+
145
+ Use the `FronteggAuthGuard` to redirect the user to the login page if the user not authenticated and trying to reach a private route.
146
+
147
+ ```ts
148
+ // app-routing.module.ts
149
+
116
150
  import { NgModule } from '@angular/core';
117
151
  import { Routes, RouterModule } from '@angular/router';
118
152
  import { ProtectedAppComponent } from './components/protected.component';
119
153
  import { NotFoundComponent } from './components/not-found.component';
154
+ import { HomeComponent } from './components/home.component';
155
+ import { UsersComponent } from './components/users.component';
120
156
  import { FronteggAuthGuard } from '@frontegg/angular';
121
157
 
122
158
  /** Option to protect a specific route **/
123
159
  const routes: Routes = [
124
- { path: '', component: EmptyAppComponent },
160
+ { path: '', component: HomeComponent },
125
161
  { path: 'test-private-route', canActivate: [FronteggAuthGuard], component: ProtectedAppComponent },
126
162
  { path: '**', component: NotFoundComponent },
127
163
  ]
@@ -140,8 +176,8 @@ const routes: Routes = [
140
176
  ]
141
177
 
142
178
  @NgModule({
179
+ declarations: [ProtectedAppComponent, HomeComponent, UsersComponent, NotFoundComponent],
143
180
  imports: [RouterModule.forRoot(routes)],
144
- providers: [],
145
181
  exports: [RouterModule],
146
182
  })
147
183
  export class AppRoutingModule {}
@@ -179,7 +215,7 @@ For Frontegg admin portal integration we will import the`FronteggAppService` fro
179
215
  use `showAdminPortal`
180
216
  method when clicking on the relevant button.
181
217
 
182
- ```
218
+ ```ts
183
219
  import { Component, OnInit } from '@angular/core';
184
220
  import { FronteggAppService } from '@frontegg/angular';
185
221
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontegg/angular",
3
- "version": "5.5.3-alpha.3224668504",
3
+ "version": "5.5.3-alpha.3288072955",
4
4
  "license": "MIT",
5
5
  "peerDependencies": {
6
6
  "@angular/common": ">=12.0.0",