Skip to content

Commit

Permalink
[F] Facebook SSO redirects to exit page
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Mason committed Oct 30, 2023
1 parent 8688351 commit 5b6e723
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions middleware.ts
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).*)",
],
};

0 comments on commit 5b6e723

Please sign in to comment.