-
Notifications
You must be signed in to change notification settings - Fork 45
Add register mutation and alternate confirmation flow #185
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module GraphqlDevise | ||
| module Mutations | ||
| class ConfirmRegistrationWithToken < Base | ||
| argument :confirmation_token, String, required: true | ||
|
|
||
| field :credentials, | ||
| GraphqlDevise::Types::CredentialType, | ||
| null: true, | ||
| description: 'Authentication credentials. Null unless user is signed in after confirmation.' | ||
|
|
||
| def resolve(confirmation_token:) | ||
| resource = resource_class.confirm_by_token(confirmation_token) | ||
|
|
||
| if resource.errors.empty? | ||
| yield resource if block_given? | ||
|
|
||
| response_payload = { authenticatable: resource } | ||
|
|
||
| response_payload[:credentials] = set_auth_headers(resource) if resource.active_for_authentication? | ||
|
|
||
| response_payload | ||
| else | ||
| raise_user_error(I18n.t('graphql_devise.confirmations.invalid_token')) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module GraphqlDevise | ||
| module Mutations | ||
| class Register < Base | ||
| argument :email, String, required: true | ||
| argument :password, String, required: true | ||
| argument :password_confirmation, String, required: true | ||
| argument :confirm_url, String, required: false | ||
|
|
||
| field :credentials, | ||
| GraphqlDevise::Types::CredentialType, | ||
| null: true, | ||
| description: 'Authentication credentials. Null if after signUp resource is not active for authentication (e.g. Email confirmation required).' | ||
|
|
||
| def resolve(confirm_url: nil, **attrs) | ||
| resource = build_resource(attrs.merge(provider: provider)) | ||
| raise_user_error(I18n.t('graphql_devise.resource_build_failed')) if resource.blank? | ||
|
|
||
| redirect_url = confirm_url || DeviseTokenAuth.default_confirm_success_url | ||
| if confirmable_enabled? && redirect_url.blank? | ||
| raise_user_error(I18n.t('graphql_devise.registrations.missing_confirm_redirect_url')) | ||
| end | ||
|
|
||
| check_redirect_url_whitelist!(redirect_url) | ||
|
|
||
| resource.skip_confirmation_notification! if resource.respond_to?(:skip_confirmation_notification!) | ||
|
|
||
| if resource.save | ||
| yield resource if block_given? | ||
|
|
||
| unless resource.confirmed? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this consider
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really related, |
||
| resource.send_confirmation_instructions( | ||
| redirect_url: redirect_url, | ||
| template_path: ['graphql_devise/mailer'] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Starting to feel we can have a common place for this path |
||
| ) | ||
| end | ||
|
|
||
| response_payload = { authenticatable: resource } | ||
|
|
||
| response_payload[:credentials] = set_auth_headers(resource) if resource.active_for_authentication? | ||
|
|
||
| response_payload | ||
| else | ||
| resource.try(:clean_up_passwords) | ||
| raise_user_error_list( | ||
| I18n.t('graphql_devise.registration_failed'), | ||
| errors: resource.errors.full_messages | ||
| ) | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def build_resource(attrs) | ||
| resource_class.new(attrs) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mutations | ||
| class Register < GraphqlDevise::Mutations::Register | ||
| argument :name, String, required: false | ||
|
|
||
| field :user, Types::UserType, null: true | ||
|
|
||
| def resolve(email:, **attrs) | ||
| original_payload = super | ||
| original_payload.merge(user: original_payload[:authenticatable]) | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this path trigger a deprecation warning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure we should do that here. Plus, any value can be passed to message, not sure it's necessary