Home app - Support for not requiring login#2883
Home app - Support for not requiring login#2883cairocoder01 wants to merge 4 commits intoDiscipleTools:developfrom
Conversation
Ensures correct user identification when using magic URLs, especially in scenarios where the user is not explicitly logged in. This change centralizes user ID retrieval using `DT_Magic_URL::get_current_user_id` to consistently determine the user based on the magic link's `post_id` and `post_type`. This prevents issues where the wrong user context was being applied, for example when generating the "Home" link or when determining which apps to display. It also updates the launcher to pass the user ID to the magic URL generation functions, so that the correct home link is displayed for the user.
PR Review: Home App - Support for Not Requiring LoginSummaryThis PR improves magic link handling for the home app when login is not required. The changes centralize user ID retrieval and ensure proper URL generation for non-logged-in users accessing the home app via magic links. ✅ Strengths
🔍 Issues & Concerns1. Type Safety Issue in
|
Code Review - PR #2883SummaryThis PR addresses an important issue where the home app was not respecting the "require login" setting and was redirecting users through login even when not required. The changes centralize user ID retrieval through magic links and ensure proper user context throughout the home app. Positive Aspects ✅
Issues Found 🚨1. Critical: Undefined Method Call (dt-apps/dt-home/magic-link-home-app.php:509)if ( !is_user_logged_in() ) {
DT_ML_Helper::update_user_logged_in_state();
}Problem: The class Recommendation: Either remove this code block if it's not needed, or ensure the class/method exists. If this is from another branch/PR, that dependency should be noted. 2. Type Safety Issue (dt-apps/dt-home/magic-link-home-app.php:497)$user_id = (int) $params['parts']['post_id'];Problem: While you cast to int here, the value in Recommendation: Add validation: $user_id = isset($params['parts']['post_id']) ? (int) $params['parts']['post_id'] : 0;
if ( $user_id === 0 ) {
return new WP_Error( __METHOD__, 'Invalid user ID', [ 'status' => 400 ] );
}3. Missing Null Check (dt-apps/dt-home/includes/class-home-apps.php:734)$post_id = get_user_option( 'corresponds_to_contact', $user_id );
$url = DT_Magic_URL::get_link_url_for_post(
$app_meta['post_type'],
$post_id, // Could be false/empty
$app_ml_root,
$app_ml_type
);Problem: Recommendation: Add validation: $post_id = get_user_option( 'corresponds_to_contact', $user_id );
if ( !empty( $post_id ) ) {
$url = DT_Magic_URL::get_link_url_for_post(
$app_meta['post_type'],
$post_id,
$app_ml_root,
$app_ml_type
);
if ( ! empty( $url ) ) {
$app['url'] = $url;
}
}4. Typo in PHPDoc (dt-reports/magic-url-class.php:477)/**
* Get the magic url link for a past // "past" should be "post"Code Quality Observations
Security Considerations
Testing Recommendations
PerformanceNo significant performance concerns. The changes actually reduce database queries by using the existing Suggested Action Items
Overall, this is a good improvement that simplifies the code and fixes an important bug. The main blocker is the undefined method call that needs to be addressed before merging. |
Pull Request Review - Home App: Support for not requiring loginSummaryThis PR addresses an important issue where the home app wasn't respecting the Code Quality & Best Practices ✅Strengths:
Minor concerns:
Potential Bugs & Issues
|
Currently, the new home app doesn't respect the setting to not require login. It still redirects users through the login. This resolves that an fixes subsequent issues for getting the proper app URLs based on the magic link user instead of the current user.
Some added AI summary from my second commit, which is the bulk of the changes:
This affects the URLs that are used on the main home app screen as well as the app links in the launcher nav and home button. Hopefully there aren't other things I missed, but I'm not entirely sure.