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 souls_fb_auth in SoulsMutation #143

Closed
POPPIN-FUMI opened this issue Nov 30, 2021 · 1 comment
Closed

Add souls_fb_auth in SoulsMutation #143

POPPIN-FUMI opened this issue Nov 30, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@POPPIN-FUMI
Copy link
Contributor

I updated souls-doc's firebase login method like below;

module Mutations
  module Managers::UserManager
    class SignInUser < BaseMutation
      field :status, String, null: false
      field :token, String, null: true
      field :user_role, String, null: true
      field :username, String, null: true
      argument :token, String, required: false

      def resolve(token:)
        payload = souls_fb_auth(token: token)
        begin
          user = ::User.find_by_uid(payload["sub"])
          user.update(icon_url: payload["picture"], username: payload["name"])
          token_base = JsonWebToken.encode(user_id: user.id)
          {
            status: "ログイン成功!",
            username: user.username,
            token: token_base
          }
        rescue StandardError
          user =
            ::User.new(
              uid: payload["sub"],
              email: payload["email"],
              icon_url: payload["picture"],
              username: payload["name"],
              user_role: 4
            )
          if user.save
            token = JsonWebToken.encode(user_id: user.id)
            {
              status: "ユーザー新規登録完了!",
              username: user.username,
              token: token,
              user_role: user.user_role
            }
          else
            { status: user.errors.full_messages }
          end
        end
      end
    end
  end
end

SOULs Doc

It would be super if that souls_fb_auth works behind and return Firebase payload.

current code

module Mutations
  class BaseMutation < GraphQL::Schema::RelayClassicMutation
    argument_class Types::BaseArgument
    field_class Types::BaseField
    input_object_class Types::BaseInputObject
    object_class Types::BaseObject

    def fb_auth(token:)
      FirebaseIdToken::Certificates.request!
      sleep(3) if ENV["RACK_ENV"] == "development"
      @payload = FirebaseIdToken::Signature.verify(token)
      raise(ArgumentError, "Invalid or Missing Token") if @payload.blank?

      @payload
    end
,
,
@POPPIN-FUMI POPPIN-FUMI added the enhancement New feature or request label Nov 30, 2021
@jamesneve
Copy link
Contributor

Resolved by #146

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

No branches or pull requests

2 participants