Merged in feat/SW-3639-autologin-sas (pull request #3245)

Feat/SW-3639 autologin sas

* wip

* cleanup

* remove commented code and default lang to EN


Approved-by: Anton Gunnarsson
This commit is contained in:
Joakim Jäderberg
2025-11-28 13:00:42 +00:00
parent e621570f99
commit 9294f0958b
4 changed files with 170 additions and 50 deletions

View File

@@ -0,0 +1,27 @@
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"
}