Skip to content

Commit

Permalink
Merge pull request #78 from danskernesdigitalebibliotek/DDFBRA-274-ne…
Browse files Browse the repository at this point in the history
…xtjs-15-async-changes

Fix some async API changes in NextJs 15
  • Loading branch information
spaceo authored Dec 17, 2024
2 parents e4d852d + d763705 commit f0b40ed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
13 changes: 9 additions & 4 deletions app/auth/token/refresh/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { headers } from "next/headers"
import { NextRequest, NextResponse } from "next/server"
import * as client from "openid-client"
import { z } from "zod"
Expand All @@ -13,7 +14,11 @@ const sessionTokenSchema = z.object({
refresh_token: z.string(),
})

export async function GET(request: NextRequest, response: NextResponse) {
// TODO: check if headers still work as intended,
// when reenabling this together with refresh token functionality in the middleware.
export async function GET(request: NextRequest) {
const requestHeaders = await headers()

const appUrl = String(goConfig("app.url"))
const config = await getUniloginClientConfig()
// TODO: Fix refresh token flow with new openid-client.
Expand All @@ -23,12 +28,12 @@ export async function GET(request: NextRequest, response: NextResponse) {

// If the user is not logged in, we redirect to the frontpage.
if (!session.isLoggedIn) {
return NextResponse.redirect(frontpage, { headers: response.headers })
return NextResponse.redirect(frontpage, { headers: requestHeaders })
}
const redirect = request.nextUrl.searchParams.get("redirect")
// We need the redirect URL to be present in the query string.
if (!redirect) {
return NextResponse.redirect(frontpage, { headers: response.headers })
return NextResponse.redirect(frontpage, { headers: requestHeaders })
}

try {
Expand All @@ -46,7 +51,7 @@ export async function GET(request: NextRequest, response: NextResponse) {
const isZodError = error instanceof z.ZodError
console.error(isZodError ? JSON.stringify(error.errors) : error)
} finally {
return NextResponse.redirect(redirect, { headers: response.headers })
return NextResponse.redirect(redirect, { headers: requestHeaders })
}
}

Expand Down
11 changes: 10 additions & 1 deletion app/work/[id]/read/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
"use client"

import { useSearchParams } from "next/navigation"
import React from "react"

import Reader from "@/components/shared/publizonReader/PublizonReader"

function Page({ searchParams: { id } }: { searchParams: { id: string } }) {
function Page() {
const searchParams = useSearchParams()
const id = searchParams.get("id")

const handleBack = () => {
window.history.back()
}

// TODO: Do we want to do this if there is no id?
if (!id) {
return null
}

return (
<div className="absolute inset-0 h-screen w-screen">
<div className="absolute h-full w-full bg-reader-grey"></div>
Expand Down
3 changes: 0 additions & 3 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverSourceMaps: true,
},
images: {
remotePatterns: [
{
Expand Down

0 comments on commit f0b40ed

Please sign in to comment.