Skip to content
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

Add hook for social account registration #448

Merged
merged 1 commit into from Jan 2, 2023
Merged

Add hook for social account registration #448

merged 1 commit into from Jan 2, 2023

Conversation

c-w
Copy link
Contributor

@c-w c-w commented Nov 3, 2022

What does this pull request do?

This pull request adds a hook to the social registration serializer to inject optional custom the behavior when the user signs up with a social provider.

Why is this useful?

I have a registration flow that requires additional information to be sent by the client so that the backend can take certain actions after the user signed up. I implemented this by subclassing the registration serializers and adding my required additional fields.

However, there currently is no clean way to run custom logic after the social account has been registered if this logic needs access to the request data. The django-allauth package does provide the save_user hook in the DefaultSocialAccountAdapter, but this hook doesn't have access to the serializer and re-parsing the request body fails in the ASGI context as the request stream has already been consumed by the serializer.

As a work-around, I currently copy the entire validate method into my subclass to inject my custom logic but given the amount of code that's present in the method, this isn't a long-term maintainable solution as it's very brittle to changes in the dj-rest-auth package. Adding a new lifecycle hook that fires after the registration is complete enables my use-case in a maintainable way and I can easily see this enabling many other use-cases in the future.

@iMerica
Copy link
Owner

iMerica commented Jan 2, 2023

Thank you for submitting this PR and apologies for the delay.

@iMerica iMerica merged commit 4cab22e into iMerica:master Jan 2, 2023
@c-w c-w deleted the post-signup branch January 3, 2023 13:28
@c-w
Copy link
Contributor Author

c-w commented Jan 3, 2023

Thanks for the merge and release 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants