Sha256: e33fa7aa5ce1305516d339baf8e457eb36710773cebf375be84f34c77ed60f4a
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: true module Ibrain::Auth::Mutations class SignInMutation < BaseMutation field :user, Types::Objects::UserType, null: true field :token, String, null: true field :result, Boolean, null: true argument :username, String, description: 'Username', required: true argument :password, String, description: 'Password', required: true def resolve(args) # TODO: define logic inside repository repo = ::AuthRepository.new(nil, normalize_params(args)) user = repo.sign_in if user.present? sign_in(resource_name, user) @current_user = warden.authenticate!(auth_options) warden.set_user(current_user) current_user.jwt_token, jti = auth_headers(request, user) current_user.jti = jti current_user.save! end OpenStruct.new( user: user_signed_in? ? current_user : nil, token: current_user.try(:jwt_token), result: user_signed_in? ) end private def normalize_params(args) ActionController::Parameters.new({ auth: args }) end def auth_options { scope: resource_name } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ibrain-auth-0.1.2 | app/graphql/ibrain/auth/mutations/sign_in_mutation.rb |