Skip to content

Commit

Permalink
Fix some async API changes in NextJs 15
Browse files Browse the repository at this point in the history
For some reason these problems was not caught by our ci checks.
  • Loading branch information
spaceo committed Dec 12, 2024
1 parent 7a2526b commit 44c54c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 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

0 comments on commit 44c54c5

Please sign in to comment.