forked from StrafesNET/maps-service
Remove hardcoded auth URLs
This commit is contained in:
@@ -21,7 +21,7 @@ function HeaderButton(header: HeaderButton) {
|
||||
|
||||
export default function Header() {
|
||||
const handleLoginClick = () => {
|
||||
window.location.href = "https://auth.staging.strafes.net/oauth2/login?redirect=" + window.location.href;
|
||||
window.location.href = "/auth/oauth2/login?redirect=" + window.location.href;
|
||||
};
|
||||
|
||||
const [valid, setValid] = useState<boolean>(false)
|
||||
@@ -50,7 +50,7 @@ export default function Header() {
|
||||
<HeaderButton name="Submit" href="/submit"/>
|
||||
{valid && user ? (
|
||||
<div className="author">
|
||||
<Link href="https://auth.staging.strafes.net/">
|
||||
<Link href="/auth">
|
||||
<Image className="avatar" width={28} height={28} priority={true} src={user.AvatarURL} alt={user.Username}/>
|
||||
<button>{user.Username}</button>
|
||||
</Link>
|
||||
|
||||
@@ -1,13 +1,29 @@
|
||||
import { NextRequest, NextResponse } from "next/server"
|
||||
|
||||
export const config = {
|
||||
matcher: ["/api/:path*"],
|
||||
matcher: ["/api/:path*", "/auth/:path*"],
|
||||
}
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
if (!process.env.API_HOST) {
|
||||
throw new Error("env variable \"API_HOST\" is not set")
|
||||
}
|
||||
const url = new URL(process.env.API_HOST + request.nextUrl.pathname.replace(/^\/api/, '') + request.nextUrl.search)
|
||||
return NextResponse.rewrite(url, { request })
|
||||
const { pathname, search } = request.nextUrl
|
||||
|
||||
if (pathname.startsWith("/api")) {
|
||||
if (!process.env.API_HOST) {
|
||||
throw new Error('env variable "API_HOST" is not set')
|
||||
}
|
||||
const apiUrl = new URL(process.env.API_HOST + pathname.replace(/^\/api/, '') + search)
|
||||
return NextResponse.rewrite(apiUrl, { request })
|
||||
} else if (pathname.startsWith("/auth")) {
|
||||
if (!process.env.AUTH_HOST) {
|
||||
throw new Error('env variable "AUTH_HOST" is not set')
|
||||
}
|
||||
|
||||
const authHost = process.env.AUTH_HOST.replace(/\/$/, "")
|
||||
const path = pathname.replace(/^\/auth/, "")
|
||||
const redirectUrl = new URL(authHost + path + search)
|
||||
|
||||
return NextResponse.redirect(redirectUrl, 302)
|
||||
}
|
||||
|
||||
return NextResponse.next()
|
||||
}
|
||||
Reference in New Issue
Block a user