Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 26 19:04
    JoaoPedroAssis opened #302
  • Jan 13 02:36
    athix commented #301
  • Jan 13 02:08
    athix labeled #301
  • Jan 12 23:58
    matoni109 edited #301
  • Jan 12 23:58
    matoni109 opened #301
  • Jan 11 14:12
    lorenzk commented #296
  • Jan 10 20:45
    athix commented #298
  • Jan 10 20:44
    athix labeled #298
  • Jan 10 20:36
    rzepetor opened #298
  • Jan 08 22:27
    rzepetor commented #297
  • Jan 08 22:04
    athix commented #297
  • Jan 08 21:54
    rzepetor closed #297
  • Jan 08 21:54
    rzepetor commented #297
  • Jan 08 21:17
    rzepetor edited #297
  • Jan 08 21:16
    rzepetor opened #297
  • Dec 31 2021 15:44
    athix commented #296
  • Dec 31 2021 11:23
    martinzamuner opened #296
  • Dec 06 2021 20:01
    athix labeled #295
  • Dec 06 2021 20:01
    athix commented #295
  • Dec 06 2021 18:36
    paderinandrey edited #295
Josh Buker
@athix

Testing

Philipp Neugebauer
@philippneugebauer
hey, I try to use login_user in my controller tests but I always receive NameError: undefined local variable or method `login_user' as error. I found some stuff about test helpers, but it's very inconsistent and so I couldn't figure out how I should solve that. Hopefully someone here can help me out? :)
I'm not using rspecs, just the normal rails test stuff
Josh Buker
@athix
Hmm. I only have experience using rspec myself, so I'm not sure if I can figure out the cause myself. Would it be possible for you to post the first bit of the stack trace and whatever file(s) it's referring to in your specs?
Josh Buker
@athix
Hey @Ch4s3, need your help with a bugfix release. You available?
Oleg
@youzik
Hey guys, anyone works on JWT here?
Josh Buker
@athix
Been meaning to look into them, but not yet
BONNAURE Olivier
@solisoft
Hi There, I guess it's a common question but : It is easy to move from devise to sorcery ?
Pranav Surya
@pranav-surya

I am new to sorcery and have a question. say if a new user was created the core module with email and password. and later he tries to login using external provider take for eg. github (which has the same email ) it tries create the user again and fails.
is there an existing way to reuse the existing user and add the authentication record for the external provider using it?

i see we can pass a block to :create_from to skip user creation but it also skips adding the external auth info.
@athix

Pranav Surya
@pranav-surya
class OauthsController < ApplicationController

    skip_before_action :require_login, raise: false

  def oauth
      login_at(params[:provider])
  end

  def callback
    provider = params[:provider]
    if @user = login_from(provider)
      redirect_to root_path, :notice => "Logged in from #{provider.titleize}!"
    else
      begin
        sorcery_fetch_user_hash(provider)
        attr = user_attrs(@provider.user_info_mapping, @user_hash)

        raise RuntimeError.new("Email not present mapped from external provider") if attr.dig(:email).nil?

        if @user = User.find_by_email(attr.dig(:email))
          reset_session
          auto_login(@user)
          add_provider_to_user(provider)
        else
          @user = create_from(provider)
          reset_session
          auto_login(@user)
        end
        redirect_to root_path, :notice => "Logged in from #{provider.titleize}!"
      rescue => exception
        Rails.logger.info("Exception caught: #{exception.message}")
        redirect_to root_path, :alert => "Failed to login from #{provider.titleize}!"
      end
    end
  end
end
does this logic follow accepted practices?