Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Auth token shows user authenticating in the future" if authTime not specified #67

Open
amosyuen opened this issue Jun 8, 2020 · 2 comments

Comments

@amosyuen
Copy link

amosyuen commented Jun 8, 2020

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);
@jfrumar-infinitusai
Copy link

I added this PR to try and resolve: #66

@AudunWA
Copy link

AudunWA commented Sep 24, 2020

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),
        },
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants