-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added turbo click event to session extend button
- Loading branch information
1 parent
80e2fd3
commit 48a1e9c
Showing
7 changed files
with
128 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class Api::SessionsController < ApplicationController | ||
# Skip CSRF protection for API calls if you're using protect_from_forgery | ||
# skip_before_action :verify_authenticity_token, only: [:extend] | ||
|
||
def extend | ||
Rails.logger.info "API::SessionsController#extend called" | ||
|
||
# Reset the Devise timeout timer | ||
request.env['devise.skip_timeout'] = true | ||
|
||
if current_user | ||
Rails.logger.info "Current user found: #{current_user.id}" | ||
current_user.remember_me! if current_user.respond_to?(:remember_me!) | ||
current_user.remember_me = true if current_user.respond_to?(:remember_me=) | ||
sign_in(current_user, force: true) | ||
|
||
respond_to do |format| | ||
format.json { | ||
Rails.logger.info "Responding with JSON" | ||
render json: { success: true, message: "Session extended successfully" } | ||
} | ||
format.html { | ||
Rails.logger.info "Responding with HTML redirect" | ||
redirect_back(fallback_location: root_path) | ||
} | ||
format.any { | ||
Rails.logger.info "Responding with 406 Not Acceptable" | ||
head :not_acceptable | ||
} | ||
end | ||
else | ||
Rails.logger.warn "No current user found" | ||
respond_to do |format| | ||
format.json { render json: { success: false, error: "No active session" }, status: :unauthorized } | ||
format.html { redirect_to new_user_session_path } | ||
format.any { head :unauthorized } | ||
end | ||
end | ||
rescue => e | ||
Rails.logger.error "Error in extend session: #{e.message}" | ||
Rails.logger.error e.backtrace.join("\n") | ||
respond_to do |format| | ||
format.json { render json: { success: false, error: e.message }, status: :internal_server_error } | ||
format.html { redirect_to root_path, alert: "An error occurred while extending your session." } | ||
format.any { head :internal_server_error } | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { fetchInternalAPIService } from './fetchInternalAPIService'; | ||
|
||
export const sessionAdapter = { | ||
/** | ||
* Extends the current user session | ||
* @returns {Promise<Response>} The fetch response | ||
*/ | ||
extendSession: async () => { | ||
console.log('sessionAdapter.extendSession called'); | ||
try { | ||
console.log('Sending POST request to /api/extend_session'); | ||
|
||
const response = await fetchInternalAPIService('/api/extend_session', { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json' | ||
}, | ||
credentials: 'same-origin' | ||
}); | ||
|
||
console.log('Response data:', response); | ||
return response; | ||
} catch (error) { | ||
console.error('Error extending session:', error); | ||
throw error; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters