Skip to content

Add hook for social account registration - #448

Merged
iMerica merged 1 commit into
iMerica:masterfrom
c-w:post-signup
Jan 2, 2023
Merged

Add hook for social account registration#448
iMerica merged 1 commit into
iMerica:masterfrom
c-w:post-signup

Conversation

@c-w

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

Copy link
Copy Markdown
Contributor

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

iMerica commented Jan 2, 2023

Copy link
Copy Markdown
Owner

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

c-w commented Jan 3, 2023

Copy link
Copy Markdown
Contributor Author

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.

2 participants