You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -117,7 +118,7 @@ function onValue (_snapshot_) {
117
118
}
118
119
ref.on('value', onValue);
119
120
ref.set({
120
-
foo:'bar';
121
+
foo:'bar',
121
122
});
122
123
ref.flush();
123
124
console.assert(ref.getData().foo==='bar', 'data has foo');
@@ -169,26 +170,46 @@ ref.flush(); // added foo after null
169
170
170
171
Authentication methods for simulating changes to the auth state of a Firebase reference.
171
172
172
-
##### `changeAuthState(authData)` -> `undefined`
173
+
##### `changeAuthState(user)` -> `undefined`
173
174
174
-
Changes the active authentication credentials to the `authData` object. Before changing the authentication state, `changeAuthState` checks whether the `authData` object is deeply equal to the current authentication data. `onAuth` listeners will only be triggered if the data is not deeply equal. To simulate no user being authenticated, pass `null` for `authData`. This operation is queued until the next `flush`.
175
+
Changes the active authentication credentials to the `authData` object.
176
+
Before changing the authentication state, `changeAuthState` checks the
177
+
`user` object against the current authentication data.
178
+
`onAuthStateChanged` listeners will only be triggered if the data is not
179
+
deeply equal.
175
180
176
-
`authData` should adhere to the [documented schema](https://www.firebase.com/docs/web/api/firebase/onauth.html).
181
+
`user` should be a `MockUser` object or an object with the same fields
182
+
as `MockUser`. To simulate no user being authenticated, pass `null` for
183
+
`user`. This operation is queued until the next `flush`.
177
184
178
185
Example:
179
186
180
187
```js
181
-
ref.changeAuthState({
188
+
ref.changeAuthState(newMockUser(ref, {
182
189
uid:'theUid',
183
-
provider:'github',
184
-
token:'theToken',
185
-
expires:Math.floor(newDate() /1000) +24*60*60, // expire in 24 hours
metadata: {}, // firebase-mock offers limited support for this field
200
+
customClaims: {
201
+
isAdmin:true,
202
+
// etc.
203
+
},
204
+
_idtoken:'theToken',
205
+
_tokenValidity: {
206
+
authTime:'2019-11-22T08:46:15Z',
207
+
issuedAtTime:'2019-11-22T08:46:15Z',
208
+
expirationTime:'2019-11-22T09:46:15Z',
209
+
},
210
+
}));
190
211
ref.flush();
191
-
console.assert(ref.getAuth().auth.myAuthProperty, 'authData has custom property');
212
+
console.assert(ref.getAuth().displayName==='Mr. Meeseeks', 'Auth name is correct');
192
213
```
193
214
194
215
<hr>
@@ -201,6 +222,13 @@ Finds a user previously created with [`createUser`](https://www.firebase.com/doc
201
222
202
223
Finds a user previously created with [`createUser`](https://www.firebase.com/docs/web/api/firebase/createuser.html). If no user was created with the specified `email`, the promise is rejected.
203
224
225
+
##### `updateUser(user)` -> `Promise<MockUser>`
226
+
227
+
Replace the existing user with a new one, by matching uid. Throws an
228
+
error if no user exists whose uid matches the given user's uid. Resolves
229
+
with the updated user when complete. This operation is queued until the
230
+
next flush.
231
+
204
232
## Server Timestamps
205
233
206
234
MockFirebase allow you to simulate the behavior of [server timestamps](https://www.firebase.com/docs/web/api/servervalue/timestamp.html) when using a real Firebase instance. Unless you use `Firebase.setClock`, `Firebase.ServerValue.TIMESTAMP` will be transformed to the current date (`Date.now()`) when your data change is flushed.
0 commit comments