Skip to content

First time login fails - KeyError: 'last_sign_in_time' #144

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

Closed
kusayp opened this issue Oct 1, 2023 · 1 comment · Fixed by #145
Closed

First time login fails - KeyError: 'last_sign_in_time' #144

kusayp opened this issue Oct 1, 2023 · 1 comment · Fixed by #145
Labels
bug Something isn't working

Comments

@kusayp
Copy link

kusayp commented Oct 1, 2023

Hi!, i have defined the function to check if user is already logged in

@identity_fn.before_user_signed_in()
def useralreadyloggedin(
    event: identity_fn.AuthBlockingEvent | None,
) -> identity_fn.BeforeSignInResponse | None:
try:
    email: str = event.data.email if event.data.email is not None else ""
except Exception as err:
    print(err)

When user is or has logged in before then everything runs fine
But when the user is logging in for the first time, the function throws a KeyError: 'last_sign_in_time'. However if i disable the function and log the user in, then the next time i try will the functions up, the error is not thrown again.

DEFAULT 2023-10-01T13:05:02.705713Z --- Logging error ---
ERROR 2023-10-01T13:05:02.710436Z Traceback (most recent call last): File "/layers/google.python.pip/pip/lib/python3.11/site-packages/firebase_functions/private/_identity_fn.py", line 323, in before_operation_handler event = _auth_blocking_event_from_token_data(decoded_token)
DEFAULT 2023-10-01T13:05:02.710445Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2023-10-01T13:05:02.710453Z File "/layers/google.python.pip/pip/lib/python3.11/site-packages/firebase_functions/private/_identity_fn.py", line 201, in _auth_blocking_event_from_token_data
DEFAULT 2023-10-01T13:05:02.710459Z data=_auth_user_record_from_token_data(token_data["user_record"]),
DEFAULT 2023-10-01T13:05:02.710465Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2023-10-01T13:05:02.710473Z File "/layers/google.python.pip/pip/lib/python3.11/site-packages/firebase_functions/private/_identity_fn.py", line 119, in _auth_user_record_from_token_data
DEFAULT 2023-10-01T13:05:02.710479Z metadata=_auth_user_metadata_from_token_data(token_data["metadata"]),
DEFAULT 2023-10-01T13:05:02.710484Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2023-10-01T13:05:02.710490Z File "/layers/google.python.pip/pip/lib/python3.11/site-packages/firebase_functions/private/_identity_fn.py", line 71, in _auth_user_metadata_from_token_data
DEFAULT 2023-10-01T13:05:02.710498Z token_data["last_sign_in_time"] / 1000.0),
DEFAULT 2023-10-01T13:05:02.710503Z ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
DEFAULT 2023-10-01T13:05:02.710632Z KeyError: 'last_sign_in_time'

requirements.txt:

firebase_functions~=0.1.0
@exaby73
Copy link
Contributor

exaby73 commented Oct 9, 2023

Hello @kusayp. While fixing another issue, I ran into this issue and provided a fix for it there. I believe this issue will be fixed by #145

@exaby73 exaby73 added the bug Something isn't working label Oct 9, 2023
@exaby73 exaby73 linked a pull request Oct 9, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants