Feat/SW-3639 autologin sas * wip * cleanup * remove commented code and default lang to EN Approved-by: Anton Gunnarsson
28 lines
689 B
TypeScript
28 lines
689 B
TypeScript
import {
|
|
type NextMiddleware,
|
|
type NextRequest,
|
|
NextResponse,
|
|
} from "next/server"
|
|
|
|
import type { MiddlewareMatcher } from "./types"
|
|
|
|
export const middleware: NextMiddleware = async (req) => {
|
|
const redirectUrl = loginRequiredRedirect(req)
|
|
if (redirectUrl) {
|
|
return NextResponse.redirect(redirectUrl)
|
|
}
|
|
}
|
|
|
|
function loginRequiredRedirect(req: NextRequest) {
|
|
if (req.nextUrl.searchParams.get("error") === "login_required") {
|
|
return (
|
|
req.cookies.get("next-auth.callback-url")?.value || req.nextUrl.origin
|
|
)
|
|
}
|
|
return undefined
|
|
}
|
|
|
|
export const matcher: MiddlewareMatcher = (request) => {
|
|
return request.nextUrl.pathname === "/api/web/auth/callback/sas"
|
|
}
|