Skip to content

Commit fedd987

Browse files
committed
app v0.0.1
1 parent defdb5d commit fedd987

27 files changed

+176
-88
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# See http://help.github.com/ignore-files/ for more about ignoring files.
22

3+
/src/environments/environment.prod.ts
4+
/src/environments/environment.ts
5+
NOTES.md
6+
37
# compiled output
48
/dist
59
/tmp

NOTES.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,3 @@ npm install -g typescript
99
npm install angularfire2 firebase --save
1010

1111
Firebase sign in methods enabled
12-
13-
14-
http://stackoverflow.com/questions/34925992/how-to-avoid-imports-with-very-long-relative-paths-in-angular-2
15-
tsconfig.json changed "baseUrl": "src"
16-
to "baseUrl": "."

README.md

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,51 @@
1-
# Firestarter
1+
# FireStarter - Angular4 + Firebase Starter App
22

3-
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.0.0-rc.2.
3+
FireStarter is designed to handle the basic features most Angular+Firebase apps need. It can serve as a foundation to quickly roll out more complex features.
44

5-
## Development server
5+
Demo
66

7-
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
7+
## Features
88

9-
## Code scaffolding
9+
- Authentication w/ Router Guard
10+
- Realtime Database CRUD Demo
11+
- File Uploads to Firebase Storage
12+
- SASS-based
13+
- Bootstrap 4
1014

11-
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class/module`.
15+
## Usage
1216

13-
## Build
17+
Create an account at https://firebase.google.com/
1418

15-
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.
19+
`git clone`
20+
`cd firestarter`
21+
`npm install`
1622

17-
## Running unit tests
23+
Create two new files in the `/environments` dir.
1824

19-
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
25+
environment.ts
26+
```typescript
27+
export const environment = {
28+
production: false,
29+
firebaseConfig: {
30+
apiKey: "APIKEY",
31+
authDomain: "DEV-APP.firebaseapp.com",
32+
databaseURL: "https://DEV-APP.firebaseio.com",
33+
storageBucket: "DEV-APP.appspot.com"
34+
}
35+
};
36+
```
37+
environment.prod.ts
38+
```typescript
39+
export const environment = {
40+
production: true,
41+
firebaseConfig: {
42+
// same as above, or use a different firebase project to isolate environments
43+
}
44+
};
45+
```
2046

21-
## Running end-to-end tests
47+
And finally `ng serve`
2248

23-
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
24-
Before running the tests make sure you are serving the app via `ng serve`.
49+
## Apps Using FireStarter in Production
2550

26-
## Further help
27-
28-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
51+
- [ArtiFilter](https://app.artifilter.com) - Neural Art Generator

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
"karma": "~1.4.1",
4545
"karma-chrome-launcher": "~2.0.0",
4646
"karma-cli": "~1.0.1",
47+
"karma-coverage-istanbul-reporter": "^0.2.0",
4748
"karma-jasmine": "~1.1.0",
4849
"karma-jasmine-html-reporter": "^0.2.2",
49-
"karma-coverage-istanbul-reporter": "^0.2.0",
5050
"protractor": "~5.1.0",
5151
"ts-node": "~2.0.0",
5252
"tslint": "~4.5.0",

src/app/app-routing.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { NgModule } from '@angular/core';
22
import { Routes, RouterModule } from '@angular/router';
3+
import { AuthGuard } from './core/auth.guard';
4+
35
import { UserLoginComponent } from './users/user-login/user-login.component';
46
import { ItemsListComponent } from './items/items-list/items-list.component';
57
import { UploadsListComponent } from './uploads/uploads-list/uploads-list.component';
@@ -10,8 +12,8 @@ const routes: Routes = [
1012
children: []
1113
},
1214
{ path: 'login', component: UserLoginComponent, },
13-
{ path: 'items', component: ItemsListComponent, },
14-
{ path: 'uploads', component: UploadsListComponent, },
15+
{ path: 'items', component: ItemsListComponent, canActivate: [AuthGuard]},
16+
{ path: 'uploads', component: UploadsListComponent, canActivate: [AuthGuard]},
1517
];
1618

1719
@NgModule({

src/app/app.component.html

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
<top-nav></top-nav>
1+
<top-nav></top-nav>
22

3-
<!-- <div class="jumbotron jumbotron-fluid">
4-
<div class="container">
5-
<h1 class="display-3"><i class="fa fa-fire"></i> {{title}}</h1>
6-
<p class="lead">Angular v4 starter app wired up with Firebase</p>
7-
</div>
8-
</div> -->
9-
10-
<div class="container">
3+
<div class="container main-content">
114

125
<div class="row">
13-
<div class="col-md-3 align-self-start">
6+
<div class="col-md-4 align-self-start">
147

158
<user-profile></user-profile>
169

@@ -19,10 +12,14 @@ <h1 class="display-3"><i class="fa fa-fire"></i> {{title}}</h1>
1912

2013

2114
</div>
22-
<div class="col-md-9">
15+
<main class="col-md-8 main">
2316

2417
<router-outlet></router-outlet>
2518

26-
</div>
19+
</main>
2720
</div>
21+
2822
</div>
23+
24+
25+
<footer-nav></footer-nav>

src/app/app.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AngularFireModule } from 'angularfire2';
1313

1414
// FireStarter Users
1515
import { AuthService } from './core/auth.service';
16+
import { AuthGuard} from './core/auth.guard';
1617
import { UserLoginComponent } from './users/user-login/user-login.component';
1718
import { UserProfileComponent } from './users/user-profile/user-profile.component';
1819

@@ -31,6 +32,7 @@ import { UploadDetailComponent } from './uploads/upload-detail/upload-detail.com
3132
// FireStarter Navigation
3233
import { NavService } from './ui/shared/nav.service';
3334
import { TopNavComponent } from './ui/top-nav/top-nav.component';
35+
import { FooterNavComponent } from './ui/footer-nav/footer-nav.component';
3436

3537

3638
export const firebaseConfig = environment.firebaseConfig;
@@ -49,7 +51,8 @@ export const firebaseConfig = environment.firebaseConfig;
4951
UploadFormComponent,
5052
UploadsListComponent,
5153
UploadDetailComponent,
52-
TopNavComponent
54+
TopNavComponent,
55+
FooterNavComponent
5356
],
5457
imports: [
5558
BrowserModule,
@@ -61,6 +64,7 @@ export const firebaseConfig = environment.firebaseConfig;
6164
],
6265
providers: [
6366
AuthService,
67+
AuthGuard,
6468
ItemService,
6569
UploadService,
6670
NavService,

src/app/core/auth.guard.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Injectable } from '@angular/core';
2+
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
3+
import { Observable } from 'rxjs/Observable';
4+
import { AuthService } from './auth.service';
5+
// import { AngularFireAuth } from "angularfire2";
6+
7+
@Injectable()
8+
export class AuthGuard implements CanActivate {
9+
constructor(private auth: AuthService, private router: Router) {}
10+
11+
12+
canActivate(
13+
next: ActivatedRouteSnapshot,
14+
state: RouterStateSnapshot): Observable<boolean> | boolean {
15+
if (this.auth.authenticated) { return true; }
16+
17+
console.log('access denied!')
18+
this.router.navigate(['/login']);
19+
return false
20+
21+
22+
}
23+
}

src/app/core/auth.service.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
import { Injectable } from '@angular/core';
22
import { AngularFireAuth, AngularFireDatabase, FirebaseAuthState, AuthProviders, AuthMethods, AngularFire } from "angularfire2";
3-
// import { User } from "../users/user";
43
import { Router } from "@angular/router";
54

65

76
@Injectable()
87
export class AuthService {
98

10-
public authState: FirebaseAuthState = null;
9+
authState: FirebaseAuthState = null;
1110

1211
constructor(private af: AngularFire,
1312
private db: AngularFireDatabase,
1413
private router:Router) {
1514

1615
af.auth.subscribe((auth) => {
1716
this.authState = auth;
18-
console.log(this.af.auth)
19-
console.log(this.authState)
20-
console.log(this.authState)
2117
});
2218
}
2319

@@ -36,11 +32,20 @@ export class AuthService {
3632
return this.authenticated ? this.authState.uid : '';
3733
}
3834

35+
// Anonymous User
36+
get currentUserAnonymous(): boolean {
37+
return this.authenticated ? this.authState.anonymous : false
38+
}
39+
3940
// Returns current user display name or Guest
4041
get currentUserDisplayName(): string {
41-
return this.authenticated ? this.authState.auth.displayName : 'GUEST';
42-
}
42+
if (!this.authenticated) { return 'GUEST' }
43+
44+
else if (this.currentUserAnonymous) { return 'ANONYMOUS' }
4345

46+
else { return this.authState.auth.displayName || 'OAUTH USER' }
47+
48+
}
4449

4550
//// Social Auth ////
4651

@@ -64,7 +69,19 @@ export class AuthService {
6469
return this.af.auth.login({provider, method: AuthMethods.Popup})
6570
.then(() => this.updateUserData() )
6671
.catch(error => console.log(error));
67-
}
72+
}
73+
74+
75+
//// Anonymous Auth ////
76+
77+
anonymousLogin() {
78+
return this.af.auth.login({
79+
provider: AuthProviders.Anonymous,
80+
method: AuthMethods.Anonymous,
81+
})
82+
.then(() => this.updateUserData())
83+
.catch(error => console.log(error));
84+
}
6885

6986
//// Email/Password Auth ////
7087

@@ -80,16 +97,6 @@ export class AuthService {
8097
// .catch(error => console.log(error));
8198
// }
8299

83-
//// Anonymous Auth ////
84-
85-
// anonymousLogin() {
86-
// return this.af.auth.login({
87-
// provider: AuthProviders.Anonymous,
88-
// method: AuthMethods.Anonymous,
89-
// })
90-
// .then(() => this.writeUserData())
91-
// .catch(error => console.log(error));
92-
// }
93100

94101
//// Sign Out ////
95102

src/app/items/item-form/item-form.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ <h3>New Task Form</h3>
77
<input placeholder="Item Title" class="form-control"
88
[(ngModel)]="item.title"
99
required minlength="2" maxlength="23"
10-
#title='ngModel'>
10+
#title='ngModel' autofocus>
1111

1212
<div *ngIf="title.dirty">
1313
<span *ngIf='title.errors; then errors else valid'>template renders here...</span>

0 commit comments

Comments
 (0)