This repository was archived by the owner on Apr 4, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,8 @@ const firebaseWebApi = require("nativescript-plugin-firebase/app");
6262As stated [ here] ( https://firebase.google.com/docs/auth/ios/manage-users#get_the_currently_signed-in_user ) :
6363
6464> The recommended way to get the current user is by setting a listener on the Auth object
65-
65+ <details>
66+ <summary> Native API</summary >
6667 To listen to auth state changes you can register a listener during ` init ` :
6768
6869``` js
@@ -98,7 +99,35 @@ If - for some reason - you want more control over the listener you can use these
9899
99100 // check if already listening to auth state changes
100101 firebase .hasAuthStateListener (listener);
102+ ```
103+ </details >
104+
105+ <details >
106+ <summary >Web API</summary >
107+
108+ The callback handler in will be called with the currentUser (undefined if not signed in) upon attaching the listener
109+ and when the auth state changes.
110+
111+ ``` js
112+ firebaseWebApi .auth ().onAuthStateChanged ((user ?: User ) => {
113+ console .log (" >> auth state changed: " + user);
114+ if (user) {
115+ this .set (" userEmailOrPhone" , user .email ? user .email : (user .phoneNumber ? user .phoneNumber : " N/A" ));
116+ alert ({
117+ title: " User signed in" ,
118+ message: JSON .stringify (user),
119+ okButtonText: " Nice!"
120+ });
121+ } else {
122+ alert ({
123+ title: " User signed out" ,
124+ okButtonText: " Bye!"
125+ });
126+ }
127+ },
128+ error => console .log (" OnAuthChanged Error: " + error));
101129```
130+ </details >
102131
103132### Get Current User
104133Once the user is logged in you can retrieve the currently logged in user:
You can’t perform that action at this time.
0 commit comments