From 4f32581f164e6fca29c54c0a8176857d9af15792 Mon Sep 17 00:00:00 2001 From: Mac Siri Date: Mon, 26 Feb 2024 13:42:41 -0500 Subject: [PATCH] Fix onboarding redirects --- app/controllers/registrations_controller.rb | 15 +++++++++++++-- app/javascript/onboarding/Onboarding.jsx | 11 +++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 48da471530ad..cb6ff8065688 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -4,7 +4,9 @@ class RegistrationsController < Devise::RegistrationsController def new return redirect_to root_path(signin: "true") if user_signed_in? - if URI(request.referer || "").host == URI(request.base_url).host + if URI(request.referer || "").host == URI(request.base_url).host && + URI(request.referer).path.exclude?("/enter") && + URI(request.referer).path.exclude?("/users/sign_up") store_location_for(:user, request.referer) end @@ -32,13 +34,22 @@ def create redirect_to confirm_email_path(email: resource.email) else sign_in(resource) - redirect_to root_path + respond_with resource, location: after_sign_up_path_for(resource) end else render action: "by_email" end end + def after_sign_up_path_for(resource) + referrer = stored_location_for(resource) || root_path + if referrer + onboarding_path(referrer: referrer) + else + onboarding_path + end + end + private def prepare_new_forem_instance diff --git a/app/javascript/onboarding/Onboarding.jsx b/app/javascript/onboarding/Onboarding.jsx index 5ade54918688..b25ac60f11ed 100644 --- a/app/javascript/onboarding/Onboarding.jsx +++ b/app/javascript/onboarding/Onboarding.jsx @@ -12,17 +12,17 @@ export class Onboarding extends Component { this.recordBillboardConversion(); - const url = new URL(window.location); - const previousLocation = url.searchParams.get('referrer'); - const slides = [ProfileForm, FollowTags, FollowUsers, EmailPreferencesForm]; this.nextSlide = this.nextSlide.bind(this); this.prevSlide = this.prevSlide.bind(this); this.slidesCount = slides.length; + const url = new URL(window.location); + const previousLocation = url.searchParams.get('referrer'); this.state = { currentSlide: 0, + previousLocation, }; this.slides = slides.map((SlideComponent, index) => ( @@ -39,15 +39,14 @@ export class Onboarding extends Component { } nextSlide() { - const { currentSlide } = this.state; + const { currentSlide, previousLocation } = this.state; const nextSlide = currentSlide + 1; if (nextSlide < this.slides.length) { this.setState({ currentSlide: nextSlide, }); } else { - // Redirect to the main feed at the end of onboarding. - window.location.href = '/'; + window.location.href = previousLocation || '/'; } }