| 12345678910111213141516171819202122232425262728293031323334353637 |
- # frozen_string_literal: true
- module Mutations
- class User::ConfirmAccount < Mutations::BaseMutation
- include ControllerMethods
- field :user, Types::UserType, null: true
- argument :confirmation_token, String, required: true
- argument :redirect_url, String, required: true
- def resolve(confirmation_token:, redirect_url:)
- user = User.confirm_by_token(confirmation_token)
- if user.errors.empty?
- redirect_header_options = {account_confirmation_success: true}
- redirect_to_link = if controller.signed_in?(resource_name)
- signed_in_resource.build_auth_url(
- redirect_url,
- redirect_headers(
- client_and_token(controller.signed_in_resource.create_token),
- redirect_header_options,
- ),
- )
- else
- DeviseTokenAuth::Url.generate(redirect_url, redirect_header_options)
- end
- controller.redirect_to(redirect_to_link)
- {user: user}
- else
- raise_user_error('invalid confirmation token')
- end
- end
- end
- end
|