mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-14 18:58:10 +08:00
on_after_login hook (#1092)
* on_after_login minimal impl. Questions: is the spot logical for after method? Is after the internal login call. Would before_login be needed? Maybe not, as auth is the way to do pre-login things. Added fastapi request as a param just in case, as other callbacks had it too. Docs addition is missing. * tried to complete the implementation, but the test with user_manager.on_after_login.called fails though * move on_after_login tests to right place, to TestLogin. These ones pass. TODO: check TestCallback * on_after_login tests to TestCallback too, for oauth. Apparently test_redirect_url_router fires the callback too, I guess that's correct, am not using oauth myself. * fix formatting with make format * docs for on_after_login Co-authored-by: Toni Alatalo <toni.alatalo@gmail.com>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
from typing import Tuple
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Response, status
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request, Response, status
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
|
||||
from fastapi_users import models
|
||||
@ -49,6 +49,7 @@ def get_auth_router(
|
||||
responses=login_responses,
|
||||
)
|
||||
async def login(
|
||||
request: Request,
|
||||
response: Response,
|
||||
credentials: OAuth2PasswordRequestForm = Depends(),
|
||||
user_manager: BaseUserManager[models.UP, models.ID] = Depends(get_user_manager),
|
||||
@ -66,7 +67,9 @@ def get_auth_router(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=ErrorCode.LOGIN_USER_NOT_VERIFIED,
|
||||
)
|
||||
return await backend.login(strategy, user, response)
|
||||
login_return = await backend.login(strategy, user, response)
|
||||
await user_manager.on_after_login(user, request)
|
||||
return login_return
|
||||
|
||||
logout_responses: OpenAPIResponseType = {
|
||||
**{
|
||||
|
Reference in New Issue
Block a user