-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1788 from timdeschryver/docs/v15-v16
add docs for migration v15-v16
- Loading branch information
Showing
1 changed file
with
197 additions
and
0 deletions.
There are no files selected for viewing
197 changes: 197 additions & 0 deletions
197
docs/site/angular-auth-oidc-client/docs/migrations/v15-to-v16.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
--- | ||
sidebar_position: 6 | ||
--- | ||
|
||
# Version 15 to 16 | ||
|
||
## TL;DR: Breaking Changes | ||
|
||
- Dropped support for Angular 14 | ||
- The guard `AutoLoginAllRoutesGuard` is deprecated in favor of `AutoLoginPartialRoutesGuard` | ||
|
||
## TL;DR: New Features | ||
|
||
- Add new standalone/functional API's | ||
|
||
## Dropped support for Angular 14 | ||
|
||
Angular 14 support is dropped because we want to introduce new standalone/functional methods to use this library (see below for more info). | ||
|
||
## The guard `AutoLoginAllRoutesGuard` is deprecated in favor of `AutoLoginPartialRoutesGuard` | ||
|
||
`AutoLoginAllRoutesGuard` is not recommended anymore and is marked as deprecated. | ||
The guard will be removed in a future version. | ||
|
||
Instead, use the `AutoLoginPartialRoutesGuard` guard. | ||
For information see [Why is AutoLoginAllRoutesGuard not recommended?](https://github.com/damienbod/angular-auth-oidc-client/issues/1549). | ||
|
||
Old: | ||
|
||
```ts | ||
import { AutoLoginAllRoutesGuard } from 'angular-auth-oidc-client'; | ||
|
||
const routes: Routes = [ | ||
{ | ||
path: 'protected', | ||
component: ProtectedComponent, | ||
canActivate: [AutoLoginAllRoutesGuard], // ⚠️ Using the deprecated AutoLoginAllRoutesGuard guard | ||
}, | ||
]; | ||
``` | ||
|
||
New: | ||
|
||
```ts | ||
import { AutoLoginPartialRoutesGuard } from 'angular-auth-oidc-client'; | ||
|
||
const routes: Routes = [ | ||
{ | ||
path: 'protected', | ||
component: ProtectedComponent, | ||
canActivate: [AutoLoginPartialRoutesGuard], // 👈 Using the recommended AutoLoginPartialRoutesGuard guards | ||
}, | ||
]; | ||
``` | ||
|
||
## Add new standalone/functional API's | ||
|
||
This library still supports using Angular Modules, but we included new API's if you want to make use of the standalone/functional API's that were introduced in Angular. | ||
|
||
To see this in action, you can also take a look at the [demo standalone application](https://github.com/damienbod/angular-auth-oidc-client/tree/main/projects/sample-code-flow-standalone). | ||
|
||
### Configuration | ||
|
||
Instead of using `AuthModule.forRoot({})`, you can now configure the auth module by using `provideAuth`. | ||
|
||
```ts | ||
import { NgModule } from '@angular/core'; | ||
import { AuthModule } from 'angular-auth-oidc-client'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
AuthModule.forRoot({ | ||
config: { | ||
/* Your config here */ | ||
}, | ||
}), | ||
], | ||
exports: [AuthModule], | ||
}) | ||
export class AuthConfigModule {} | ||
``` | ||
|
||
Becomes: | ||
|
||
```ts | ||
import { ApplicationConfig } from '@angular/core'; | ||
import { bootstrapApplication } from '@angular/platform-browser'; | ||
import { provideAuth } from 'angular-auth-oidc-client'; | ||
import { AppComponent } from './app/app.component'; | ||
|
||
export const appConfig: ApplicationConfig = { | ||
providers: [ | ||
// 👇 using provideAuth | ||
provideAuth({ | ||
config: { | ||
/* Your config here */ | ||
}, | ||
}), | ||
], | ||
}; | ||
|
||
bootstrapApplication(AppComponent, appConfig); | ||
``` | ||
|
||
### HTTP Interceptor | ||
|
||
Instead of registering the `AuthInterceptor` using the `HTTP_INTERCEPTORS` injection token, you can configure the HTTP client by including the `authInterceptor` interceptor. | ||
|
||
```ts | ||
import { AuthInterceptor, AuthModule } from 'angular-auth-oidc-client'; | ||
|
||
@NgModule({ | ||
// ... | ||
imports: [ | ||
// ... | ||
AuthModule.forRoot(), | ||
HttpClientModule, | ||
], | ||
providers: [ | ||
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }, | ||
// ... | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
Becomes: | ||
|
||
```ts | ||
import { ApplicationConfig } from '@angular/core'; | ||
import { bootstrapApplication } from '@angular/platform-browser'; | ||
import { provideHttpClient, withInterceptors } from '@angular/common/http'; | ||
import { provideAuth, authInterceptor } from 'angular-auth-oidc-client'; | ||
import { AppComponent } from './app/app.component'; | ||
|
||
export const appConfig: ApplicationConfig = { | ||
providers: [ | ||
// 👇 using authInterceptor | ||
provideHttpClient(withInterceptors([authInterceptor()])), | ||
provideAuth({ | ||
config: { | ||
/* Your config here */ | ||
}, | ||
}), | ||
], | ||
}; | ||
|
||
bootstrapApplication(AppComponent, appConfig); | ||
``` | ||
|
||
### Guards | ||
|
||
Instead of protecting your routes using the class-based guard `AutoLoginPartialRoutesGuard`, you can now use the `autoLoginPartialRoutesGuard` functional guard. | ||
|
||
Note there's no `autoLoginAllRoutesGuard` because its class-based version is deprecated. | ||
|
||
```ts | ||
import { RouterModule, Routes } from '@angular/router'; | ||
import { AutoLoginPartialRoutesGuard } from 'angular-auth-oidc-client'; | ||
import { ProtectedComponent } from './protected/protected.component'; | ||
|
||
const appRoutes: Routes = [ | ||
{ | ||
path: 'protected', | ||
component: ProtectedComponent, | ||
canActivate: [AutoLoginPartialRoutesGuard], | ||
}, | ||
{ | ||
path: 'customers', | ||
loadChildren: () => import('./customers/customers.module').then((m) => m.CustomersModule), | ||
canLoad: [AutoLoginPartialRoutesGuard], | ||
}, | ||
]; | ||
``` | ||
|
||
Becomes: | ||
|
||
```ts | ||
import { RouterModule, Routes } from '@angular/router'; | ||
import { AutoLoginPartialRoutesGuard } from 'angular-auth-oidc-client'; | ||
import { ProtectedComponent } from './protected/protected.component'; | ||
|
||
const appRoutes: Routes = [ | ||
{ | ||
path: 'protected', | ||
component: ProtectedComponent, | ||
// 👇 using autoLoginPartialRoutesGuard | ||
canActivate: [autoLoginPartialRoutesGuard], | ||
}, | ||
{ | ||
path: 'customers', | ||
loadChildren: () => import('./customers/customers.routes').then((m) => m.routes), | ||
// 👇 using autoLoginPartialRoutesGuard | ||
canMatch: [autoLoginPartialRoutesGuard], | ||
}, | ||
]; | ||
``` |