Fix account service API URL joining (#624)
This commit is contained in:
parent
9daf5a3378
commit
cde2ccdf80
@ -2,11 +2,11 @@ export const dynamic = 'force-dynamic'
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountSession, userHasRole } from '@server/account/session'
|
||||
import type { AccountUserRole } from '@server/account/session'
|
||||
|
||||
const ACCOUNT_API_BASE = `${getAccountServiceBaseUrl()}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
const READ_ROLES: AccountUserRole[] = ['admin', 'operator']
|
||||
const WRITE_ROLES: AccountUserRole[] = ['admin']
|
||||
|
||||
@ -2,11 +2,11 @@ export const dynamic = 'force-dynamic'
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountSession, userHasRole } from '@server/account/session'
|
||||
import type { AccountUserRole } from '@server/account/session'
|
||||
|
||||
const ACCOUNT_API_BASE = `${getAccountServiceBaseUrl()}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
const REQUIRED_ROLES: AccountUserRole[] = ['admin']
|
||||
|
||||
type ErrorPayload = {
|
||||
|
||||
@ -2,11 +2,11 @@ export const dynamic = 'force-dynamic'
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountSession, userHasRole } from '@server/account/session'
|
||||
import type { AccountUserRole } from '@server/account/session'
|
||||
|
||||
const ACCOUNT_API_BASE = `${getAccountServiceBaseUrl()}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
const ALLOWED_ROLES: AccountUserRole[] = ['admin', 'operator']
|
||||
|
||||
|
||||
@ -2,10 +2,9 @@ import { cookies } from 'next/headers'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { applyMfaCookie, applySessionCookie, clearMfaCookie, clearSessionCookie, deriveMaxAgeFromExpires, MFA_COOKIE_NAME } from '@lib/authGateway'
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const ACCOUNT_API_BASE = `${ACCOUNT_SERVICE_URL}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
type LoginPayload = {
|
||||
email?: string
|
||||
|
||||
@ -2,10 +2,9 @@ import { cookies } from 'next/headers'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { SESSION_COOKIE_NAME, clearSessionCookie } from '@lib/authGateway'
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const ACCOUNT_API_BASE = `${ACCOUNT_SERVICE_URL}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
void request
|
||||
|
||||
@ -2,10 +2,9 @@ import { cookies } from 'next/headers'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { applyMfaCookie, MFA_COOKIE_NAME, SESSION_COOKIE_NAME } from '@lib/authGateway'
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const ACCOUNT_API_BASE = `${ACCOUNT_SERVICE_URL}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
// This Next.js route proxies MFA provisioning requests to the account service.
|
||||
// The UI calls /api/auth/mfa/setup, which in turn forwards to the Go backend
|
||||
|
||||
@ -2,10 +2,9 @@ import { cookies } from 'next/headers'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { MFA_COOKIE_NAME, SESSION_COOKIE_NAME } from '@lib/authGateway'
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const ACCOUNT_API_BASE = `${ACCOUNT_SERVICE_URL}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const cookieStore = cookies()
|
||||
|
||||
@ -9,10 +9,9 @@ import {
|
||||
deriveMaxAgeFromExpires,
|
||||
MFA_COOKIE_NAME,
|
||||
} from '@lib/authGateway'
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const ACCOUNT_API_BASE = `${ACCOUNT_SERVICE_URL}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
type VerifyPayload = {
|
||||
token?: string
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const ACCOUNT_API_BASE = `${ACCOUNT_SERVICE_URL}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
type RegistrationPayload = {
|
||||
name?: string
|
||||
|
||||
@ -2,10 +2,9 @@ import { cookies } from 'next/headers'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { SESSION_COOKIE_NAME, clearSessionCookie } from '@lib/authGateway'
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const ACCOUNT_API_BASE = `${ACCOUNT_SERVICE_URL}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
type AccountUser = {
|
||||
id?: string
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const ACCOUNT_API_BASE = `${ACCOUNT_SERVICE_URL}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
type VerifyPayload = {
|
||||
email?: string
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_URL = getAccountServiceBaseUrl()
|
||||
const ACCOUNT_API_BASE = `${ACCOUNT_SERVICE_URL}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
type SendPayload = {
|
||||
email?: string
|
||||
|
||||
@ -210,6 +210,21 @@ export function getAccountServiceBaseUrl(): string {
|
||||
return normalizeBrowserBaseUrl(resolved)
|
||||
}
|
||||
|
||||
export function getAccountServiceApiBaseUrl(): string {
|
||||
const accountBaseUrl = getAccountServiceBaseUrl()
|
||||
const apiPath = '/api/auth/'
|
||||
try {
|
||||
const url = new URL(apiPath, accountBaseUrl)
|
||||
return normalizeBaseUrl(url.toString())
|
||||
} catch (error) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.warn('Failed to resolve account service API base URL, falling back to concatenation', error)
|
||||
}
|
||||
const normalizedBase = normalizeBaseUrl(accountBaseUrl)
|
||||
return normalizeBaseUrl(`${normalizedBase}${apiPath}`)
|
||||
}
|
||||
}
|
||||
|
||||
export function getServerServiceBaseUrl(): string {
|
||||
const configured = readEnvValue(
|
||||
'SERVER_SERVICE_URL',
|
||||
|
||||
@ -4,10 +4,9 @@ import { cookies } from 'next/headers'
|
||||
import type { NextRequest } from 'next/server'
|
||||
|
||||
import { SESSION_COOKIE_NAME } from '@lib/authGateway'
|
||||
import { getAccountServiceBaseUrl } from '@lib/serviceConfig'
|
||||
import { getAccountServiceApiBaseUrl } from '@lib/serviceConfig'
|
||||
|
||||
const ACCOUNT_SERVICE_BASE = getAccountServiceBaseUrl()
|
||||
const ACCOUNT_API_BASE = `${ACCOUNT_SERVICE_BASE}/api/auth`
|
||||
const ACCOUNT_API_BASE = getAccountServiceApiBaseUrl()
|
||||
|
||||
export type AccountUserRole = 'guest' | 'user' | 'operator' | 'admin'
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user