How does fastapi-user handle email verifications ? #1449
Closed
striker561
started this conversation in
General
Replies: 1 comment 1 reply
-
You can get the authentication token from here, and then proceed with the email sending logic. Example of using Background Tasks https://fastapi.tiangolo.com/tutorial/background-tasks/#background-tasks class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
reset_password_token_secret = SECRET
verification_token_secret = SECRET
def __init__(self, user_db, background_tasks: BackgroundTasks):
super().__init__(user_db)
self.background_tasks = background_tasks
async def on_after_request_verify(
self, user: User, token: str, request: Optional[Request] = None
):
print(f"Verification requested for user {user.id}. Verification token: {token}")
await self.send_mail(user=user, token=token)
async def send_mail(self, user: User, token: token):
...
self.background_tasks.add_task(...)
async def get_user_manager(background_tasks: BackgroundTasks, user_db=Depends(get_user_db)):
yield UserManager(user_db=user_db, background_tasks=background_tasks) There are other celery, arq ... There are many ways to implement. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've successfully integrated fastapi-users into my project and found the setup process straightforward. However, I'm unclear about what happens when a verification request for an email is made. It seems that the library doesn't automatically send an email for verification. Could you please clarify how we should handle sending the verification email ourselves? Specifically, I'm interested in understanding how to generate the email verification link or token within this process.
Thank you for your help
Beta Was this translation helpful? Give feedback.
All reactions