Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix | Handle invalid auth token #158

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ class ApplicationController < ActionController::Base

helper_method :current_profile, :current_conference, :vapid_public_key

rescue_from ActionController::InvalidAuthenticityToken,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can test this out by going to /user_session/new, deleting your cookies, and submitting the form. Another way is to inspect the DOM and change the CSRF token in the head and in the form you want to submit

with: :after_invalid_authenticity_token

private

def current_profile = current_user&.profile

# TODO: Must change after implementing multi-conference support
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this note to the "Bugs & improvements" sheet

def current_conference = Conference.last

def vapid_public_key
Base64.urlsafe_decode64(ENV["VAPID_PUBLIC_KEY"]).bytes.to_json
end

def after_invalid_authenticity_token
path_to_redirect = request.referer
path_to_redirect ||= user_signed_in? ? sessions_path : new_user_session_path
redirect_to path_to_redirect, alert: t("authorization.invalid_auth_token")
end
end
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ en:
submit: "Apply"
authorization:
unauthorized: "You are not authorized to access this page."
invalid_auth_token: "Your request has expired. Please try again."
session_mailer:
reminder:
subject: "This session is starting soon"
Expand All @@ -66,4 +67,3 @@ en:
one: "1month"
other: "%{count}months"
x_months: "%{count}months"

20 changes: 0 additions & 20 deletions lib/tasks/db.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace :db do
desc "Loading Rails World 2024 conference data."

task :rails_world_2024_seed, [:start_date] => :environment do |t, args|
start_date = args[:start_date].present? ? Date.parse(args[:start_date]) : Date.new(2024, 9, 26)
month = start_date.month
Expand All @@ -25,43 +24,24 @@ namespace :db do

# Create Tags
community = Tag.find_or_create_by!(name: "Community")

security = Tag.find_or_create_by!(name: "Security")

rails_8 = Tag.find_or_create_by!(name: "Rails 8")

productivity = Tag.find_or_create_by!(name: "Productivity")

tools = Tag.find_or_create_by!(name: "Tools")

developer_experience = Tag.find_or_create_by!(name: "Developer Experience")

deployment = Tag.find_or_create_by!(name: "Deployment")

performance = Tag.find_or_create_by!(name: "Performance")

storage_solutions = Tag.find_or_create_by!(name: "Storage Solutions")

refactoring = Tag.find_or_create_by!(name: "Refactoring")

database = Tag.find_or_create_by!(name: "Database")

hotwire = Tag.find_or_create_by!(name: "Hotwire")

ai = Tag.find_or_create_by!(name: "AI")

integrations = Tag.find_or_create_by!(name: "Integrations")

testing = Tag.find_or_create_by!(name: "Testing")

best_practices = Tag.find_or_create_by!(name: "Best Practices")

pwa = Tag.find_or_create_by!(name: "PWA")

insights = Tag.find_or_create_by!(name: "Insights")

background_jobs = Tag.find_or_create_by!(name: "Background Jobs")

rails_internals = Tag.find_or_create_by!(name: "Rails Internals")

# Create Speakers
Expand Down