Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions rafts/frontend/src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,6 @@
************************************************************************
*/

import { NextRequest } from 'next/server'
import { GET as AuthGET, POST as AuthPOST } from '@/auth/cadc-auth/credentials'

const basePath = process.env.NEXT_PUBLIC_BASE_PATH || ''

// Fix the URL path for NextAuth v5 which doesn't handle base paths well
function fixUrl(req: NextRequest): NextRequest {
if (!basePath) return req

const url = new URL(req.url)
// Remove the base path from the pathname for NextAuth processing
if (url.pathname.startsWith(`${basePath}/api/auth`)) {
url.pathname = url.pathname.replace(basePath, '')
}

return new NextRequest(url, req)
}

export async function GET(req: NextRequest) {
const fixedReq = fixUrl(req)
return AuthGET(fixedReq)
}

export async function POST(req: NextRequest) {
const fixedReq = fixUrl(req)
return AuthPOST(fixedReq)
}
export { AuthGET as GET, AuthPOST as POST }
3 changes: 3 additions & 0 deletions rafts/frontend/src/auth/cadc-auth/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ import { fetchUserInfo } from './fetchUserInfo'
import { fetchUserGroups } from './fetchUserGroups'
import { authenticateUser } from '@/auth/cadc-auth/authenticateUser'

const appBasePath = process.env.NEXT_PUBLIC_BASE_PATH || ''

export const {
handlers: { GET, POST },
auth,
signIn,
signOut,
} = NextAuth({
basePath: `${appBasePath}/api/auth`,
providers: [
CredentialsProvider({
name: 'CADC Login',
Expand Down