Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit e06f8db

Browse files
There is no "getIdToken" method on firebase.auth().currentUser? #1189
1 parent b252e32 commit e06f8db

File tree

7 files changed

+33
-11
lines changed

7 files changed

+33
-11
lines changed

demo-ng/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"nativescript-angular": "^6.1.0",
2626
"nativescript-camera": "~4.1.1",
2727
"nativescript-imagepicker": "~6.0.5",
28-
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-8.1.0.tgz",
28+
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-8.1.1.tgz",
2929
"nativescript-theme-core": "~1.0.4",
3030
"reflect-metadata": "~0.1.10",
3131
"rxjs": "~6.0.0 || >=6.1.0",
@@ -43,4 +43,4 @@
4343
"nativescript-dev-webpack": "^0.15.1",
4444
"typescript": "~2.8.0"
4545
}
46-
}
46+
}

demo/app/main-view-model.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,14 @@ export class HelloWorldModel extends Observable {
7878
public doWebLoginByPassword(): void {
7979
this.ensureWebOnAuthChangedHandler();
8080
firebaseWebApi.auth().signInWithEmailAndPassword('[email protected]', 'pwd123LOL')
81-
.then(() => console.log("User logged in"))
81+
.then(() => {
82+
console.log("User logged in");
83+
84+
// now retrieve an auth token we can use to access Firebase from our server
85+
firebaseWebApi.auth().currentUser.getIdToken(false)
86+
.then((token: string) => console.log("Auth token retrieved: " + token))
87+
.catch(errorMessage => console.log("Auth token retrieval error: " + errorMessage));
88+
})
8289
.catch(err => {
8390
alert({
8491
title: "Login error",

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"firebase-functions": "^2.0.5",
13-
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-8.1.0.tgz",
13+
"nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-8.1.1.tgz",
1414
"nativescript-theme-core": "^1.0.4",
1515
"nativescript-unit-test-runner": "^0.3.4",
1616
"tns-core-modules": "~5.2.0"

src/firebase.android.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,11 @@ function toLoginResult(user, additionalUserInfo?): User {
806806
creationTimestamp: user.getMetadata() ? new Date(user.getMetadata().getCreationTimestamp() as number) : null,
807807
lastSignInTimestamp: user.getMetadata() ? new Date(user.getMetadata().getLastSignInTimestamp() as number) : null
808808
},
809+
getIdToken: (forceRefresh?: boolean) => new Promise((resolve, reject) => {
810+
firebase.getAuthToken({forceRefresh})
811+
.then((result: GetAuthTokenResult) => resolve(result.token))
812+
.catch(reject)
813+
}),
809814
sendEmailVerification: (actionCodeSettings?: ActionCodeSettings) => firebase.sendEmailVerification(actionCodeSettings)
810815
};
811816

src/firebase.d.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,12 @@ export interface User {
351351
profileImageURL?: string;
352352
metadata: UserMetadata;
353353
additionalUserInfo?: AdditionalUserInfo;
354+
354355
/** iOS only */
355356
refreshToken?: string;
356357

358+
getIdToken(forceRefresh?: boolean): Promise<string>;
359+
357360
sendEmailVerification(actionCodeSettings?: ActionCodeSettings): Promise<void>;
358361
}
359362

@@ -730,13 +733,15 @@ export namespace firestore {
730733
*/
731734
cacheSizeBytes?: number;
732735
}
733-
/**
734-
* Specifies custom settings to be used to configure the `Firestore`
735-
* instance. Must be set before invoking any other methods.
736-
*
737-
* @param settings The settings to use.
738-
*/
736+
737+
/**
738+
* Specifies custom settings to be used to configure the `Firestore`
739+
* instance. Must be set before invoking any other methods.
740+
*
741+
* @param settings The settings to use.
742+
*/
739743
export function settings(settings: Settings): void;
744+
740745
export interface SetOptions {
741746
merge?: boolean;
742747
}

src/firebase.ios.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,11 @@ function toLoginResult(user, additionalUserInfo?: FIRAdditionalUserInfo): User {
687687
creationTimestamp: user.metadata.creationDate as Date,
688688
lastSignInTimestamp: user.metadata.lastSignInDate as Date
689689
},
690+
getIdToken: (forceRefresh?: boolean) => new Promise((resolve, reject) => {
691+
firebase.getAuthToken({forceRefresh})
692+
.then((result: GetAuthTokenResult) => resolve(result.token))
693+
.catch(reject)
694+
}),
690695
sendEmailVerification: (actionCodeSettings?: ActionCodeSettings) => firebase.sendEmailVerification(actionCodeSettings)
691696
};
692697

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "8.1.0",
3+
"version": "8.1.1",
44
"description": "Fire. Base. Firebase!",
55
"main": "firebase",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)