@@ -6,12 +6,12 @@ Firestack handles authentication for us out of the box, both with email/password
6
6
7
7
## Local Auth
8
8
9
- #### [ listenForAuth ()] ( https://firebase.google.com/docs/reference/js/firebase.auth.Auth#onAuthStateChanged )
9
+ #### [ onAuthStateChanged ()] ( https://firebase.google.com/docs/reference/js/firebase.auth.Auth#onAuthStateChanged )
10
10
11
11
Listen for changes in the users auth state (logging in and out).
12
12
13
13
``` javascript
14
- firestack .auth . listenForAuth ((evt ) => {
14
+ firestack .auth (). onAuthStateChanged ((evt ) => {
15
15
// evt is the authentication event, it contains an `error` key for carrying the
16
16
// error message in case of an error and a `user` key upon successful authentication
17
17
if (! evt .authenticated ) {
@@ -25,22 +25,22 @@ firestack.auth.listenForAuth((evt) => {
25
25
.then (() => console .log (' Listening for authentication changes' ))
26
26
```
27
27
28
- #### unlistenForAuth ()
28
+ #### offAuthStateChanged ()
29
29
30
- Remove the ` listenForAuth ` listener.
30
+ Remove the ` onAuthStateChanged ` listener.
31
31
This is important to release resources from our app when we don't need to hold on to the listener any longer.
32
32
33
33
``` javascript
34
- firestack .auth . unlistenForAuth ()
34
+ firestack .auth (). offAuthStateChanged ()
35
35
```
36
36
37
- #### [ createUserWithEmail ()] ( https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createUserWithEmailAndPassword )
37
+ #### [ createUserWithEmailAndPassword ()] ( https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createUserWithEmailAndPassword )
38
38
39
- We can create a user by calling the ` createUserWithEmail ()` function.
39
+ We can create a user by calling the ` createUserWithEmailAndPassword ()` function.
40
40
The method accepts two parameters, an email and a password.
41
41
42
42
``` javascript
43
- firestack .
auth . createUserWithEmail (
' [email protected] ' ,
' 123456' )
43
+ firestack .
auth (). createUserWithEmailAndPassword (
' [email protected] ' ,
' 123456' )
44
44
.then ((user ) => {
45
45
console .log (' user created' , user)
46
46
})
@@ -49,13 +49,13 @@ firestack.auth.createUserWithEmail('
[email protected] ', '123456')
49
49
})
50
50
```
51
51
52
- #### [ signInWithEmail ()] ( https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithEmailAndPassword )
52
+ #### [ signInWithEmailAndPassword ()] ( https://firebase.google.com/docs/reference/js/firebase.auth.Auth#signInWithEmailAndPassword )
53
53
54
- To sign a user in with their email and password, use the ` signInWithEmail ()` function.
54
+ To sign a user in with their email and password, use the ` signInWithEmailAndPassword ()` function.
55
55
It accepts two parameters, the user's email and password:
56
56
57
57
``` javascript
58
- firestack .
auth . signInWithEmail (
' [email protected] ' ,
' 123456' )
58
+ firestack .
auth (). signInWithEmailAndPassword (
' [email protected] ' ,
' 123456' )
59
59
.then ((user ) => {
60
60
console .log (' User successfully logged in' , user)
61
61
})
69
69
Sign an anonymous user. If the user has already signed in, that user will be returned.
70
70
71
71
``` javascript
72
- firestack .auth .signInAnonymously ()
72
+ firestack .auth () .signInAnonymously ()
73
73
.then ((user ) => {
74
74
console .log (' Anonymous user successfully logged in' , user)
75
75
})
76
76
.catch ((err ) => {
77
77
console .error (' Anonymous user signin error' , err);
78
78
})
79
+ ```
79
80
80
81
#### signInWithProvider()
81
82
@@ -88,7 +89,7 @@ We can use an external authentication provider, such as twitter/facebook for aut
88
89
To sign a user using a self-signed custom token, use the ` signInWithCustomToken() ` function. It accepts one parameter, the custom token:
89
90
90
91
``` javascript
91
- firestack.auth.signInWithCustomToken (TOKEN )
92
+ firestack .auth () .signInWithCustomToken (TOKEN )
92
93
.then ((user ) => {
93
94
console .log (' User successfully logged in' , user)
94
95
})
@@ -103,7 +104,7 @@ We can update the current user's email by using the command: `updateUserEmail()`
103
104
It accepts a single argument: the user's new email:
104
105
105
106
``` javascript
106
- firestack .
auth .
updateUserEmail (
' [email protected] ' )
107
+ firestack .
auth () .
updateUserEmail (
' [email protected] ' )
107
108
.then ((res ) => console .log (' Updated user email' ))
108
109
.catch (err => console .error (' There was an error updating user email' ))
109
110
```
@@ -114,7 +115,7 @@ We can update the current user's password using the `updateUserPassword()` metho
114
115
It accepts a single parameter: the new password for the current user
115
116
116
117
``` javascript
117
- firestack .auth .updateUserPassword (' somethingReallyS3cr3t733t' )
118
+ firestack .auth () .updateUserPassword (' somethingReallyS3cr3t733t' )
118
119
.then (res => console .log (' Updated user password' ))
119
120
.catch (err => console .error (' There was an error updating your password' ))
120
121
```
@@ -128,7 +129,7 @@ It accepts a single parameter:
128
129
Possible keys are listed [ here] ( https://firebase.google.com/docs/auth/ios/manage-users#update_a_users_profile ) .
129
130
130
131
``` javascript
131
- firestack .auth
132
+ firestack .auth ()
132
133
.updateUserProfile ({
133
134
displayName: ' Ari Lerner'
134
135
})
@@ -142,7 +143,7 @@ To send a password reset for a user based upon their email, we can call the `sen
142
143
It accepts a single parameter: the email of the user to send a reset email.
143
144
144
145
``` javascript
145
- firestack .
auth .
sendPasswordResetWithEmail (
' [email protected] ' )
146
+ firestack .
auth () .
sendPasswordResetWithEmail (
' [email protected] ' )
146
147
.then (res => console .log (' Check your inbox for further instructions' ))
147
148
.catch (err => console .error (' There was an error :(' ))
148
149
```
@@ -152,7 +153,7 @@ It's possible to delete a user completely from your account on Firebase.
152
153
Calling the ` deleteUser() ` method will take care of this for you.
153
154
154
155
``` javascript
155
- firestack .auth
156
+ firestack .auth ()
156
157
.deleteUser ()
157
158
.then (res => console .log (' Sad to see you go' ))
158
159
.catch (err => console .error (' There was an error - Now you are trapped!' ))
@@ -163,7 +164,7 @@ firestack.auth
163
164
If you want user's token, use ` getToken() ` method.
164
165
165
166
``` javascript
166
- firestack .auth
167
+ firestack .auth ()
167
168
.getToken ()
168
169
.then (res => console .log (res .token ))
169
170
.catch (err => console .error (' error' ))
@@ -175,7 +176,7 @@ To sign the current user out, use the `signOut()` method.
175
176
It accepts no parameters
176
177
177
178
``` javascript
178
- firestack .auth
179
+ firestack .auth ()
179
180
.signOut ()
180
181
.then (res => console .log (' You have been signed out' ))
181
182
.catch (err => console .error (' Uh oh... something weird happened' ))
@@ -188,7 +189,7 @@ Although you _can_ get the current user using the `getCurrentUser()` method, it'
188
189
However, if you need to get the current user, call the ` getCurrentUser() ` method:
189
190
190
191
``` javascript
191
- firestack .auth
192
+ firestack .auth ()
192
193
.getCurrentUser ()
193
194
.then (user => console .log (' The currently logged in user' , user))
194
195
.catch (err => console .error (' An error occurred' ))
0 commit comments