-
Notifications
You must be signed in to change notification settings - Fork 89
fix(auth): correctly handle non-fragment callbacks #496
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import CallbackPage from "@/auth/CallbackPage"; | ||
|
|
||
| /** | ||
| * OIDC authentication callback route. | ||
| * This page handles the redirect from the identity provider after user authentication. | ||
| */ | ||
| export default function AuthCallbackPage() { | ||
| return <CallbackPage />; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import CallbackPage from "@/auth/CallbackPage"; | ||
|
|
||
| /** | ||
| * OIDC silent authentication callback route. | ||
| * This page handles silent token renewal redirects from the identity provider. | ||
| */ | ||
| export default function SilentAuthCallbackPage() { | ||
| return <CallbackPage />; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| "use client"; | ||
|
|
||
| import FullScreenLoading from "@components/ui/FullScreenLoading"; | ||
| import { useRouter } from "next/navigation"; | ||
| import { useEffect } from "react"; | ||
|
|
||
| /** | ||
| * Callback page component for OIDC authentication redirects. | ||
| * This page provides a valid route for static export at /auth and /silent-auth, | ||
| * preventing 404 errors with standards-compliant OAuth 2.0 redirect URIs. | ||
| * | ||
| * The @axa-fr/react-oidc library intercepts these routes when OAuth callback | ||
| * parameters are present and renders its own callback handler. This component | ||
| * serves as a fallback if somehow rendered directly. | ||
| */ | ||
| export default function CallbackPage() { | ||
| const router = useRouter(); | ||
|
|
||
| useEffect(() => { | ||
| // Fallback: if this component renders directly, redirect to /peers | ||
| const timer = setTimeout(() => { | ||
| router.replace("/peers"); | ||
| }, 100); | ||
|
|
||
| return () => clearTimeout(timer); | ||
| }, [router]); | ||
|
|
||
| return <FullScreenLoading />; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -130,6 +130,26 @@ const CallBackSuccess = () => { | |||||||||||||
| const params = useSearchParams(); | ||||||||||||||
| const errorParam = params.get("error"); | ||||||||||||||
| const currentPath = usePathname(); | ||||||||||||||
| useRedirect(currentPath, true, !errorParam); | ||||||||||||||
| const router = useRouter(); | ||||||||||||||
|
|
||||||||||||||
| useEffect(() => { | ||||||||||||||
| if (!errorParam && currentPath === "/auth") { | ||||||||||||||
| // Redirect to /peers after a brief delay to ensure tokens are stored | ||||||||||||||
| const timer = setTimeout(() => { | ||||||||||||||
|
||||||||||||||
| let queryParams = ""; | ||||||||||||||
| try { | ||||||||||||||
| const stored = localStorage.getItem("netbird-query-params"); | ||||||||||||||
| if (stored) { | ||||||||||||||
| queryParams = `?${stored}`; | ||||||||||||||
| localStorage.removeItem("netbird-query-params"); | ||||||||||||||
| } | ||||||||||||||
| } catch (e) { } | ||||||||||||||
|
||||||||||||||
| } catch (e) { } | |
| } catch (e) { | |
| if (process.env.NODE_ENV !== "production") { | |
| console.error("Error accessing localStorage in CallBackSuccess:", e); | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic number 100ms delay lacks explanation. Add a comment or constant explaining the purpose of this delay.