redirect back to ft/uri for OAuth (#702)

This commit is contained in:
Kartikey Chauhan 2025-12-14 21:21:48 +05:30 committed by GitHub
parent 37aa7305b2
commit e94fbd7866
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 5 deletions

View file

@ -54,4 +54,8 @@ SKYLIGHT_AUTHENTICATION=replace_me
IPINFO_API_KEY=replace_me
MAIL_HACKCLUB_TOKEN=replace_me
MAIL_HACKCLUB_TOKEN=replace_me
# Hack Club Account
HCA_CLIENT_ID=your_hackclub_account_client_id_here
HCA_CLIENT_SECRET=your_hackclub_account_secret_id_here

View file

@ -1,5 +1,7 @@
class SessionsController < ApplicationController
def hca_new
session[:return_data] = { url: params[:continue].presence || request.referer } if request.referer.present? && request.referer != request.url
Rails.logger.info("Sessions return data: #{session[:return_data]}")
redirect_uri = url_for(action: :hca_create, only_path: false)
redirect_to User.hca_authorize_url(redirect_uri),
@ -9,9 +11,9 @@ class SessionsController < ApplicationController
def hca_create
if params[:error].present?
Rails.logger.error "Slack OAuth error: #{params[:error]}"
Sentry.capture_message("Slack OAuth error: #{params[:error]}")
redirect_to root_path, alert: "Failed to authenticate with Slack. Error ID: #{Sentry.last_event_id}"
Rails.logger.error "HCA OAuth error: #{params[:error]}"
Sentry.capture_message("HCA OAuth error: #{params[:error]}")
redirect_to redirect_path, alert: "Failed to authenticate with Hack Club Auth. Error ID: #{Sentry.last_event_id}"
return
end
@ -26,7 +28,13 @@ class SessionsController < ApplicationController
MigrateUserFromHackatimeJob.perform_later(@user.id)
end
redirect_to root_path, notice: "Successfully signed in with Hack Club Auth! Welcome!"
if @user.created_at > 5.seconds.ago
session[:return_data] ||= { url: params[:continue].presence || request.referer }
Rails.logger.info("Sessions return data: #{session[:return_data]}")
redirect_to my_wakatime_setup_path, notice: "Successfully signed in with Hack Club Auth! Welcome!"
else
redirect_to root_path, notice: "Successfully signed in with Hack Club Auth! Welcome!"
end
else
redirect_to root_path, alert: "Failed to authenticate with Hack Club Auth!"
end