Skip to content

Commit 7d017ee

Browse files
committed
change: angular-cli v1.0.2 + angularfire2 rc4.0.0
1 parent 6118ec4 commit 7d017ee

File tree

9 files changed

+84
-89
lines changed

9 files changed

+84
-89
lines changed

package.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,31 @@
2424
"@angular/platform-server": "^4.0.0",
2525
"@angular/router": "^4.0.0",
2626
"@types/lodash": "^4.14.61",
27-
"angularfire2": "^2.0.0-beta.8",
28-
"bootstrap": "^4.0.0-alpha.6",
27+
"angularfire2": "^4.0.0-rc.0",
2928
"core-js": "^2.4.1",
3029
"firebase": "^3.7.2",
3130
"lodash": "^4.17.4",
3231
"rxjs": "^5.1.0",
3332
"typescript": "^2.2.1",
34-
"zone.js": "^0.7.6"
33+
"zone.js": "^0.8.10"
3534
},
3635
"devDependencies": {
37-
"@angular/cli": "1.0.0-rc.2",
36+
"@angular/cli": "^1.0.2",
3837
"@angular/compiler-cli": ">=4.0.0-beta <5.0.0",
39-
"@types/jasmine": "2.5.38",
40-
"@types/node": "~6.0.60",
41-
"codelyzer": "~2.0.0",
42-
"jasmine-core": "~2.5.2",
43-
"jasmine-spec-reporter": "~3.2.0",
44-
"karma": "~1.4.1",
45-
"karma-chrome-launcher": "~2.0.0",
38+
"@types/jasmine": "2.5.47",
39+
"@types/node": "~7.0.18",
40+
"codelyzer": "~3.0.1",
41+
"jasmine-core": "~2.6.1",
42+
"jasmine-spec-reporter": "~4.1.0",
43+
"karma": "~1.7.0",
44+
"karma-chrome-launcher": "~2.1.1",
4645
"karma-cli": "~1.0.1",
47-
"karma-coverage-istanbul-reporter": "^0.2.0",
46+
"karma-coverage-istanbul-reporter": "^1.2.1",
4847
"karma-jasmine": "~1.1.0",
4948
"karma-jasmine-html-reporter": "^0.2.2",
5049
"protractor": "~5.1.0",
51-
"ts-node": "~2.0.0",
52-
"tslint": "~4.5.0",
53-
"typescript": "~2.1.0"
50+
"ts-node": "~3.0.4",
51+
"tslint": "~5.2.0",
52+
"typescript": "~2.3.2"
5453
}
5554
}

src/app/app.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import { AppComponent } from './app.component';
99

1010
///// Start FireStarter
1111
import { environment } from '../environments/environment';
12+
import * as firebase from 'firebase/app';
1213
import { AngularFireModule } from 'angularfire2';
14+
import { AngularFireDatabaseModule } from 'angularfire2/database';
15+
import { AngularFireAuthModule} from 'angularfire2/auth';
16+
1317

1418
// FireStarter Users
1519
import { AuthService } from './core/auth.service';
@@ -67,9 +71,11 @@ export const firebaseConfig = environment.firebaseConfig;
6771
FormsModule,
6872
ReactiveFormsModule,
6973
HttpModule,
74+
BrowserAnimationsModule,
7075
AppRoutingModule,
7176
AngularFireModule.initializeApp(firebaseConfig),
72-
BrowserAnimationsModule,
77+
AngularFireDatabaseModule,
78+
AngularFireAuthModule
7379
],
7480
providers: [
7581
AuthService,

src/app/core/auth.service.ts

Lines changed: 50 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
import { Injectable } from '@angular/core';
2-
import { AngularFireAuth, AngularFireDatabase, FirebaseAuthState, AuthProviders, AuthMethods, AngularFire } from "angularfire2";
2+
import { AngularFireDatabaseModule, AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
3+
import { AngularFireAuth } from 'angularfire2/auth';
34
import { Router } from "@angular/router";
45
import * as firebase from 'firebase';
56

6-
export class EmailPasswordCredentials {
7-
email: string;
8-
password: string;
9-
}
10-
117

128
@Injectable()
139
export class AuthService {
1410

15-
authState: FirebaseAuthState = null;
11+
authState: any = null;
1612

17-
constructor(private af: AngularFire,
13+
constructor(private afAuth: AngularFireAuth,
1814
private db: AngularFireDatabase,
1915
private router:Router) {
2016

21-
af.auth.subscribe((auth) => {
22-
this.authState = auth;
17+
this.afAuth.authState.subscribe((auth) => {
18+
this.authState = auth
2319
});
2420
}
2521

@@ -28,14 +24,14 @@ export class AuthService {
2824
return this.authState !== null;
2925
}
3026

31-
// Returns current user
27+
// Returns current user data
3228
get currentUser(): any {
33-
return this.authenticated ? this.authState.auth : null;
29+
return this.authenticated ? this.authState : null;
3430
}
3531

3632
// Returns
3733
get currentUserObservable(): any {
38-
return this.af.auth
34+
return this.afAuth.authState
3935
}
4036

4137
// Returns current user UID
@@ -45,83 +41,76 @@ export class AuthService {
4541

4642
// Anonymous User
4743
get currentUserAnonymous(): boolean {
48-
return this.authenticated ? this.authState.anonymous : false
44+
return this.authenticated ? this.authState.isAnonymous : false
4945
}
5046

5147
// Returns current user display name or Guest
5248
get currentUserDisplayName(): string {
53-
if (!this.authenticated) { return 'Guest' }
54-
49+
if (!this.authState) { return 'Guest' }
5550
else if (this.currentUserAnonymous) { return 'Anonymous' }
56-
57-
else { return this.authState.auth.displayName || 'User without a Name' }
58-
51+
else { return this.authState['displayName'] || 'User without a Name' }
5952
}
6053

6154
//// Social Auth ////
6255

63-
githubLogin(): firebase.Promise<FirebaseAuthState> {
64-
return this.socialSignIn(AuthProviders.Github);
56+
githubLogin() {
57+
const provider = new firebase.auth.GithubAuthProvider()
58+
return this.socialSignIn(provider);
6559
}
6660

67-
googleLogin(): firebase.Promise<FirebaseAuthState> {
68-
return this.socialSignIn(AuthProviders.Google);
61+
googleLogin() {
62+
const provider = new firebase.auth.GoogleAuthProvider()
63+
return this.socialSignIn(provider);
6964
}
7065

71-
facebookLogin(): firebase.Promise<FirebaseAuthState> {
72-
return this.socialSignIn(AuthProviders.Facebook);
66+
facebookLogin() {
67+
const provider = new firebase.auth.FacebookAuthProvider()
68+
return this.socialSignIn(provider);
7369
}
7470

75-
twitterLogin(): firebase.Promise<FirebaseAuthState> {
76-
return this.socialSignIn(AuthProviders.Twitter);
71+
twitterLogin(){
72+
const provider = new firebase.auth.TwitterAuthProvider()
73+
return this.socialSignIn(provider);
7774
}
7875

79-
private socialSignIn(provider: number): firebase.Promise<FirebaseAuthState> {
80-
return this.af.auth.login({provider, method: AuthMethods.Popup})
81-
.then(() => this.updateUserData() )
76+
private socialSignIn(provider) {
77+
return this.afAuth.auth.signInWithPopup(provider)
78+
.then((credential) => {
79+
this.authState = credential.user
80+
this.updateUserData()
81+
})
8282
.catch(error => console.log(error));
8383
}
8484

8585

8686
//// Anonymous Auth ////
8787

8888
anonymousLogin() {
89-
return this.af.auth.login({
90-
provider: AuthProviders.Anonymous,
91-
method: AuthMethods.Anonymous,
89+
return this.afAuth.auth.signInAnonymously()
90+
.then((user) => {
91+
this.authState = user
92+
this.updateUserData()
9293
})
93-
.then(() => this.updateUserData())
9494
.catch(error => console.log(error));
9595
}
9696

97-
// anonymousUpgrade(): firebase.Promise<FirebaseAuthState> {
98-
//
99-
// let anonId = this.currentUserId
100-
//
101-
// // Login with google
102-
// return this.googleLogin().then( () => {
103-
// // get the data snapshot from anonymous account account
104-
// this.db.object(anonId).subscribe(snapshot => {
105-
// // map the anonymous user data to the new account.
106-
// this.db.object(this.currentUserId).update(snapshot)
107-
// })
108-
// });
109-
// }
110-
11197
//// Email/Password Auth ////
11298

113-
emailSignUp(credentials: EmailPasswordCredentials): firebase.Promise<FirebaseAuthState> {
114-
return this.af.auth.createUser(credentials)
115-
.then(() => this.updateUserData())
99+
emailSignUp(email:string, password:string) {
100+
return this.afAuth.auth.createUserWithEmailAndPassword(email, password)
101+
.then((user) => {
102+
this.authState = user
103+
this.updateUserData()
104+
})
116105
.catch(error => console.log(error));
117106
}
118107

119-
emailLogin(credentials: EmailPasswordCredentials): firebase.Promise<FirebaseAuthState> {
120-
return this.af.auth.login(credentials,
121-
{ provider: AuthProviders.Password,
122-
method: AuthMethods.Password
123-
})
124-
.then(() => this.updateUserData())
108+
emailLogin(email:string, password:string) {
109+
return this.afAuth.auth.signInWithEmailAndPassword(email, password)
110+
.then((user) => {
111+
this.authState = user
112+
this.updateUserData()
113+
})
125114
.catch(error => console.log(error));
126115
}
127116

@@ -138,7 +127,7 @@ export class AuthService {
138127
//// Sign Out ////
139128

140129
signOut(): void {
141-
this.af.auth.logout();
130+
this.afAuth.auth.signOut();
142131
this.router.navigate(['/'])
143132
}
144133

@@ -151,9 +140,9 @@ export class AuthService {
151140

152141
let path = `users/${this.currentUserId}`; // Endpoint on firebase
153142
let data = {
154-
name: this.currentUser.displayName,
155-
email: this.currentUser.email,
156-
}
143+
email: this.authState.email,
144+
name: this.authState.displayName
145+
}
157146

158147
this.db.object(path).update(data)
159148
.catch(error => console.log(error));

src/app/items/items-list/items-list.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22
import { ItemService } from '../shared/item.service';
33
import { Item } from '../shared/item';
4-
import { FirebaseListObservable } from "angularfire2";
4+
import { FirebaseListObservable } from 'angularfire2/database';
55

66
@Component({
77
selector: 'items-list',

src/app/items/shared/item.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Injectable } from '@angular/core';
2-
import { AngularFire, FirebaseListObservable, FirebaseObjectObservable, AngularFireDatabase } from "angularfire2";
2+
// import { AngularFire, FirebaseListObservable, FirebaseObjectObservable, AngularFireDatabase } from "angularfire2";
3+
import { AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';
34
import { Item } from './item';
45

56
@Injectable()
@@ -10,8 +11,7 @@ export class ItemService {
1011
items: FirebaseListObservable<Item[]> = null; // list of objects
1112
item: FirebaseObjectObservable<Item> = null; // single object
1213

13-
constructor(private af: AngularFire,
14-
private db: AngularFireDatabase) { }
14+
constructor(private db: AngularFireDatabase) { }
1515

1616

1717
// Return an observable list with optional query

src/app/uploads/shared/upload.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Injectable } from '@angular/core';
2-
import { AngularFire, AngularFireDatabase, FirebaseListObservable } from 'angularfire2';
2+
// import { AngularFire, AngularFireDatabase, FirebaseListObservable } from 'angularfire2';
33
import { Upload } from './upload';
4+
import { AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';
45
import * as firebase from 'firebase';
56

67

78
@Injectable()
89
export class UploadService {
910

10-
constructor(private af: AngularFire, private db: AngularFireDatabase) { }
11+
constructor(private db: AngularFireDatabase) { }
1112

1213
private basePath:string = '/uploads';
1314
private uploadTask: firebase.storage.UploadTask;

src/app/uploads/uploads-list/uploads-list.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2-
import { FirebaseListObservable } from "angularfire2";
2+
import { FirebaseListObservable } from 'angularfire2/database';
33
import { UploadService } from '../shared/upload.service';
44
import { Upload } from '../shared/upload';
55

src/app/users/user-form/user-form.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ <h3>Existing User Login</h3>
5252
{{ formErrors.password }}
5353
</div>
5454

55-
<button type="submit" class="btn btn-block btn-primary" [disabled]="!userForm.valid">Submit</button>
55+
<button type="submit" class="button" [disabled]="!userForm.valid">Submit</button>
5656

5757
<span *ngIf="userForm.valid" class="help is-success">Form Looks Valid</span>
5858

59-
<p *ngIf="!passReset && userForm.controls.email.valid" class="btn btn-sm btn-secondary" (click)="resetPassword()">Reset Password for {{userForm.value.email}}?</p>
60-
<p *ngIf="passReset" class="text-warning">Reset requested. Check your email instructions.</p>
59+
<a *ngIf="!passReset && userForm.controls.email.valid" class="help is-info" (click)="resetPassword()">Reset Password for {{userForm.value.email}}?</a>
60+
<p *ngIf="passReset" class="help is-info">Reset requested. Check your email instructions.</p>
6161

6262

6363
</form>

src/app/users/user-form/user-form.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ export class UserFormComponent implements OnInit {
2424
}
2525

2626
signup(): void {
27-
this.auth.emailSignUp(this.userForm.value)
27+
this.auth.emailSignUp(this.userForm.value['email'], this.userForm.value['password'])
2828
}
2929

3030
login(): void {
31-
this.auth.emailLogin(this.userForm.value)
31+
this.auth.emailLogin(this.userForm.value['email'], this.userForm.value['password'])
3232
}
3333

3434
resetPassword() {

0 commit comments

Comments
 (0)