├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e ├── app.e2e-spec.ts ├── app.po.ts └── tsconfig.e2e.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── protractor.conf.js ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.ts │ ├── app.module.ts │ ├── auth │ │ ├── auth.guard.ts │ │ ├── auth.module.ts │ │ └── auth.service.ts │ ├── callback.component.ts │ ├── comments │ │ ├── comment.ts │ │ ├── comments.module.ts │ │ └── comments │ │ │ ├── comment-form │ │ │ ├── comment-form.component.html │ │ │ └── comment-form.component.ts │ │ │ ├── comments.component.css │ │ │ ├── comments.component.html │ │ │ └── comments.component.ts │ ├── core │ │ ├── api.service.ts │ │ ├── core.module.ts │ │ ├── dog-detail.ts │ │ ├── dog.ts │ │ ├── error.component.ts │ │ ├── header │ │ │ ├── header.component.html │ │ │ └── header.component.ts │ │ └── loading.component.ts │ ├── dog │ │ ├── dog.module.ts │ │ └── dog │ │ │ ├── dog.component.html │ │ │ └── dog.component.ts │ └── dogs │ │ ├── dogs.module.ts │ │ └── dogs │ │ ├── dogs.component.html │ │ └── dogs.component.ts ├── assets │ ├── .gitkeep │ └── images │ │ └── loading.svg ├── environments │ ├── environment.prod.ts │ └── environment.ts.example ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts ├── styles.css ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── typings.d.ts ├── tsconfig.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | environment.ts 4 | 5 | # compiled output 6 | /dist 7 | /tmp 8 | /out-tsc 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # IDEs and editors 14 | /.idea 15 | .project 16 | .classpath 17 | .c9/ 18 | *.launch 19 | .settings/ 20 | *.sublime-workspace 21 | 22 | # IDE - VSCode 23 | .vscode/* 24 | !.vscode/settings.json 25 | !.vscode/tasks.json 26 | !.vscode/launch.json 27 | !.vscode/extensions.json 28 | 29 | # misc 30 | /.sass-cache 31 | /connect.lock 32 | /coverage 33 | /libpeerconnection.log 34 | npm-debug.log 35 | testem.log 36 | /typings 37 | 38 | # e2e 39 | /e2e/*.js 40 | /e2e/*.map 41 | 42 | # System Files 43 | .DS_Store 44 | Thumbs.db 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # angular-firebase 2 | 3 | Follow this tutorial to learn how to authenticate a Node.js server and Angular app with Cloud Firestore database using Auth0: [How to Authenticate Firebase and Angular with Auth0](https://auth0.com/blog/how-to-authenticate-firebase-and-angular-with-auth0-part-1/). 4 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "ng-firebase": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "architect": { 11 | "build": { 12 | "builder": "@angular-devkit/build-angular:browser", 13 | "options": { 14 | "outputPath": "dist", 15 | "index": "src/index.html", 16 | "main": "src/main.ts", 17 | "tsConfig": "src/tsconfig.app.json", 18 | "polyfills": "src/polyfills.ts", 19 | "assets": [ 20 | "src/assets", 21 | "src/favicon.ico" 22 | ], 23 | "styles": [ 24 | "src/styles.css" 25 | ], 26 | "scripts": [] 27 | }, 28 | "configurations": { 29 | "production": { 30 | "optimization": true, 31 | "outputHashing": "all", 32 | "sourceMap": false, 33 | "extractCss": true, 34 | "namedChunks": false, 35 | "aot": true, 36 | "extractLicenses": true, 37 | "vendorChunk": false, 38 | "buildOptimizer": true, 39 | "fileReplacements": [ 40 | { 41 | "replace": "src/environments/environment.ts", 42 | "with": "src/environments/environment.prod.ts" 43 | } 44 | ] 45 | } 46 | } 47 | }, 48 | "serve": { 49 | "builder": "@angular-devkit/build-angular:dev-server", 50 | "options": { 51 | "browserTarget": "ng-firebase:build" 52 | }, 53 | "configurations": { 54 | "production": { 55 | "browserTarget": "ng-firebase:build:production" 56 | } 57 | } 58 | }, 59 | "extract-i18n": { 60 | "builder": "@angular-devkit/build-angular:extract-i18n", 61 | "options": { 62 | "browserTarget": "ng-firebase:build" 63 | } 64 | }, 65 | "test": { 66 | "builder": "@angular-devkit/build-angular:karma", 67 | "options": { 68 | "main": "src/test.ts", 69 | "karmaConfig": "./karma.conf.js", 70 | "polyfills": "src/polyfills.ts", 71 | "tsConfig": "src/tsconfig.spec.json", 72 | "scripts": [], 73 | "styles": [ 74 | "src/styles.css" 75 | ], 76 | "assets": [ 77 | "src/assets", 78 | "src/favicon.ico" 79 | ] 80 | } 81 | }, 82 | "lint": { 83 | "builder": "@angular-devkit/build-angular:tslint", 84 | "options": { 85 | "tsConfig": [ 86 | "src/tsconfig.app.json", 87 | "src/tsconfig.spec.json" 88 | ], 89 | "exclude": [ 90 | "**/node_modules/**" 91 | ] 92 | } 93 | } 94 | } 95 | }, 96 | "ng-firebase-e2e": { 97 | "root": "e2e", 98 | "sourceRoot": "e2e", 99 | "projectType": "application", 100 | "architect": { 101 | "e2e": { 102 | "builder": "@angular-devkit/build-angular:protractor", 103 | "options": { 104 | "protractorConfig": "./protractor.conf.js", 105 | "devServerTarget": "ng-firebase:serve" 106 | } 107 | }, 108 | "lint": { 109 | "builder": "@angular-devkit/build-angular:tslint", 110 | "options": { 111 | "tsConfig": [ 112 | "e2e/tsconfig.e2e.json" 113 | ], 114 | "exclude": [ 115 | "**/node_modules/**" 116 | ] 117 | } 118 | } 119 | } 120 | } 121 | }, 122 | "defaultProject": "ng-firebase", 123 | "schematics": { 124 | "@schematics/angular:class": { 125 | "spec": false 126 | }, 127 | "@schematics/angular:component": { 128 | "spec": false, 129 | "prefix": "app", 130 | "styleext": "css" 131 | }, 132 | "@schematics/angular:directive": { 133 | "spec": false, 134 | "prefix": "app" 135 | }, 136 | "@schematics/angular:guard": { 137 | "spec": false 138 | }, 139 | "@schematics/angular:module": { 140 | "spec": false 141 | }, 142 | "@schematics/angular:pipe": { 143 | "spec": false 144 | }, 145 | "@schematics/angular:service": { 146 | "spec": false 147 | } 148 | } 149 | } -------------------------------------------------------------------------------- /e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('ng-firebase App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to app!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "jasminewd2", 11 | "node" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ], 20 | fixWebpackSourcePaths: true 21 | }, 22 | 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng-firebase", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "6.1.8", 16 | "@angular/common": "6.1.8", 17 | "@angular/compiler": "6.1.8", 18 | "@angular/core": "6.1.8", 19 | "@angular/fire": "^5.0.2", 20 | "@angular/forms": "6.1.8", 21 | "@angular/http": "6.1.8", 22 | "@angular/platform-browser": "6.1.8", 23 | "@angular/platform-browser-dynamic": "6.1.8", 24 | "@angular/router": "6.1.8", 25 | "auth0-js": "^9.7.3", 26 | "core-js": "^2.4.1", 27 | "firebase": "^5.5.1", 28 | "rxjs": "^6.3.2", 29 | "zone.js": "^0.8.20" 30 | }, 31 | "devDependencies": { 32 | "@angular-devkit/build-angular": "~0.8.0", 33 | "@angular-devkit/core": "^0.3.2", 34 | "@angular-devkit/schematics": "^0.3.2", 35 | "@angular/cli": "^6.2.3", 36 | "@angular/compiler-cli": "6.1.8", 37 | "@angular/language-service": "6.1.8", 38 | "@types/jasmine": "~2.5.53", 39 | "@types/jasminewd2": "~2.0.2", 40 | "@types/node": "~6.0.60", 41 | "ajv": "^6.1.1", 42 | "codelyzer": "^4.0.1", 43 | "jasmine-core": "~2.6.2", 44 | "jasmine-spec-reporter": "~4.1.0", 45 | "karma": "~1.7.0", 46 | "karma-chrome-launcher": "~2.1.1", 47 | "karma-cli": "~1.0.1", 48 | "karma-coverage-istanbul-reporter": "^1.2.1", 49 | "karma-jasmine": "~1.1.0", 50 | "karma-jasmine-html-reporter": "^0.2.2", 51 | "protractor": "^5.4.1", 52 | "ts-node": "~3.2.0", 53 | "tslint": "~5.7.0", 54 | "typescript": "2.9.2" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './e2e/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { CallbackComponent } from './callback.component'; 4 | import { AuthGuard } from './auth/auth.guard'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: '', 9 | loadChildren: './dogs/dogs.module#DogsModule', 10 | pathMatch: 'full' 11 | }, 12 | { 13 | path: 'dog', 14 | loadChildren: './dog/dog.module#DogModule', 15 | canActivate: [ 16 | AuthGuard 17 | ] 18 | }, 19 | { 20 | path: 'callback', 21 | component: CallbackComponent 22 | } 23 | ]; 24 | 25 | @NgModule({ 26 | imports: [RouterModule.forRoot(routes)], 27 | exports: [RouterModule] 28 | }) 29 | export class AppRoutingModule { } 30 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styles: [] 7 | }) 8 | export class AppComponent { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { AppRoutingModule } from './app-routing.module'; 4 | import { AuthModule } from './auth/auth.module'; 5 | import { CoreModule } from './core/core.module'; 6 | import { CommentsModule } from './comments/comments.module'; 7 | import { AppComponent } from './app.component'; 8 | import { CallbackComponent } from './callback.component'; 9 | 10 | @NgModule({ 11 | declarations: [ 12 | AppComponent, 13 | CallbackComponent 14 | ], 15 | imports: [ 16 | BrowserModule, 17 | AppRoutingModule, 18 | AuthModule.forRoot(), 19 | CoreModule.forRoot(), 20 | CommentsModule 21 | ], 22 | bootstrap: [AppComponent] 23 | }) 24 | export class AppModule { } 25 | -------------------------------------------------------------------------------- /src/app/auth/auth.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; 3 | import { Observable } from 'rxjs'; 4 | import { AuthService } from './auth.service'; 5 | 6 | @Injectable() 7 | export class AuthGuard implements CanActivate { 8 | 9 | constructor(private auth: AuthService) { } 10 | 11 | canActivate( 12 | next: ActivatedRouteSnapshot, 13 | state: RouterStateSnapshot): Observable | Promise | boolean { 14 | if (this.auth.loggedIn) { 15 | return true; 16 | } else { 17 | // Send guarded route to redirect after logging in 18 | this.auth.login(state.url); 19 | return false; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/app/auth/auth.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, ModuleWithProviders } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { AuthService } from './auth.service'; 4 | import { AuthGuard } from './auth.guard'; 5 | import { AngularFireAuthModule } from '@angular/fire/auth'; 6 | 7 | @NgModule({ 8 | imports: [ 9 | CommonModule, 10 | AngularFireAuthModule 11 | ] 12 | }) 13 | export class AuthModule { 14 | static forRoot(): ModuleWithProviders { 15 | return { 16 | ngModule: AuthModule, 17 | providers: [ 18 | AuthService, 19 | AuthGuard 20 | ] 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/app/auth/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { environment } from './../../environments/environment'; 4 | import * as auth0 from 'auth0-js'; 5 | import { AngularFireAuth } from '@angular/fire/auth'; 6 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 7 | import { Subscription, of, timer } from 'rxjs'; 8 | import { mergeMap } from 'rxjs/operators'; 9 | 10 | @Injectable() 11 | export class AuthService { 12 | // Create Auth0 web auth instance 13 | private _auth0 = new auth0.WebAuth({ 14 | clientID: environment.auth.clientId, 15 | domain: environment.auth.clientDomain, 16 | responseType: 'token', 17 | redirectUri: environment.auth.redirect, 18 | audience: environment.auth.audience, 19 | scope: environment.auth.scope 20 | }); 21 | accessToken: string; 22 | userProfile: any; 23 | // Track authentication status 24 | loggedIn: boolean; 25 | loading: boolean; 26 | // Track Firebase authentication status 27 | loggedInFirebase: boolean; 28 | // Subscribe to the Firebase token stream 29 | firebaseSub: Subscription; 30 | // Subscribe to Firebase renewal timer stream 31 | refreshFirebaseSub: Subscription; 32 | 33 | constructor( 34 | private router: Router, 35 | private afAuth: AngularFireAuth, 36 | private http: HttpClient 37 | ) {} 38 | 39 | login(redirect?: string) { 40 | // Set redirect after login 41 | const _redirect = redirect ? redirect : this.router.url; 42 | localStorage.setItem('auth_redirect', _redirect); 43 | // Auth0 authorize request 44 | this._auth0.authorize(); 45 | } 46 | 47 | handleLoginCallback() { 48 | this.loading = true; 49 | // When Auth0 hash parsed, get profile 50 | this._auth0.parseHash((err, authResult) => { 51 | if (authResult && authResult.accessToken) { 52 | window.location.hash = ''; 53 | // Store access token 54 | this.accessToken = authResult.accessToken; 55 | // Get user info: set up session, get Firebase token 56 | this.getUserInfo(authResult); 57 | } else if (err) { 58 | this.router.navigate(['/']); 59 | this.loading = false; 60 | console.error(`Error authenticating: ${err.error}`); 61 | } 62 | }); 63 | } 64 | 65 | getUserInfo(authResult) { 66 | // Use access token to retrieve user's profile and set session 67 | this._auth0.client.userInfo(this.accessToken, (err, profile) => { 68 | if (profile) { 69 | this._setSession(authResult, profile); 70 | } else if (err) { 71 | console.warn(`Error retrieving profile: ${err.error}`); 72 | } 73 | }); 74 | } 75 | 76 | private _setSession(authResult, profile) { 77 | // Set tokens and expiration in localStorage 78 | const expiresAt = JSON.stringify((authResult.expiresIn * 1000) + Date.now()); 79 | localStorage.setItem('expires_at', expiresAt); 80 | this.userProfile = profile; 81 | // Session set; set loggedIn and loading 82 | this.loggedIn = true; 83 | this.loading = false; 84 | // Get Firebase token 85 | this._getFirebaseToken(); 86 | // Redirect to desired route 87 | this.router.navigateByUrl(localStorage.getItem('auth_redirect')); 88 | } 89 | 90 | private _getFirebaseToken() { 91 | // Prompt for login if no access token 92 | if (!this.accessToken) { 93 | this.login(); 94 | } 95 | const getToken$ = () => { 96 | return this.http 97 | .get(`${environment.apiRoot}auth/firebase`, { 98 | headers: new HttpHeaders().set('Authorization', `Bearer ${this.accessToken}`) 99 | }); 100 | }; 101 | this.firebaseSub = getToken$().subscribe( 102 | res => this._firebaseAuth(res), 103 | err => console.error(`An error occurred fetching Firebase token: ${err.message}`) 104 | ); 105 | } 106 | 107 | private _firebaseAuth(tokenObj) { 108 | this.afAuth.auth.signInWithCustomToken(tokenObj.firebaseToken) 109 | .then(res => { 110 | this.loggedInFirebase = true; 111 | // Schedule token renewal 112 | this.scheduleFirebaseRenewal(); 113 | console.log('Successfully authenticated with Firebase!'); 114 | }) 115 | .catch(err => { 116 | const errorCode = err.code; 117 | const errorMessage = err.message; 118 | console.error(`${errorCode} Could not log into Firebase: ${errorMessage}`); 119 | this.loggedInFirebase = false; 120 | }); 121 | } 122 | 123 | scheduleFirebaseRenewal() { 124 | // If user isn't authenticated, check for Firebase subscription 125 | // and unsubscribe, then return (don't schedule renewal) 126 | if (!this.loggedInFirebase) { 127 | if (this.firebaseSub) { 128 | this.firebaseSub.unsubscribe(); 129 | } 130 | return; 131 | } 132 | // Unsubscribe from previous expiration observable 133 | this.unscheduleFirebaseRenewal(); 134 | // Create and subscribe to expiration observable 135 | // Custom Firebase tokens minted by Firebase 136 | // expire after 3600 seconds (1 hour) 137 | const expiresAt = new Date().getTime() + (3600 * 1000); 138 | const expiresIn$ = of(expiresAt) 139 | .pipe( 140 | mergeMap( 141 | expires => { 142 | const now = Date.now(); 143 | // Use timer to track delay until expiration 144 | // to run the refresh at the proper time 145 | return timer(Math.max(1, expires - now)); 146 | } 147 | ) 148 | ); 149 | 150 | this.refreshFirebaseSub = expiresIn$ 151 | .subscribe( 152 | () => { 153 | console.log('Firebase token expired; fetching a new one'); 154 | this._getFirebaseToken(); 155 | } 156 | ); 157 | } 158 | 159 | unscheduleFirebaseRenewal() { 160 | if (this.refreshFirebaseSub) { 161 | this.refreshFirebaseSub.unsubscribe(); 162 | } 163 | } 164 | 165 | logout() { 166 | // Ensure all auth items removed 167 | localStorage.removeItem('expires_at'); 168 | localStorage.removeItem('auth_redirect'); 169 | this.accessToken = undefined; 170 | this.userProfile = undefined; 171 | this.loggedIn = false; 172 | // Sign out of Firebase 173 | this.loggedInFirebase = false; 174 | this.afAuth.auth.signOut(); 175 | // Return to homepage 176 | this.router.navigate(['/']); 177 | } 178 | 179 | get tokenValid(): boolean { 180 | // Check if current time is past access token's expiration 181 | const expiresAt = JSON.parse(localStorage.getItem('expires_at')); 182 | return Date.now() < expiresAt; 183 | } 184 | 185 | } 186 | -------------------------------------------------------------------------------- /src/app/callback.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { AuthService } from './auth/auth.service'; 3 | 4 | @Component({ 5 | selector: 'app-callback', 6 | template: ` 7 | 8 | ` 9 | }) 10 | export class CallbackComponent implements OnInit { 11 | 12 | constructor(private auth: AuthService) { } 13 | 14 | ngOnInit() { 15 | this.auth.handleLoginCallback(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/app/comments/comment.ts: -------------------------------------------------------------------------------- 1 | export class Comment { 2 | constructor( 3 | public user: string, 4 | public uid: string, 5 | public picture: string, 6 | public text: string, 7 | public timestamp: number 8 | ) {} 9 | 10 | // Workaround because Firestore won't accept class instances 11 | // as data when adding documents; must unwrap instance to save. 12 | // See: https://github.com/firebase/firebase-js-sdk/issues/311 13 | public get getObj(): object { 14 | const result = {}; 15 | Object.keys(this).map(key => result[key] = this[key]); 16 | return result; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/app/comments/comments.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { CoreModule } from '../core/core.module'; 4 | import { environment } from './../../environments/environment'; 5 | import { AngularFireModule } from '@angular/fire'; 6 | import { AngularFirestoreModule } from '@angular/fire/firestore'; 7 | import { CommentsComponent } from './comments/comments.component'; 8 | import { CommentFormComponent } from './comments/comment-form/comment-form.component'; 9 | 10 | @NgModule({ 11 | imports: [ 12 | CommonModule, 13 | CoreModule, // Access FormsModule, Loading, and Error components 14 | AngularFireModule.initializeApp(environment.firebase), 15 | AngularFirestoreModule 16 | ], 17 | declarations: [ 18 | CommentsComponent, 19 | CommentFormComponent 20 | ], 21 | exports: [ 22 | CommentsComponent 23 | ] 24 | }) 25 | export class CommentsModule { } 26 | -------------------------------------------------------------------------------- /src/app/comments/comments/comment-form/comment-form.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 10 | 13 |
14 |
15 | -------------------------------------------------------------------------------- /src/app/comments/comments/comment-form/comment-form.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Output, EventEmitter } from '@angular/core'; 2 | import { Comment } from './../../comment'; 3 | import { AuthService } from '../../../auth/auth.service'; 4 | 5 | @Component({ 6 | selector: 'app-comment-form', 7 | templateUrl: './comment-form.component.html' 8 | }) 9 | export class CommentFormComponent implements OnInit { 10 | @Output() postComment = new EventEmitter(); 11 | commentForm: Comment; 12 | 13 | constructor(private auth: AuthService) { } 14 | 15 | ngOnInit() { 16 | this._newComment(); 17 | } 18 | 19 | private _newComment() { 20 | this.commentForm = new Comment( 21 | this.auth.userProfile.name, 22 | this.auth.userProfile.sub, 23 | this.auth.userProfile.picture, 24 | '', 25 | null); 26 | } 27 | 28 | onSubmit() { 29 | this.commentForm.timestamp = new Date().getTime(); 30 | this.postComment.emit(this.commentForm); 31 | this._newComment(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/app/comments/comments/comments.component.css: -------------------------------------------------------------------------------- 1 | .avatar { 2 | display: inline-block; 3 | height: 30px; 4 | } 5 | .comment-text { 6 | background: #eee; 7 | position: relative; 8 | } 9 | .comment-text::before { 10 | border-bottom: 10px solid #eee; 11 | border-left: 6px solid transparent; 12 | border-right: 6px solid transparent; 13 | content: ''; 14 | display: block; 15 | height: 1px; 16 | position: absolute; 17 | top: -10px; left: 9px; 18 | width: 1px; 19 | } 20 | -------------------------------------------------------------------------------- /src/app/comments/comments/comments.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Comments

3 | 4 | 5 |

6 | Loading comments... 7 |

8 | 9 |
10 | 11 |
12 |
    13 |
  • 14 |
    15 |
    16 | 17 | {{ comment.user }} 18 | {{ comment.timestamp | date:'short' }} 19 | 20 | × 25 | 26 |
    27 |
    28 |
    29 |
    30 |

    31 |
    32 |
    33 |
  • 34 |
35 | 36 |
37 | 38 |
39 | 40 | 41 |

42 | Please log in to leave a comment. 43 |

44 |
45 |
46 |
47 | -------------------------------------------------------------------------------- /src/app/comments/comments/comments.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument } from '@angular/fire/firestore'; 3 | import { throwError, Observable } from 'rxjs'; 4 | import { map, catchError } from 'rxjs/operators'; 5 | import { Comment } from './../comment'; 6 | import { AuthService } from '../../auth/auth.service'; 7 | 8 | @Component({ 9 | selector: 'app-comments', 10 | templateUrl: './comments.component.html', 11 | styleUrls: ['./comments.component.css'] 12 | }) 13 | export class CommentsComponent { 14 | private _commentsCollection: AngularFirestoreCollection; 15 | comments$: Observable; 16 | loading = true; 17 | error: boolean; 18 | 19 | constructor( 20 | private afs: AngularFirestore, 21 | public auth: AuthService 22 | ) { 23 | // Get latest 15 comments from Firestore, ordered by timestamp 24 | this._commentsCollection = afs.collection( 25 | 'comments', 26 | ref => ref.orderBy('timestamp').limit(15) 27 | ); 28 | // Set up observable of comments 29 | this.comments$ = this._commentsCollection.snapshotChanges() 30 | .pipe( 31 | map(res => this._onNext(res)), 32 | catchError((err, caught) => this._onError(err, caught)) 33 | ); 34 | } 35 | 36 | private _onNext(res) { 37 | this.loading = false; 38 | this.error = false; 39 | // Add Firestore ID to comments 40 | // The ID is necessary to delete specific comments 41 | return res.map(action => { 42 | const data = action.payload.doc.data() as Comment; 43 | const id = action.payload.doc.id; 44 | return { id, ...data }; 45 | }); 46 | } 47 | 48 | private _onError(err, caught): Observable { 49 | this.loading = false; 50 | this.error = true; 51 | return throwError('An error occurred while retrieving comments.'); 52 | } 53 | 54 | onPostComment(comment: Comment) { 55 | // Unwrap the Comment instance to an object for Firestore 56 | // See https://github.com/firebase/firebase-js-sdk/issues/311 57 | const commentObj = comment.getObj; 58 | this._commentsCollection.add(commentObj); 59 | } 60 | 61 | canDeleteComment(uid: string): boolean { 62 | if (!this.auth.loggedInFirebase || !this.auth.userProfile) { 63 | return false; 64 | } 65 | return uid === this.auth.userProfile.sub; 66 | } 67 | 68 | deleteComment(id: string) { 69 | // Delete comment with confirmation prompt first 70 | if (window.confirm('Are you sure you want to delete your comment?')) { 71 | const thisDoc: AngularFirestoreDocument = this.afs.doc(`comments/${id}`); 72 | thisDoc.delete(); 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/app/core/api.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http'; 3 | import { environment } from './../../environments/environment'; 4 | import { AuthService } from './../auth/auth.service'; 5 | import { Observable, throwError } from 'rxjs'; 6 | import { catchError } from 'rxjs/operators'; 7 | import { Dog } from './../core/dog'; 8 | import { DogDetail } from './../core/dog-detail'; 9 | 10 | @Injectable() 11 | export class ApiService { 12 | private _API = `${environment.apiRoot}api`; 13 | 14 | constructor( 15 | private http: HttpClient, 16 | private auth: AuthService) { } 17 | 18 | getDogs$(): Observable { 19 | return this.http 20 | .get(`${this._API}/dogs`) 21 | .pipe( 22 | catchError((err, caught) => this._onError(err, caught)) 23 | ); 24 | } 25 | 26 | getDogByRank$(rank: number): Observable { 27 | return this.http 28 | .get(`${this._API}/dog/${rank}`, { 29 | headers: new HttpHeaders().set('Authorization', `Bearer ${this.auth.accessToken}`) 30 | }) 31 | .pipe( 32 | catchError((err, caught) => this._onError(err, caught)) 33 | ); 34 | } 35 | 36 | private _onError(err, caught) { 37 | let errorMsg = 'Error: Unable to complete request.'; 38 | if (err instanceof HttpErrorResponse) { 39 | errorMsg = err.message; 40 | if (err.status === 401 || errorMsg.indexOf('No JWT') > -1 || errorMsg.indexOf('Unauthorized') > -1) { 41 | this.auth.login(); 42 | } 43 | } 44 | return throwError(errorMsg); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/app/core/core.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, ModuleWithProviders } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { HttpClientModule } from '@angular/common/http'; 4 | import { FormsModule } from '@angular/forms'; 5 | import { RouterModule } from '@angular/router'; 6 | import { Title } from '@angular/platform-browser'; 7 | import { DatePipe } from '@angular/common'; 8 | import { HeaderComponent } from './header/header.component'; 9 | import { ApiService } from './api.service'; 10 | import { LoadingComponent } from './loading.component'; 11 | import { ErrorComponent } from './error.component'; 12 | 13 | @NgModule({ 14 | imports: [ 15 | CommonModule, 16 | RouterModule, 17 | HttpClientModule, // AuthModule is a sibling and can use this without us exporting it 18 | FormsModule 19 | ], 20 | declarations: [ 21 | HeaderComponent, 22 | LoadingComponent, 23 | ErrorComponent 24 | ], 25 | exports: [ 26 | FormsModule, // Export FormsModule so CommentsModule can use it 27 | HeaderComponent, 28 | LoadingComponent, 29 | ErrorComponent 30 | ] 31 | }) 32 | export class CoreModule { 33 | static forRoot(): ModuleWithProviders { 34 | return { 35 | ngModule: CoreModule, 36 | providers: [ 37 | Title, 38 | DatePipe, 39 | ApiService 40 | ] 41 | }; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/app/core/dog-detail.ts: -------------------------------------------------------------------------------- 1 | export interface DogDetail { 2 | breed: string; 3 | rank: number; 4 | description: string; 5 | personality: string; 6 | energy: string; 7 | group: string; 8 | image: string; 9 | link: string; 10 | } 11 | -------------------------------------------------------------------------------- /src/app/core/dog.ts: -------------------------------------------------------------------------------- 1 | export interface Dog { 2 | breed: string; 3 | rank: number; 4 | image: string; 5 | } 6 | -------------------------------------------------------------------------------- /src/app/core/error.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-error', 5 | template: ` 6 |

7 | Error: There was an error retrieving data. 8 |

9 | ` 10 | }) 11 | export class ErrorComponent { 12 | } 13 | -------------------------------------------------------------------------------- /src/app/core/header/header.component.html: -------------------------------------------------------------------------------- 1 | 24 | -------------------------------------------------------------------------------- /src/app/core/header/header.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | import { AuthService } from '../../auth/auth.service'; 3 | 4 | @Component({ 5 | selector: 'app-header', 6 | templateUrl: './header.component.html', 7 | styles: [` 8 | img { 9 | border-radius: 100px; 10 | width: 30px; 11 | } 12 | .loading { line-height: 31px; } 13 | .home-link { color: #212529; } 14 | .home-link:hover { text-decoration: none; } 15 | `] 16 | }) 17 | export class HeaderComponent { 18 | 19 | constructor(public auth: AuthService) {} 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/app/core/loading.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-loading', 5 | template: ` 6 |
7 | 8 |
9 | `, 10 | styles: [` 11 | .inline { 12 | display: inline-block; 13 | } 14 | img { 15 | height: 80px; 16 | width: 80px; 17 | } 18 | .inline img { 19 | height: 24px; 20 | width: 24px; 21 | } 22 | `] 23 | }) 24 | export class LoadingComponent { 25 | @Input() inline: boolean; 26 | } 27 | -------------------------------------------------------------------------------- /src/app/dog/dog.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { Routes, RouterModule } from '@angular/router'; 4 | import { CoreModule } from '../core/core.module'; 5 | import { DogComponent } from './dog/dog.component'; 6 | 7 | const DOG_ROUTES: Routes = [ 8 | { 9 | path: ':rank', 10 | component: DogComponent 11 | } 12 | ]; 13 | 14 | @NgModule({ 15 | imports: [ 16 | CommonModule, 17 | CoreModule, 18 | RouterModule.forChild(DOG_ROUTES) 19 | ], 20 | declarations: [ 21 | DogComponent 22 | ] 23 | }) 24 | export class DogModule { } 25 | -------------------------------------------------------------------------------- /src/app/dog/dog/dog.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |

{{ getPageTitle(dog) }}

8 |
9 |
10 |
13 |
14 |
    15 |
  • Group: {{ dog.group }}
  • 16 |
  • Personality: {{ dog.personality }}
  • 17 |
  • Energy Level: {{ dog.energy }}
  • 18 |
19 |
20 |
21 |
22 |

23 |

24 | ← Back 25 | {{ dog.breed }} AKC Info 29 |

30 |
31 |
32 |
33 | -------------------------------------------------------------------------------- /src/app/dog/dog/dog.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | import { Title } from '@angular/platform-browser'; 4 | import { ApiService } from '../../core/api.service'; 5 | import { DogDetail } from './../../core/dog-detail'; 6 | import { throwError, Subscription, Observable } from 'rxjs'; 7 | import { tap, catchError } from 'rxjs/operators'; 8 | 9 | @Component({ 10 | selector: 'app-dog', 11 | templateUrl: './dog.component.html', 12 | styles: [` 13 | .dog-photo { 14 | background-repeat: no-repeat; 15 | background-position: 50% 50%; 16 | background-size: cover; 17 | min-height: 250px; 18 | width: 100%; 19 | } 20 | `] 21 | }) 22 | export class DogComponent implements OnInit, OnDestroy { 23 | paramSub: Subscription; 24 | dog$: Observable; 25 | loading = true; 26 | error: boolean; 27 | 28 | constructor( 29 | private route: ActivatedRoute, 30 | private api: ApiService, 31 | private title: Title 32 | ) { } 33 | 34 | ngOnInit() { 35 | this.paramSub = this.route.params 36 | .subscribe( 37 | params => { 38 | this.dog$ = this.api.getDogByRank$(params.rank).pipe( 39 | tap(val => this._onNext(val)), 40 | catchError((err, caught) => this._onError(err, caught)) 41 | ); 42 | } 43 | ); 44 | } 45 | 46 | private _onNext(val: DogDetail) { 47 | this.loading = false; 48 | } 49 | 50 | private _onError(err, caught): Observable { 51 | this.loading = false; 52 | this.error = true; 53 | return throwError('An error occurred fetching detail data for this dog.'); 54 | } 55 | 56 | getPageTitle(dog: DogDetail): string { 57 | const pageTitle = `#${dog.rank}: ${dog.breed}`; 58 | this.title.setTitle(pageTitle); 59 | return pageTitle; 60 | } 61 | 62 | getImgStyle(url: string) { 63 | return `url(${url})`; 64 | } 65 | 66 | ngOnDestroy() { 67 | this.paramSub.unsubscribe(); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/app/dogs/dogs.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { Routes, RouterModule } from '@angular/router'; 4 | import { CoreModule } from '../core/core.module'; 5 | import { CommentsModule } from '../comments/comments.module'; 6 | import { DogsComponent } from './dogs/dogs.component'; 7 | 8 | const DOGS_ROUTES: Routes = [ 9 | { 10 | path: '', 11 | component: DogsComponent 12 | } 13 | ]; 14 | 15 | @NgModule({ 16 | imports: [ 17 | CommonModule, 18 | CoreModule, 19 | RouterModule.forChild(DOGS_ROUTES), 20 | CommentsModule 21 | ], 22 | declarations: [ 23 | DogsComponent 24 | ] 25 | }) 26 | export class DogsModule { } 27 | -------------------------------------------------------------------------------- /src/app/dogs/dogs/dogs.component.html: -------------------------------------------------------------------------------- 1 |

{{ pageTitle }}

2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 |

10 | These were the top 10 most popular dog breeds in the United States in 2016, ranked by the American Kennel Club (AKC). 11 |

12 |
13 |
14 |
15 | 16 |
17 |
#{{ dog.rank }}: {{ dog.breed }}
18 |

19 | Learn more 20 |

21 |
22 |
23 |
24 |
25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /src/app/dogs/dogs/dogs.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Title } from '@angular/platform-browser'; 3 | import { ApiService } from '../../core/api.service'; 4 | import { Dog } from './../../core/dog'; 5 | import { throwError, Observable } from 'rxjs'; 6 | import { tap, catchError } from 'rxjs/operators'; 7 | 8 | @Component({ 9 | selector: 'app-dogs', 10 | templateUrl: './dogs.component.html' 11 | }) 12 | export class DogsComponent implements OnInit { 13 | pageTitle = 'Popular Dogs'; 14 | dogsList$: Observable; 15 | loading = true; 16 | error: boolean; 17 | 18 | constructor( 19 | private title: Title, 20 | private api: ApiService 21 | ) { 22 | this.dogsList$ = api.getDogs$().pipe( 23 | tap(val => this._onNext(val)), 24 | catchError((err, caught) => this._onError(err, caught)) 25 | ); 26 | } 27 | 28 | ngOnInit() { 29 | this.title.setTitle(this.pageTitle); 30 | } 31 | 32 | private _onNext(val: Dog[]) { 33 | this.loading = false; 34 | } 35 | 36 | private _onError(err, caught): Observable { 37 | this.loading = false; 38 | this.error = true; 39 | return throwError('An error occurred fetching dogs data.'); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auth0-blog/angular-firebase/2d6766a8d8eda81565053941695383ee5e9f513e/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/assets/images/loading.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts.example: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | const FB_PROJECT_ID = ''; 7 | 8 | export const environment = { 9 | production: false, 10 | auth: { 11 | clientId: '', 12 | clientDomain: '', // e.g., you.auth0.com 13 | audience: '', // e.g., http://localhost:1337/ 14 | redirect: 'http://localhost:4200/callback', 15 | scope: 'openid profile email' 16 | }, 17 | firebase: { 18 | apiKey: '', 19 | authDomain: `${FB_PROJECT_ID}.firebaseapp.com`, 20 | databaseURL: `https://${FB_PROJECT_ID}.firebaseio.com`, 21 | projectId: FB_PROJECT_ID, 22 | storageBucket: `${FB_PROJECT_ID}.appspot.com`, 23 | messagingSenderId: '' 24 | }, 25 | apiRoot: '' // e.g., http://localhost:1337/ (include trailing slash) 26 | }; 27 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/auth0-blog/angular-firebase/2d6766a8d8eda81565053941695383ee5e9f513e/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Top 10 Dogs 6 | 7 | 8 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Required to support Web Animations `@angular/platform-browser/animations`. 51 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 52 | **/ 53 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 54 | 55 | 56 | 57 | /*************************************************************************************************** 58 | * Zone JS is required by default for Angular itself. 59 | */ 60 | import 'zone.js/dist/zone'; // Included with Angular CLI. 61 | 62 | 63 | 64 | /*************************************************************************************************** 65 | * APPLICATION IMPORTS 66 | */ 67 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | button:not(disabled), a { 2 | cursor: pointer !important; 3 | } 4 | button:disabled { 5 | cursor: not-allowed !important; 6 | } 7 | .text-primary { 8 | color:#0275d8 !important; 9 | } 10 | a.text-primary:focus, 11 | a.text-primary:hover { 12 | color: #025aa5; 13 | text-decoration: underline !important; 14 | } 15 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare const __karma__: any; 17 | declare const require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "baseUrl": "./", 6 | "module": "es2015", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "baseUrl": "./", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts", 15 | "polyfills.ts" 16 | ], 17 | "include": [ 18 | "**/*.spec.ts", 19 | "**/*.d.ts" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "target": "es5", 11 | "typeRoots": [ 12 | "node_modules/@types" 13 | ], 14 | "lib": [ 15 | "es2017", 16 | "dom" 17 | ], 18 | "module": "es2015", 19 | "baseUrl": "./" 20 | } 21 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-shadowed-variable": true, 69 | "no-string-literal": false, 70 | "no-string-throw": true, 71 | "no-switch-case-fall-through": true, 72 | "no-trailing-whitespace": true, 73 | "no-unnecessary-initializer": true, 74 | "no-unused-expression": true, 75 | "no-use-before-declare": true, 76 | "no-var-keyword": true, 77 | "object-literal-sort-keys": false, 78 | "one-line": [ 79 | true, 80 | "check-open-brace", 81 | "check-catch", 82 | "check-else", 83 | "check-whitespace" 84 | ], 85 | "prefer-const": true, 86 | "quotemark": [ 87 | true, 88 | "single" 89 | ], 90 | "radix": true, 91 | "semicolon": [ 92 | true, 93 | "always" 94 | ], 95 | "triple-equals": [ 96 | true, 97 | "allow-null-check" 98 | ], 99 | "typedef-whitespace": [ 100 | true, 101 | { 102 | "call-signature": "nospace", 103 | "index-signature": "nospace", 104 | "parameter": "nospace", 105 | "property-declaration": "nospace", 106 | "variable-declaration": "nospace" 107 | } 108 | ], 109 | "typeof-compare": true, 110 | "unified-signatures": true, 111 | "variable-name": false, 112 | "whitespace": [ 113 | true, 114 | "check-branch", 115 | "check-decl", 116 | "check-operator", 117 | "check-separator", 118 | "check-type" 119 | ], 120 | "directive-selector": [ 121 | true, 122 | "attribute", 123 | "app", 124 | "camelCase" 125 | ], 126 | "component-selector": [ 127 | true, 128 | "element", 129 | "app", 130 | "kebab-case" 131 | ], 132 | "no-output-on-prefix": true, 133 | "use-input-property-decorator": true, 134 | "use-output-property-decorator": true, 135 | "use-host-property-decorator": true, 136 | "no-input-rename": true, 137 | "no-output-rename": true, 138 | "use-life-cycle-interface": true, 139 | "use-pipe-transform-interface": true, 140 | "component-class-suffix": true, 141 | "directive-class-suffix": true 142 | } 143 | } 144 | --------------------------------------------------------------------------------