-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[F] Facebook SSO redirects to exit page
- Loading branch information
Blake Mason
committed
Oct 30, 2023
1 parent
8688351
commit 5b6e723
Showing
1 changed file
with
35 additions
and
8 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 |
---|---|---|
@@ -1,15 +1,42 @@ | ||
import createMiddleware from "next-intl/middleware"; | ||
import { NextResponse } from "next/server"; | ||
import type { NextRequest } from "next/server"; | ||
import createIntlMiddleware from "next-intl/middleware"; | ||
import { fallbackLng, languages } from "./lib/i18n/settings"; | ||
|
||
export default createMiddleware({ | ||
// A list of all locales that are supported | ||
locales: languages, | ||
// This function can be marked `async` if using `await` inside | ||
export function middleware(request: NextRequest) { | ||
const { | ||
nextUrl: { search, pathname }, | ||
} = request; | ||
|
||
// If this locale is matched, pathnames work without a prefix (e.g. `/about`) | ||
defaultLocale: fallbackLng, | ||
}); | ||
if (pathname === "/sso-redirect") { | ||
const urlSearchParams = new URLSearchParams(search); | ||
const params = Object.fromEntries(urlSearchParams.entries()); | ||
const { state: redirectPath, facebook, code } = params; | ||
if (redirectPath && facebook && code) { | ||
const redirectUrl = request.nextUrl.clone(); | ||
redirectUrl.pathname = redirectPath; | ||
|
||
return NextResponse.redirect(redirectUrl); | ||
} | ||
} else { | ||
const handleI18nRouting = createIntlMiddleware({ | ||
// A list of all locales that are supported | ||
locales: languages, | ||
|
||
// If this locale is matched, pathnames work without a prefix (e.g. `/about`) | ||
defaultLocale: fallbackLng, | ||
}); | ||
const response = handleI18nRouting(request); | ||
|
||
return response; | ||
} | ||
} | ||
|
||
export const config = { | ||
// do not localize next.js paths | ||
matcher: ["/((?!api|_next/static|_next/image|assets|favicon.ico|sw.js).*)"], | ||
matcher: [ | ||
"/sso-redirect/", | ||
"/((?!api|_next/static|_next/image|assets|favicon.ico|sw.js).*)", | ||
], | ||
}; |