Skip to content

Had to shift the frontegg.init_app inside lifespan function for FastAPI #122

@chirag-mehta

Description

@chirag-mehta

After an upgrade to Frontegg version 3.0.0 my authentication calls started failing.

So I came to this repo and changed my fastapi app startup using a startup_event function. But that didn't work either.

FastAPI version 0.92.0

I had to instead add it to a lifespan function as follows:

@asynccontextmanager
async def lifespan(app: FastAPI):
    """
    This function is used to run a task in the background for the entire lifespan of the application.
    
    Args:
        app (FastAPI): FastAPI application instance
    
    frontend.init_app() is used to initialize the Frontegg SDK.
    """
    print("Starting lifespan...")
    await frontegg.init_app(client_id=FRONTEGG_CLIENT_ID, api_key=FRONTEGG_API_KEY)
    try:
        yield
    finally:
        print("Stopping lifespan...")

app = FastAPI(debug=True, lifespan=lifespan)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions