Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- omniauth_controller.rb
- def sign_in_oauth_from_provider
- result = AuthenticateUser.call(omniauth: request.env['omniauth.auth'])
- #@user = User.find_for_oauth(request.env['omniauth.auth'])
- #if @user.persisted?
- if result.success?
- sign_in_and_redirect @user, event: :authentication
- set_flash_message(:notice, :success, kind: @provider_auth) if is_navigational_format?
- end
- end
- INTERACTOR
- class AuthenticateUser
- include Interactor
- def call
- context.omniauth
- if context.save
- context.sucess(message: 'omniauth true')
- authorization = OauthProvider.where(provider: auth.provider, uid: auth.uid.to_s).first
- return authorization.user if authorization
- email = auth.info[:email]
- user = User.where(email: email).first
- if user
- user.oauth_providers.create(provider: auth.provider, uid: auth.uid)
- else
- password = Devise.friendly_token[0, 20]
- user = User.create!(email: email, password: password, password_confirmation: password)
- user.oauth_providers.create(provider: auth.provider, uid: auth.uid)
- end
- user
- # context.sucess(message: 'omniauth true')
- else
- context.fail!
- end
- end
- end
- Error
- OmniauthCallbacksController#github is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: [] NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.
Add Comment
Please, Sign In to add comment