Skip to content

Commit 9b0b3e4

Browse files
jamesdanielsdavideast
authored andcommitted
Syntax highlighting and import *
1 parent a96a119 commit 9b0b3e4

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

docs/Auth-with-Ionic2.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ and add the following three entries.
142142
143143
your `app.module.ts` file should look something like this.
144144

145-
```bash
145+
```ts
146146

147147
import { NgModule } from '@angular/core';
148148
import { IonicApp, IonicModule } from 'ionic-angular';
@@ -190,7 +190,7 @@ Now inject AngularFireDatabase in your component. Open your `home.ts` by going i
190190
191191
Your `home.ts` file should look like this.
192192

193-
```bash
193+
```ts
194194

195195
import { Component } from '@angular/core';
196196
import { NavController } from 'ionic-angular';
@@ -215,7 +215,7 @@ export class HomePage {
215215

216216
**Update** your `home.html` at `src/pages/home/home.html`, with following entry
217217

218-
```bash
218+
```html
219219

220220
<ion-header>
221221
<ion-navbar>
@@ -259,21 +259,20 @@ C:\projects\Ionic_AngularFire2_Project> ionic g provider AuthService
259259
This should create the AuthService under `src/providers/auth-service.ts`.
260260
Update the service with the following code.
261261

262-
```bash
262+
```typescript
263263
import { Observable } from 'rxjs/Observable';
264264
import { Injectable } from '@angular/core';
265265
import { AngularFireAuth } from 'angularfire2/auth';
266-
import { User } from 'firebase';
267-
import { FacebookAuthProvider } from 'firebase/auth';
266+
import * as firebase from 'firebase/app';
268267

269268
@Injectable()
270269
export class AuthService {
271-
private authState: Observable<User>;
272-
private currentUser: User;
270+
private authState: Observable<firebase.User>;
271+
private currentUser: firebase.User;
273272

274273
constructor(public afAuth$: AngularFireAuth) {
275274
this.authState = afAuth$.authState;
276-
afAuth$.subscribe((user: User) => {
275+
afAuth$.subscribe((user: firebase.User) => {
277276
this.currentUser = user;
278277
});
279278
}
@@ -283,7 +282,7 @@ export class AuthService {
283282
}
284283

285284
signInWithFacebook(): firebase.Promise<FirebaseAuthState> {
286-
return this.afAuth$.auth.signInWithPopup(new FacebookAuthProvider());
285+
return this.afAuth$.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider());
287286
}
288287

289288
signOut(): void {
@@ -303,7 +302,7 @@ export class AuthService {
303302

304303
Add your service in `app.module.ts`. Your `app.module.ts` should look like this
305304

306-
```bash
305+
```ts
307306

308307
import { NgModule } from '@angular/core';
309308
import { IonicApp, IonicModule } from 'ionic-angular';
@@ -344,7 +343,7 @@ export class AppModule { }
344343

345344
Update your `home.html` to add a login button. Your `home.html` should look like this
346345

347-
```bash
346+
```html
348347

349348
<ion-header>
350349
<ion-navbar>
@@ -369,7 +368,7 @@ Update your `home.html` to add a login button. Your `home.html` should look like
369368
and finally, add the corresponding click handlers in `home.ts` as follows.
370369
Also, ensure the *AuthService* is injected in the constructor. Your `home.ts` should look like this
371370

372-
```bash
371+
```ts
373372

374373
import { Component } from '@angular/core';
375374
import { NavController } from 'ionic-angular';
@@ -457,7 +456,7 @@ Add the platform to your facebook portal as mentioned in the document [here](htt
457456

458457
Now import the Platform and Facebook objects in your ```auth-service.ts```
459458

460-
```
459+
```ts
461460
import { Platform } from 'ionic-angular';
462461
import { Facebook } from 'ionic-native';
463462
```
@@ -470,19 +469,19 @@ your ```auth-service.ts``` code should look like this.
470469
import { Observable } from 'rxjs/Observable';
471470
import { Injectable } from '@angular/core';
472471
import { AngularFireAuth } from 'angularfire2/auth';
473-
import { User } from 'firebase';
474-
import { FacebookAuthProvider } from 'firebase/auth';
472+
import * as firebase from 'firebase/app';
473+
475474
import { Platform } from 'ionic-angular';
476475
import { Facebook } from 'ionic-native';
477476

478477
@Injectable()
479478
export class AuthService {
480-
private authState: Observable<User>;
481-
private currentUser: User;
479+
private authState: Observable<firebase.User>;
480+
private currentUser: firebase.User;
482481

483482
constructor(public afAuth$: AngularFireAuth) {
484483
this.authState = afAuth$.authState;
485-
afAuth$.subscribe((user: User) => {
484+
afAuth$.subscribe((user: firebase.User) => {
486485
this.currentUser = user;
487486
});
488487
}
@@ -495,10 +494,10 @@ export class AuthService {
495494
if (this.platform.is('cordova')) {
496495
return Facebook.login(['email', 'public_profile']).then(res => {
497496
const facebookCredential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
498-
return this.afAuth$.aut.signInWithCredential(facebookCredential);
497+
return this.afAuth$.auth.signInWithCredential(facebookCredential);
499498
});
500499
} else {
501-
return this.afAuth$.auth.signInWithPopup(new FacebookAuthProvider());
500+
return this.afAuth$.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider());
502501
}
503502

504503
}

0 commit comments

Comments
 (0)