-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
5,071 additions
and
946 deletions.
There are no files selected for viewing
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
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
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,27 @@ | ||
# See go/angularfire-releasing for details on the AngularFire release process. | ||
# If you need to trigger a release manually, be sure to use substitutions like so: | ||
# @canary `gcloud builds submit --substitutions=SHORT_SHA="9b0a0b0"` | ||
# @next `gcloud builds submit --substitutions=TAG_NAME="v1.2.3-rc.1"` | ||
# @latest `gcloud builds submit --substitutions=TAG_NAME="v1.2.3"` | ||
steps: | ||
- name: 'gcr.io/cloud-builders/yarn' | ||
entrypoint: 'bash' | ||
args: ["./tools/build.sh"] | ||
env: | ||
- 'TAG_NAME=$TAG_NAME' | ||
- 'SHORT_SHA=$SHORT_SHA' | ||
|
||
- name: 'gcr.io/cloud-builders/yarn' | ||
entrypoint: 'bash' | ||
args: ["./tools/test.sh"] | ||
|
||
- name: 'gcr.io/cloud-builders/npm' | ||
entrypoint: 'bash' | ||
env: ['TAG_NAME=$TAG_NAME'] | ||
args: ["./tools/release.sh"] | ||
secretEnv: ['NPM_TOKEN'] | ||
|
||
secrets: | ||
- kmsKeyName: projects/angularfire/locations/global/keyRings/cloud-build/cryptoKeys/cloud-build | ||
secretEnv: | ||
NPM_TOKEN: CiQAwtE8WoPa1sNqAQJZ1WMODuJooVmO6zihz2hAZOfUmDsgogUSTQCq8yp8qgltY+8jWpAR9GuS1JaVhd+fTVRilqLtdi2yXSdiDPTzLhZ+30bMlAOcoc0PxhCBn3JOpn8H1xshX+mG8yK7xog2Uq+CLVx/ |
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,102 @@ | ||
# Route users with AngularFire guards | ||
|
||
`AngularFireAuthGuard` provides a prebuilt [`canActivate` Router Guard](https://angular.io/api/router/CanActivate) using `AngularFireAuth`. By default unauthenticated users are not permitted to navigate to protected routes: | ||
|
||
```ts | ||
import { AngularFireAuthGuard } from '@angular/fire/auth-guard'; | ||
|
||
export const routes: Routes = [ | ||
{ path: '', component: AppComponent }, | ||
{ path: 'items', component: ItemListComponent, canActivate: [AngularFireAuthGuard] }, | ||
] | ||
``` | ||
|
||
## Customizing the behavior of `AngularFireAuthGuard` | ||
|
||
To customize the behavior of `AngularFireAuthGuard`, you can pass an RXJS pipe through the route data's `authGuardPipe` key. | ||
|
||
The `auth-guard` module provides the following pre-built pipes: | ||
|
||
| Exported pipe | Functionality | | ||
|-|-| | ||
| `loggedIn` | The default pipe, rejects if the user is not authenticated. | | ||
| `isNotAnonymous` | Rejects if the user is anonymous | | ||
| `emailVerified` | Rejects if the user's email is not verified | | ||
| `hasCustomClaim(claim)` | Rejects if the user does not have the specified claim | | ||
| `redirectUnauthorizedTo(redirect)` | Redirect unauthenticated users to a different route | | ||
| `redirectLoggedInTo(redirect)` | Redirect authenticated users to a different route | | ||
|
||
Example use: | ||
|
||
```ts | ||
import { AngularFireAuthGuard, hasCustomClaim, redirectUnauthorizedTo, redirectLoggedInTo } from '@angular/fire/auth-guard'; | ||
|
||
const adminOnly = hasCustomClaim('admin'); | ||
const redirectUnauthorizedToLogin = redirectUnauthorizedTo(['login']); | ||
const redirectLoggedInToItems = redirectLoggedInTo(['items']); | ||
const belongsToAccount = (next) => hasCustomClaim(`account-${next.params.id}`); | ||
|
||
export const routes: Routes = [ | ||
{ path: '', component: AppComponent }, | ||
{ path: 'login', component: LoginComponent, canActivate: [AngularFireAuthGuard], data: { authGuardPipe: redirectLoggedInToItems }}, | ||
{ path: 'items', component: ItemListComponent, canActivate: [AngularFireAuthGuard], data: { authGuardPipe: redirectUnauthorizedToLogin }, | ||
{ path: 'admin', component: AdminComponent, canActivate: [AngularFireAuthGuard], data: { authGuardPipe: adminOnly }}, | ||
{ path: 'accounts/:id', component: AdminComponent, canActivate: [AngularFireAuthGuard], data: { authGuardPipe: belongsToAccount }} | ||
]; | ||
``` | ||
Use the provided `canActivate` helper and spread syntax to make your routes more readable: | ||
```ts | ||
import { canActivate } from '@angular/fire/auth-guard'; | ||
|
||
export const routes: Routes = [ | ||
{ path: '', component: AppComponent }, | ||
{ path: 'login', component: LoginComponent, ...canActivate(redirectLoggedInToItems) }, | ||
{ path: 'items', component: ItemListComponent, ...canActivate(redirectUnauthorizedToLogin) }, | ||
{ path: 'admin', component: AdminComponent, ...canActivate(adminOnly) }, | ||
{ path: 'accounts/:id', component: AdminComponent, ...canActivate(belongsToAccount) } | ||
]; | ||
``` | ||
### Compose your own pipes | ||
`AngularFireAuthGuard` pipes are RXJS operators which transform an optional User to a boolean or Array (for redirects). You can build easily build your own to customize behavior further: | ||
```ts | ||
import { map } from 'rxjs/operators'; | ||
|
||
// This pipe redirects a user to their "profile edit" page or the "login page" if they're unauthenticated | ||
// { path: 'profile', ...canActivate(redirectToProfileEditOrLogin) } | ||
const redirectToProfileEditOrLogin = map(user => user ? ['profiles', user.uid, 'edit'] : ['login']); | ||
``` | ||
The `auth-guard` modules provides a `customClaims` operator to reduce boiler plate when checking a user's claims: | ||
```ts | ||
import { pipe } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { customClaims } from '@angular/fire/auth-guard'; | ||
|
||
// This pipe will only allow users with the editor role to access the route | ||
// { path: 'articles/:id/edit', component: ArticleEditComponent, ...canActivate(editorOnly) } | ||
const editorOnly = pipe(customClaims, map(claims => claims.role === "editor")); | ||
``` | ||
### Using router state | ||
`AngularFireAuthGuard` will also accept `AuthPipeGenerator`s which generate `AuthPipe`s given the router state: | ||
```ts | ||
import { pipe } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { customClaims } from '@angular/fire/auth-guard'; | ||
|
||
// Only allow navigation to the route if :userId matches the authenticated user's uid | ||
// { path: 'user/:userId/edit', component: ProfileEditComponent, ...canActivate(onlyAllowSelf) } | ||
const onlyAllowSelf = (next) => map(user => !!user && next.params.userId === user.uid); | ||
|
||
// Only allow navigation to the route if the user has a custom claim matching :accountId | ||
// { path: 'accounts/:accountId/billing', component: BillingDetailsComponent, ...canActivate(accountAdmin) } | ||
const accountAdmin = (next) => pipe(customClaims, map(claims => claims[`account-${next.params.accountId}-role`] === "admin")); | ||
``` |
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,66 @@ | ||
# Deploy your application on Firebase Hosting | ||
|
||
In this guide, we'll look at how to use `@angular/fire` to automatically deploy an Angular application to Firebase hosting by using the Angular CLI. | ||
|
||
## Step 1: add `@angular/fire` to your project | ||
|
||
First, you need to add the `@angular/fire` package to your project. In your Angular CLI project run: | ||
|
||
```shell | ||
ng add @angular/fire | ||
``` | ||
|
||
*Note that the command above assumes you have global Angular CLI installed. To install Angular CLI globally run `npm i -g @angular/cli`.* | ||
|
||
The command above will trigger the `@angular/fire` `ng-add` schematics. The schematics will open a web browser and guide you through the Firebase authentication flow (if you're not signed in already). After you authenticate, you'll see a prompt to select a Firebase hosting project. | ||
|
||
The schematics will do the following: | ||
|
||
- Add `@angular/fire` to your list of dependencies | ||
- Create `firebase.json`, `.firebaserc` files in the root of your workspace. You can use them to configure your firebase hosting deployment. Find more about them [here](https://firebase.google.com/docs/hosting/full-config) | ||
- Update your workspace file (`angular.json`) by inserting the `deploy` builder | ||
|
||
In the end, your `angular.json` project will look like below: | ||
|
||
```json | ||
{ | ||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json", | ||
"version": 1, | ||
"newProjectRoot": "projects", | ||
"projects": { | ||
"sample-app": { | ||
// ... | ||
"deploy": { | ||
"builder": "@angular/fire:deploy", | ||
"options": {} | ||
} | ||
} | ||
} | ||
// ... | ||
}, | ||
"defaultProject": "sample-app" | ||
} | ||
``` | ||
|
||
If you want to add deployment capabilities to a different project in your workspace, you can run: | ||
|
||
``` | ||
ng add @angular/fire --project=[PROJECT_NAME] | ||
``` | ||
|
||
## Step 2: deploying the project | ||
|
||
As the second step, to deploy your project run: | ||
|
||
``` | ||
ng run [ANGULAR_PROJECT_NAME]:deploy | ||
``` | ||
|
||
The command above will trigger: | ||
|
||
1. Production build of your application | ||
2. Deployment of the produced assets to the firebase hosting project you selected during `ng add` | ||
|
||
## Step 3: customization | ||
|
||
To customize the deployment flow, you can use the configuration files you're already familiar with from `firebase-tools`. You can find more in the [firebase documentation](https://firebase.google.com/docs/hosting/full-config). |
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.