Skip to content

Device serial - #3800

Merged
Baalmart merged 4 commits into
stagingfrom
device-serial
Jul 13, 2026
Merged

Device serial#3800
Baalmart merged 4 commits into
stagingfrom
device-serial

Conversation

@OlukaGibson

@OlukaGibson OlukaGibson commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes (What does this PR do?)

  • Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done
  • This change ready to hit production in its current state
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included issue number in the "Closes #ISSUE-NUMBER" part of the "What are the relevant tickets?" section to link the issue.
  • I've updated corresponding documentation for the changes in this PR.
  • I have written unit and/or e2e tests for my change(s).

How should this be manually tested?

  • Please include the steps to be done inorder to setup and test this PR.

What are the relevant tickets?

Screenshots (optional)

Summary by CodeRabbit

  • Bug Fixes
    • Prevented premature redirects from the login page while authentication transitions are still in progress.
    • Improved staging environment detection to ensure authentication URL handling works reliably across different deployment setups.
    • Added additional safeguards against misconfigured authentication URLs in staging and production.
  • Refactor
    • Streamlined the authentication endpoint implementation to use the latest request handler approach.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ec011b32-d070-4b2b-89aa-f55a6663c410

📥 Commits

Reviewing files that changed from the base of the PR and between 5c3f71b and 9944c2a.

📒 Files selected for processing (1)
  • src/beacon/lib/auth.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/beacon/lib/auth.ts

📝 Walkthrough

Walkthrough

Login redirects now wait for transitions to finish. NextAuth uses a preconfigured route handler, and environment detection plus URL normalization handle staging indicators and cross-environment domain values.

Changes

Authentication and environment handling

Layer / File(s) Summary
Gate authenticated redirects
src/beacon/app/login/page.tsx
Authenticated dashboard navigation now requires !isTransitioning, and the effect tracks transition-state changes.
Update NextAuth route handler
src/beacon/app/api/auth/[...nextauth]/route.ts
The route exports a preconfigured NextAuth(authOptions) handler for GET and POST requests.
Normalize staging environment URLs
src/beacon/lib/config.js, src/beacon/lib/auth.ts
Staging detection checks service and host names independently of localhost URL branching, while URL normalization handles production and staging domain mismatches.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: baalmart

Poem

Redirects pause as transitions flow,
Auth handlers find a cleaner row.
Hosts reveal the staging scene,
URLs keep their domains keen.
Small changes, neatly aligned.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title is unrelated to the actual changes, which affect authentication flow, NextAuth routing, and environment URL handling. Rename it to reflect the auth/config changes, e.g. "Fix NextAuth redirect and environment URL handling".
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch device-serial

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/beacon/app/login/page.tsx (1)

139-152: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

isTransitioning is never reset, which can trap users on the login page.

The !isTransitioning guard correctly prevents double-redirects when handleFormSubmit already scheduled navigation. However, isTransitioning is set to true at line 221 and never reset to false. If the router.push(redirectTarget) at line 243 fails or the user lands back on /login (e.g., middleware redirect, expired session per the session callback in src/beacon/lib/auth.ts:301), the transition overlay stays visible and the useEffect's redirect branch is permanently blocked — the user is stuck with no recovery path.

Consider resetting isTransitioning in the setTimeout callback after navigation is initiated, or adding a fallback timeout that clears it.

🛡️ Proposed fix: reset isTransitioning after redirect
         // Small delay to show transition, then redirect
         setTimeout(() => {
           router.push(redirectTarget)
           router.refresh()
+          // Reset transition state in case navigation fails or user returns
+          setTimeout(() => setIsTransitioning(false), 100)
         }, 1500)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/beacon/app/login/page.tsx` around lines 139 - 152, Reset isTransitioning
after the delayed navigation initiated by handleFormSubmit completes, ensuring
the state cannot permanently block the authenticated redirect branch in the
login useEffect. Update the setTimeout callback around
router.push(redirectTarget) to clear the transition state after navigation is
initiated, while preserving the existing double-redirect guard.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/beacon/lib/config.js`:
- Around line 43-48: Update the SERVICE_NAME/HOSTNAME staging detection in the
configuration environment check to recognize both “stage” and “staging”
substrings, matching the existing NEXTAUTH_URL and client-side detection
behavior. Preserve the current precedence of this branch before the localhost
handling.

---

Outside diff comments:
In `@src/beacon/app/login/page.tsx`:
- Around line 139-152: Reset isTransitioning after the delayed navigation
initiated by handleFormSubmit completes, ensuring the state cannot permanently
block the authenticated redirect branch in the login useEffect. Update the
setTimeout callback around router.push(redirectTarget) to clear the transition
state after navigation is initiated, while preserving the existing
double-redirect guard.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b8acc141-881b-4c3e-8f98-4de520a24e95

📥 Commits

Reviewing files that changed from the base of the PR and between 1df9795 and 43d55e9.

📒 Files selected for processing (2)
  • src/beacon/app/login/page.tsx
  • src/beacon/lib/config.js

Comment thread src/beacon/lib/config.js
@github-actions

Copy link
Copy Markdown
Contributor

New azure beacon changes available for preview here

@github-actions

Copy link
Copy Markdown
Contributor

New azure beacon changes available for preview here

@OlukaGibson
OlukaGibson marked this pull request as draft July 11, 2026 12:20
@OlukaGibson
OlukaGibson marked this pull request as ready for review July 13, 2026 00:14
@OlukaGibson
OlukaGibson requested a review from Baalmart July 13, 2026 00:17

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/beacon/lib/auth.ts`:
- Around line 15-24: Normalize rawUrl by trimming surrounding whitespace and
trailing slashes before deriving isLocalhostUrl, isProdUrlOnStaging, and the
production staging-domain comparison in the NEXTAUTH_URL correction logic. Use
the normalized value for all canonical URL comparisons while preserving the
existing environment-specific assignments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: db64042f-241b-46b5-ac07-dcf8a930f222

📥 Commits

Reviewing files that changed from the base of the PR and between 43d55e9 and 5c3f71b.

📒 Files selected for processing (2)
  • src/beacon/app/api/auth/[...nextauth]/route.ts
  • src/beacon/lib/auth.ts

Comment thread src/beacon/lib/auth.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Beacon app’s authentication and environment handling to behave correctly across staging/production deployments and during client-side auth transitions.

Changes:

  • Adjust Beacon server-side environment detection to correctly classify staging based on service/pod identifiers (not only NEXTAUTH_URL).
  • Make NEXTAUTH_URL self-correct when it’s missing/localhost or mispointing between staging and production.
  • Prevent login page redirects while a post-login transition screen is active, and simplify the NextAuth app-route handler.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/beacon/lib/config.js Expands staging detection on the server using SERVICE_NAME/HOSTNAME.
src/beacon/lib/auth.ts Updates NEXTAUTH_URL normalization rules for staging/prod correctness.
src/beacon/app/login/page.tsx Avoids redirecting while isTransitioning is true during login flow.
src/beacon/app/api/auth/[...nextauth]/route.ts Switches to the App Router-style NextAuth(authOptions) handler export.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/beacon/lib/auth.ts
Comment thread src/beacon/app/login/page.tsx
@github-actions

Copy link
Copy Markdown
Contributor

New azure beacon changes available for preview here

@Baalmart
Baalmart merged commit 79ab077 into staging Jul 13, 2026
26 checks passed
@Baalmart
Baalmart deleted the device-serial branch July 13, 2026 07:21
@Baalmart Baalmart mentioned this pull request Jul 13, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants