firebase-mock
firebase-mock copied to clipboard
"Auth token shows user authenticating in the future" if authTime not specified
If authTime
is not specified when creating a MockFirebaseUser
, the code has a race condition when setting the date at https://github.com/dmurvihill/firebase-mock/blob/master/src/user.js#L170.
Added inline comments on the code from that file
function _tokenValidity(data) {
const now = new Date(); // Storing "now"
// If "data.authTime" is not defined, we set it to a new date, which will usually be later than "now"
const authTime = data.authTime ?
data.authTime : new Date();
...
// If "data.authTime" is not defined, this will most likely trigger
} else if (now < authTime) {
throw new Error(MockFirebaseUser.msg_tokenAuthedInTheFuture);
I added this PR to try and resolve: https://github.com/dmurvihill/firebase-mock/pull/66
Found a workaround until #66 gets merged:
await firebaseAdmin.auth().createUser({
// Your normal fields here
uid,
email,
password,
emailVerified: true,
// Workaround
_tokenValidity: {
issuedAtTime: new Date(),
authTime: new Date(1970, 1, 1),
expirationTime: new Date(3000, 1, 1),
},
});