Skip to content

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

Closed
@kusayp

Description

@kusayp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions